magico13

[1.4.1] ScrapYard - The Common Part Inventory - 1.1.0.107 (2018-03-18)

Recommended Posts

ScrapYard: The Common Part Inventory

ScrapYard is a mod that provides a part inventory that can be shared between multiple mods. Parts are added to the inventory when you recover a vessel and are removed from the inventory when you build a new vessel. If you have ever played with Kerbal Construction Time, it's a significantly improved version of the part inventory that KCT had, that is also able to be used by other mods.

As of writing, ScrapYard does the following:

  • Parts are added to the inventory automatically upon vessel recovery
  • Parts are applied in the editor (not automatically like with KCT)
  • Parts are then pulled from the inventory on build (mods can change when this happens)
  • Parts are stored individually in the inventory along with any modules that “define” the part (think TweakScale and Procedural Parts)
  • The number of times “like” parts are used is tracked and available for mods, both total uses and number of builds (KCT’s part tracker feature, expanded)
  • Parts are trackable from the moment they are placed in the editor until they are removed from the game via a unique ID that transcends recovery and new builds
  • The number of times an individual part is recovered is tracked, perfect for consumption by part failure mods
  • (WIP) Funds can be overridden so that using parts from the inventory do not contribute to the cost of the vessel. You do still need to have the full amount of funds (for now).
  • ContractConfigurator support for adding or removing parts from the inventory as part of contracts

 

Download: 1.1.0.107 (2018-03-18)

SpaceDock

GitHub

 

DVDdgU1.png

 

y0vd6WS.png

 

 

Source: GitHub

Absolute latest builds available from my build server here: http://magico13.net:8080/job/ScrapYard/

ScrapYard is licensed MIT and includes both MagiCore (magico13, MIT) and ModuleManager (sarbian, CC-SA).

Support me on Patreon!

Special thanks to @SiriusSam for the original idea of creating a separate part inventory way back in 2014 and for the name, and to @enneract for discussion and design help.

As a player, why do I want this?

If you are using Kerbal Construction Time, all balance is assumed you have this mod. It will substantially reduce build times for both vessels that use parts from the inventory and new vessels that use frequently used parts due to the part tracker. As of writing, no other mods are using this framework, but when they do this mod may be required. And this mod can be used by itself with the override funds option to play with a very different play style.

As a mod developer, why do I want this?

 

There are numerous reasons you might want to integrate with ScrapYard (with a hard dependency or a soft dependency, both options are offered), here are just a few that I can think of off the top of my head:

  • ScrapYard provides a way to uniquely track a part during its entire life cycle, from the moment it is placed in the editor until the time it is removed from the game. That includes surviving through multiple recoveries and launches. I imagine part failure mods might get the most use out of this, but surprise me!
  • By using a developed, common system you don’t need to worry about implementing your own part inventory and automatically gain support with other mods. Spend more time writing new features instead of rewriting something that exists.
  • Fine control over the modules that are stored with a part. Once Module Manager support for module templates is added, you can create a new module and a module manager patch to automatically store your module and its data with a part through its entire lifecycle. Module templates use MagiCore’s MathParser to allow for logic processing within the config file (currently limited to just numbers, strings will likely be added soon). Until Module Manager is supported, you can just edit the ModuleTemplates.cfg file directly.
  • Get information about how often parts are used on a total used and number of builds basis. This is referred to as either the Part Tracker or the "Like" Part Tracker since it just tracks parts that are like each other (same name).
  • Many more that I can’t think of off the top of my head :P

Mods using ScrapYard:

Kerbal Construction Time by @magico13

Untitled Part Failure Mod by @severedsolo

Changelog:

 

v1.1.0.107 (2018-03-18)
- Added new event: "OnSYInventoryAppliedToPart". Fired when pressing "apply" from main UI on an existing part.
- Bug fix where Ids were not being set correctly when copying InventoryParts, which affected any parts that were added to the inventory and then used in the same scene (editing vessels in KCT, for instance)
- Changed Vessel tracking to fully remove a vessel from the list when setting the tracking state to false to avoid the list filling up unnecessarily.

v1.0.1.104 (2018-03-17)
- Fixed an issue where "persistentId" was listed as "persistentID" that was breaking the ProcessVessel API call.
- Fixed an exception that would occur when loading a game because of the settings class.
- Changed the message logged when logging a new build to avoid confusion.

v1.0.0.102 (2018-03-14)
- Updated to KSP 1.4.1
- Support for ContractConfigurator for adding/removing parts from inventory as part of a contract (details soon).
- Considerable performance improvements, but some combinations of mods/settings may still see lag spikes in editor.
- New part category (in the advanced section) with only parts that are in the inventory.
- UI refactor. All windows are resizeable (grab bottom/right sides). Main inventory window prevents click through, even when holding a part over the part panel.
- Switched to KSP's stock persistentId system. Old parts should update correctly and not need any manual intervention. Let me know if parts aren't "sticking" when they apply, but I think I fixed that.
- The main window retains it's last state when re-entering the editor.
- Added options to change how often things are recalculated in the editor (turn it up to be less often, but less frequent lag spikes) and to enable debug logging (prints more to the log, enable if you're experiencing a bug).
- Explicit TweakScale support so that it will properly scale everything when selecting/applying from the inventory.
- Numerous other small tweaks and fixes.

v0.9.6.70 (2017-10-17)
- Updated to KSP 1.3.1
- Several additions and changes to the ScrapYard API
- First release of the WIP part selector UI. Very WIP at the moment. Known issues with modules like TweakScale.

v0.9.5.57 (2017-06-13)
- Added "Auto-Apply" option to automatically apply the inventory as you build a vessel.
- Window is now movable and position is saved.
- Allow dry costs to differ by 1 fund and still be considered the same, due to floating point inconsistencies.
- Updated to KSP 1.3 (not backwards compatible with 1.2.2, sorry.)
- Added button to reset the vessel back to "new".
- Bug fixes to not auto-apply non-stop, check the vessel when starting the editor, and only do work once a second instead of twice.

v0.9.4.51 (2017-05-14)
- Added ability to sell/discard parts in the editor by dropping them on the ScrapYard button. Selling currently occurs at 100% value, that will change in the future.
- When overriding funds, the cost display in the editor updates to show the cost after accounting for the inventory. Purely visual, so if you can't afford the whole vessel before the inventory's help then you won't be able to launch.
- Added OnSYTrackerUpdated event. Fires when the part tracker registers a build.

v0.9.3.48 (2017-05-13)
- New icon thanks to flaticon.com. Creators: Icomoon and Freepik
- Updated the Part Tracker to track builds/uses for new uses, inventoried uses, and total uses.
- With the updated MagiCore, now should support string comparison in if statements with "seq" and "sneq" for equals and not equals, and also supports "true" as "1" and "false" as "0".

v0.9.2.44 (2017-05-10)
- Fixed a few bugs that were causing forbidden templates to not match correctly.

v0.9.1.41 (2017-05-09)
- Added several methods to the API for interacting with individual parts and the inventory.
- Tried to broaden the API a bit: takes IEnumerables and returns ILists instead of requiring List for both.
- Changed MODULE_TEMPLATE to SY_MODULE_TEMPLATE and FORBIDDEN_TEMPLATE to SY_FORBIDDEN_TEMPLATE
- Added part blacklist that takes a part name (exact, no Regex) and prevents storing the part if it's on the list
- EVA kerbals are no longer added to the inventory per the blacklist.
- Templates and Blacklist are referenced via the GameDatabase, meaning they should support Module Manager but at the very least you could create your own .cfg files in your own directory and have them be added (MM should allow changing existing ones though).
- Template file (and blacklist) now lives in /ScrapYard instead of /ScrapYard/PluginData so it can be loaded.

v0.9.0.37 (2017-05-05)
- Initial Beta Release

 

Edited by magico13
1.1.0.107

Share this post


Link to post
Share on other sites

I'm looking forward to this being incorporated into a part failure mod. I've got batteries now that have been reused for dozens of launches and surely are past their prime by now.

Share this post


Link to post
Share on other sites
5 hours ago, MarcAFK said:

I'm looking forward to this being incorporated into a part failure mod. I've got batteries now that have been reused for dozens of launches and surely are past their prime by now.

I too am looking forward to it. If nobody does it I might just make a simple one. Or I might at least put in an option where parts can only be used x times before they're automatically discarded/sold (up to infinity). That at least might help a bit with inventory bloat.

Share this post


Link to post
Share on other sites

It's alive!

14 hours ago, magico13 said:
  • Parts are applied in the editor (not automatically like with KCT)

As of now, with KCT yet unreleased, and with no UI to select parts, how does applying work?

Share this post


Link to post
Share on other sites
1 hour ago, monstah said:

As of now, with KCT yet unreleased, and with no UI to select parts, how does applying work?

With or without KCT it works the same way. There's a button on the stock toolbar (that needs a real icon, if anyone wants to volunteer one :wink:) that when pressed opens up a small window with another button that says "Apply Inventory". When that is pressed ScrapYard loops through all of the parts on the current ship in the editor and tries to find parts in the inventory that match that part. It defines a "match" as both parts have the same saved Modules (defined by which modules are saved in ScrapYard), so with tweakscale the two parts have to have the same scale and with procedural parts they have to have the same dimensions, tank layout, graphics, and such. If it finds a match, it copies over the ModuleSYPartTracker from the part in the inventory onto the part in the editor, so you'll see the ID, TimeRecovered, and Inventoried status on the editor part update to reflect the values of the part in the inventory. When you build that vessel (through KCT or normally) all of those parts that were copied from the inventory are fully removed from the inventory.

This has a side effect of requiring you to be able to reproduce a part exactly in order to pull it from the inventory. That might not be possible with things like parts with upgrades that can't be downgraded, so some parts could get orphaned in the inventory. In the future you'll be able to discard/sell those parts at least to get rid of any useless parts, but once you can grab individual parts out of the inventory you won't have to manually recreate them in the editor first since that'll be handled automatically. That's one of my next goals along with the override funds option.

Share this post


Link to post
Share on other sites

Do you plan to make the inventory capable of holding sub assemblies? Not sure how to think about them getting into the inventory, but once there it would make building with parts from the inventory more convenient..

Share this post


Link to post
Share on other sites
1 hour ago, Errol said:

Do you plan to make the inventory capable of holding sub assemblies? Not sure how to think about them getting into the inventory, but once there it would make building with parts from the inventory more convenient..

Right now, no. But I've got ideas for storing subassemblies and entire vessels that may come into play later. As of right now there's no need for it, but I could see it being useful later when you don't use the "Apply Inventory" method as often. I'll keep it in mind.

Share this post


Link to post
Share on other sites
9 minutes ago, magico13 said:

Right now, no. But I've got ideas for storing subassemblies and entire vessels that may come into play later. As of right now there's no need for it, but I could see it being useful later when you don't use the "Apply Inventory" method as often. I'll keep it in mind.

If you could make something I'd actually use, unlike the stock subassembly thingie, such wow.

Share this post


Link to post
Share on other sites
4 minutes ago, monstah said:

If you could make something I'd actually use, unlike the stock subassembly thingie, such wow.

It'd probably be something like the stock one, using all the same backend code, but it'd try to grab parts out of the inventory automatically as well. So for the Falcon 9 for instance, you could save stage 1 as a subassembly and then grab that out and automatically use all the parts you recovered when you landed back at LZ-1. If you were missing any or all parts, it would just swap in new parts. That's all just how it would work in my head right now, actual implementation might be different.

Share this post


Link to post
Share on other sites

I like that, though being a data whore I would request some sort of read-out for which parts had to be added that were missing from inventory, along with costs and a total cost (of the added parts). 

Edited by Errol

Share this post


Link to post
Share on other sites

Hi, @magico13!

I know I did a silly thing: I installed beta ScrapYard on my "production" (career) game. I know, I couldn't resist... :blush:

When I loaded the game, I received a message that my KCT data was corrupted. I downloaded your latest KCT version and the message went away (yay!), but my "point usage" was lost.

I THINK I remember where I used each one but, when I started using them again, they simply weren't enough. How do I give myself new points without spending money or science points?

I can deal with the lost of built crafts and ongoing building line, but I'd like to get my KCT situation back... :(

Share this post


Link to post
Share on other sites
42 minutes ago, jlcarneiro said:

When I loaded the game, I received a message that my KCT data was corrupted. I downloaded your latest KCT version and the message went away (yay!), but my "point usage" was lost.

Not surprised that KCT got a bit messed up since there was a breaking MagiCore change not too long ago, but it shouldn't have permanently broken the save data... Did you purchase any points before your data was lost? If not, it should have returned to the correct amount since that's just based on the tech tree. If you did purchase some  then there are a few ways you could get around that (ideally if you remember how many you bought).

Two options: 1) Open the save file, search for "PurchasedUpgrades" (without quotes) and change the two numbers "Item = 0" to how ever many upgrades you purchased. I think it's funds for the first one and science for the second but I don't entirely remember. Or option 2) open up the KCT settings in game (if you've changed any settings make sure you either save it as a new Preset or backup the KCT_Settings.cfg file in the save folder) and change the UpgradeScienceFormula and/or the UpgradeFundsFormula and just set them to "0" (again, no quotes). You can then just purchase upgrades for free. When you're done with that, go back into the settings and choose the Default Preset again, or whichever Preset you were using (or put the KCT_Settings.cfg backup back in your save file).

If you need any help let me know, but it's probably better suited for the KCT thread :wink:

 

I guess this serves as a warning. If you're gonna use KCT with ScrapYard, please make sure you're updated to the latest version of the KCT dev builds! Things break otherwise!

Share this post


Link to post
Share on other sites
9 minutes ago, magico13 said:

Not surprised that KCT got a bit messed up since there was a breaking MagiCore change not too long ago, but it shouldn't have permanently broken the save data... Did you purchase any points before your data was lost? If not, it should have returned to the correct amount since that's just based on the tech tree. If you did purchase some  then there are a few ways you could get around that (ideally if you remember how many you bought).

Two options: 1) Open the save file, search for "PurchasedUpgrades" (without quotes) and change the two numbers "Item = 0" to how ever many upgrades you purchased. I think it's funds for the first one and science for the second but I don't entirely remember. Or option 2) open up the KCT settings in game (if you've changed any settings make sure you either save it as a new Preset or backup the KCT_Settings.cfg file in the save folder) and change the UpgradeScienceFormula and/or the UpgradeFundsFormula and just set them to "0" (again, no quotes). You can then just purchase upgrades for free. When you're done with that, go back into the settings and choose the Default Preset again, or whichever Preset you were using (or put the KCT_Settings.cfg backup back in your save file).

If you need any help let me know, but it's probably better suited for the KCT thread :wink:

 

I guess this serves as a warning. If you're gonna use KCT with ScrapYard, please make sure you're updated to the latest version of the KCT dev builds! Things break otherwise!

Thanks, man!

See, kids, don't try these dangerous moves without supervision, you're not kerbals! :wink:

Hey, @magico13, I've got an idea: how do I force KCT to distribute the points again? I think I'll go on with this (pretend something terrible happened to KSC and I lost a lot of money, production had to begin again and it lost its upgrades but I could salvage some of them and could get a jumpstart, headstart...

Edited by jlcarneiro

Share this post


Link to post
Share on other sites
1 hour ago, jlcarneiro said:

I've got an idea: how do I force KCT to distribute the points again? I think I'll go on with this (pretend something terrible happened to KSC and I lost a lot of money, production had to begin again and it lost its upgrades but I could salvage some of them and could get a jumpstart, headstart...

You want to reset how they were spent? There's the "Reset Upgrades" button but it normally requires two points. You can alter the UpgradeResetFormula to just cost 0 upgrades if you want (so you can reset them for free), or edit the save file to set any "Item = x" and "Upgrade = x" to zero within the KerbalConstructionTimeData node. Basically anywhere it mentions upgrades within that node, just set it to zero. I can also do it really quickly if you upload your save file.

Edited by magico13

Share this post


Link to post
Share on other sites
1 hour ago, magico13 said:

You want to reset how they were spent? There's the "Reset Upgrades" button but it normally requires two points. You can alter the UpgradeResetFormula to just cost 0 upgrades if you want (so you can reset them for free), or edit the save file to set any "Item = x" and "Upgrade = x" to zero within the KerbalConstructionTimeData node. Basically anywhere it mentions upgrades within that node, just set it to zero. I can also do it really quickly if you upload your save file.

Done on this end. Thank you very much! :wink:

Share this post


Link to post
Share on other sites
On 5/5/2017 at 8:16 PM, magico13 said:
  • The number of times “like” parts are used is tracked and available for mods, both total uses and number of builds (KCT’s part tracker feature, expanded)
  • Parts are trackable from the moment they are placed in the editor until they are removed from the game via a unique ID that transcends recovery and new builds
  • The number of times an individual part is recovered is tracked, perfect for consumption by part failure mods

Some raw initial thoughts re possible TestFlight integration

What is a "like" part?

When parts are re-used how much player interaction is there?  Does the player make decisions on what old parts to use? Can they see any data on individual parts?  Are there options for payed refurbishment, or skipping such?

Share this post


Link to post
Share on other sites
54 minutes ago, Agathorn said:

Some raw initial thoughts re possible TestFlight integration

What is a "like" part?

When parts are re-used how much player interaction is there?  Does the player make decisions on what old parts to use? Can they see any data on individual parts?  Are there options for payed refurbishment, or skipping such?

A "like" part is tracked by part name (mk1pod for instance) only, excluding any other modules. It's set up in a generic way so you could create a new tracker using a different level of "strictness", but you'd have to increment it yourself.

Right now the player interaction isn't that detailed and they don't decide which parts to use. In the future the player will be able to select individual parts out of the inventory and see which modules are saved and their values, in which case it will be very detailed.

Refurbishment isn't really a thing right now, but if you created another module and marked it to be tracked then it will persist through the part's lifetime. You may decide not to use the built in TimesRecovered but might instead create your own, for instance.

Share this post


Link to post
Share on other sites

Am I right in thinking from reading the Trello page that at the moment there is no way for a mod to remove a specific part from the inventory/stop it from being added to the inventory? (say if a part failure mod wanted to remove a "broken" part)?

Edited by severedsolo

Share this post


Link to post
Share on other sites
17 minutes ago, severedsolo said:

there is no way for a mod to remove a specific part from the inventory/stop it from being added to the inventory?

I need to update the API to add a method to add/remove individual parts since right now the API primarily deals with Lists of parts (I should also probably swap that over to IEnumerable), but if you're working with a hard dependency you can use RemovePart (or FindPart) on ScrapYard.Instance.TheInventory (https://github.com/magico13/ScrapYard/blob/master/ScrapYard/PartInventory.cs#L127). You can use a FORBIDDEN_TEMPLATE (https://github.com/magico13/ScrapYard/blob/master/GameData/ScrapYard/PluginData/ModuleTemplates.cfg#L29) [crap, I might have not updated that file in source control, that should say EVAKerbal or KerbalEVA, I have it right locally] to prevent a part from being put into the inventory, but without Module Manager support up and running yet you have to add that template to the ModuleTemplates.cfg file manually.

If you have a module that's got a clearly defined "broken" state, you can set up a FORBIDDEN_TEMPLATE that matches that state (you can also have a regular MODULE_TEMPLATE that matches the regular state). Please feel free to post the module on this thread so 1) I can help and 2) I can see what kinds of things people will be putting through the code.

Share this post


Link to post
Share on other sites

New beta build. Adds a few different things so read the changelog below, especially if you've played with module templates. The TL;DR version is that you can blacklist parts by name, the blacklist and module templates (regular and forbidden) should now support module manager (hopefully) and also just adding in a regular .cfg file to your mod folder, and there were a few additions to the API+wrapper.

Remember, still beta and mostly untested. If anyone tries adding to the blacklist or the templates through module manager or just a regular .cfg file (and not by editing the default ones) please let me know how that goes!

v0.9.1.41 (2017-05-09)

  • Added several methods to the API for interacting with individual parts and the inventory.
  • Tried to broaden the API a bit: takes IEnumerables and returns ILists instead of requiring List for both.
  • Changed MODULE_TEMPLATE to SY_MODULE_TEMPLATE and FORBIDDEN_TEMPLATE to SY_FORBIDDEN_TEMPLATE
  • Added part blacklist that takes a part name (exact, no Regex) and prevents storing the part if it's on the list
  • EVA kerbals are no longer added to the inventory per the blacklist.
  • Templates and Blacklist are referenced via the GameDatabase, meaning they should support Module Manager but at the very least you could create your own .cfg files in your own directory and have them be added (MM should allow changing existing ones though).
  • Template file (and blacklist) now lives in /ScrapYard instead of /ScrapYard/PluginData so it can be loaded.

Share this post


Link to post
Share on other sites
9 hours ago, magico13 said:

Remember, still beta and mostly untested. If anyone tries adding to the blacklist or the templates through module manager or just a regular .cfg file (and not by editing the default ones) please let me know how that goes!

This doesn't seem to be working for me at all.

At first I thought it was because I was trying to add a new module on the fly, but even with a Module that is on the part at launch, the part is still added to the inventory. Weirdly, my log does confirm that the forbidden templates were loaded.

Doesn't seem to matter if it's through a MM patch or added to the ModuleTemplates in the SY folder.

Weirdly, it DOES work if you comment out the part blacklist, and uncomment the SY_FORBIDDEN_TEMPLATE for EVAkerbal. Is it perhaps checking ALL the modules, and returning false because only one module is on the blacklist? Whereas with EVA that is (I assume) the only module?

Reproduction steps: Add ModuleEngines to a SY_FORBIDDEN_TEMPLATE and recover a LV-45 Engine - the engine will still be added to the inventory.

Log: https://www.dropbox.com/s/ivrtklna104p7ty/output_log.txt?dl=0

Share this post


Link to post
Share on other sites
16 minutes ago, severedsolo said:

Weirdly, it DOES work if you comment out the part blacklist, and uncomment the SY_FORBIDDEN_TEMPLATE for EVAkerbal. Is it perhaps checking ALL the modules, and returning false because only one module is on the blacklist? Whereas with EVA that is (I assume) the only module?

Hmm, I'll have to try that out when I get home tonight. With the EVA, I don't believe its the only module (in fact, I know the ModuleSYPartTracker is on there too). You can see that it sets a "DoNotStore" flag if it encounters any forbidden modules here and then if that's set it doesn't get added to the inventory here. The part blacklist also just sets the DoNotStore flag if the part name is on the list.

Unfortunately at work I can't even read through the log file, so I'll have to get back to you later tonight.

Share this post


Link to post
Share on other sites
24 minutes ago, garwel said:

Any plans to have it listed on CKAN?

After it's not in Beta anymore I'll put it on CKAN. I'll also have it on SpaceDock then, but while in Beta it's staying on GitHub. It does have AVC support if your concern is just knowing when there are updates.

Edited by magico13

Share this post


Link to post
Share on other sites

Sorry to bother you again, @magico13!

I have a question/request: I assumed with ScrapYard installed, StageRecovery should be deleted. Should I?

If so, could you please include the parachute calculator feature in ScrapYard? Or create a tiny module that did just this parachute checking... :wink:

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.