StygianBlack

Resource converter - adding slider and switching output resource

Recommended Posts

I've been trying for the past few days to figure out a way to implement several things to a resource converter:

  • A slider that will allow me to control the ratio of the output resource in a manner similar to reactors. The lower the slider, the less EC used and the less output resource.
  • A resource output switch similar to Interstellar Fuel Switch that would allow me to change the output resource in editor or in flight.

As was obvious I have had no success. Are there perhaps any modules, in other mods, that might be used to implement such things?

Edited by StygianBlack

Share this post


Link to post
Share on other sites

I don't think it's doable via config only-- pretty sure you'll need some plugin code for that.

Assuming that you're okay with coding, though, I think it should be reasonably straightforward to do.

Making a slider to choose "output level":

Here's one way you could do it-- not sure if it's necessarily the "best", but is reasonably simple and I think would perform well.

  1. Make your own PartModule that derives from ModuleResourceConverter.  I'll call it StygianConverter here, for short.
  2. Add a floating-point field to StygianConverter, called (for example) throttle,  suitably annotated with a KSPField, so that the user gets a UI slider that they can drag to choose any level from 1% to 100%.  Default would presumably be 100%.
    • Also add a field previousThrottle, which is initialized to some non-value like NaN.  Used for caching purposes, see below.
  3. ModuleResourceConverter has a virtual property on it, Recipe.  Override it.
    • The base-class implementation is that the recipe is fixed, so it's just loaded once and stored in a data member, _recipe, which is simply served up whenever it's asked for.
    • In your override, you call the base class' implementation, then check to see whether throttle == previousThrottle.
    • If true, just return the recipe you got.
    • If false, then set previousThrottle = throttle, tinker with the recipe to adjust the numbers appropriately, cache that value in the _recipe field, and then return it.
  4. Profit!

 

Choosing from among different outputs:

Well, one option is to do what the ISRU does, and just put multiple converters on the part.  This can be done with config only, and needs no coding.

However, if you want it so that the user has to select just one thing to convert... well, I expect you could do that with a custom ModuleResourceConverter subclass, using techniques similar to the above.  You'd add a cycle-among-N-values field to the part's UI (so the user could click-click-click until they get to the resource they want), and the Recipe implementation would need to take into account both "did the throttle change?" and "did the selected resource change?"

You'd need to come up with some custom wiring to allow specifying the multiple recipes in config, though (assuming you're not hard-coding this in your C#), which would be additional work.

Share this post


Link to post
Share on other sites

For the second: Depending on how you want to implement it, both the current MKS and Pathfinder mods have something that could work.

Share this post


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

I don't think it's doable via config only-- pretty sure you'll need some plugin code for that.

Assuming that you're okay with coding, though, I think it should be reasonably straightforward to do.

Making a slider to choose "output level":

Here's one way you could do it-- not sure if it's necessarily the "best", but is reasonably simple and I think would perform well.

  1. Make your own PartModule that derives from ModuleResourceConverter.  I'll call it StygianConverter here, for short.
  2. Add a floating-point field to StygianConverter, called (for example) throttle,  suitably annotated with a KSPField, so that the user gets a UI slider that they can drag to choose any level from 1% to 100%.  Default would presumably be 100%.
    • Also add a field previousThrottle, which is initialized to some non-value like NaN.  Used for caching purposes, see below.
  3. ModuleResourceConverter has a virtual property on it, Recipe.  Override it.
    • The base-class implementation is that the recipe is fixed, so it's just loaded once and stored in a data member, _recipe, which is simply served up whenever it's asked for.
    • In your override, you call the base class' implementation, then check to see whether throttle == previousThrottle.
    • If true, just return the recipe you got.
    • If false, then set previousThrottle = throttle, tinker with the recipe to adjust the numbers appropriately, cache that value in the _recipe field, and then return it.
  4. Profit!

 

Choosing from among different outputs:

Well, one option is to do what the ISRU does, and just put multiple converters on the part.  This can be done with config only, and needs no coding.

However, if you want it so that the user has to select just one thing to convert... well, I expect you could do that with a custom ModuleResourceConverter subclass, using techniques similar to the above.  You'd add a cycle-among-N-values field to the part's UI (so the user could click-click-click until they get to the resource they want), and the Recipe implementation would need to take into account both "did the throttle change?" and "did the selected resource change?"

You'd need to come up with some custom wiring to allow specifying the multiple recipes in config, though (assuming you're not hard-coding this in your C#), which would be additional work.

I fear my meager to almost inexistent coding skills would be as useful to me as trying to solve the horoscope. I guess, when I have some free time I'll have to bone up on my coding. I appreciate the help either way.

Share this post


Link to post
Share on other sites
38 minutes ago, DStaal said:

For the second: Depending on how you want to implement it, both the current MKS and Pathfinder mods have something that could work.

Thanks, I'll check it out.

Share this post


Link to post
Share on other sites
2 hours ago, DStaal said:

For the second: Depending on how you want to implement it, both the current MKS and Pathfinder mods have something that could work.

 

1 hour ago, StygianBlack said:

Thanks, I'll check it out.

What you'll be looking for is the "WildBlue Tools"... theres also a seperate Git Repo for it... It has a nice GUI interface where you can choose all kinds of stuff, but I'm not sure if it has converter functionality, much less user selectable converter ratios... I had thought Angel-125 would have used it in the Snacks Continued mod, but it seems he didnt use his WBTools at all for it...

I cant remember if allista's AT_Utilities does what you want, but you can check that out... allista also has a seperate Git repo for THAT utility... You can find links on any of his mod release threads or his sig, IIRC....
Actually, search for "Configurable Containers" mod... Pretty sure thats his newest mod, and that he used his utility with that...

MKS, ie all or most of RoverDude's USI mods, use his USI Toolkit... Not sure if he even has a GUI for that though... I havent used any USI stuff yet... I DO know, HE also has a seperate repo for that, as well...

 

Edited by Stone Blue

Share this post


Link to post
Share on other sites
4 hours ago, Stone Blue said:

 

What you'll be looking for is the "WildBlue Tools"... theres also a seperate Git Repo for it... It has a nice GUI interface where you can choose all kinds of stuff, but I'm not sure if it has converter functionality, much less user selectable converter ratios... I had thought Angel-125 would have used it in the Snacks Continued mod, but it seems he didnt use his WBTools at all for it...

I cant remember if allista's AT_Utilities does what you want, but you can check that out... allista also has a seperate Git repo for THAT utility... You can find links on any of his mod release threads or his sig, IIRC....
Actually, search for "Configurable Containers" mod... Pretty sure thats his newest mod, and that he used his utility with that...

MKS, ie all or most of RoverDude's USI mods, use his USI Toolkit... Not sure if he even has a GUI for that though... I havent used any USI stuff yet... I DO know, HE also has a seperate repo for that, as well...

 

Of RoverDude's USI mods I use Karbonite, which comes with the obligatory USI Core and USI Tools. In fact the resource converter I'm trying to make is based of a Karbonite converter. The thing about Karbonite is that it still uses a conversion system identical to ISRU. I can write up modules to convert X resource into Y resource at various speeds but it becomes a little more complicated because in game the left-click menu will the become flooded with Convert X to Y slow, fast, very fast etc. Even worse if I try multiple resources. So that's kind of a no go for now.

I did check up Wild Blue Tools, apparently in the source code there are files for Converter and Multi Converter. I'm not good with coding at all so I kinda can't make sense of what and how you're supposed to go about using it. I get that you need to at least put the files in the GameData folder but other than that I don't know what the components of the module are and how you make it work. Before this I worked using only pre-existing part files as a basis. Please advise.

Also, what the heck are the Plasma Screens and kPads used for?

Edited by StygianBlack

Share this post


Link to post
Share on other sites

For the Wild Blue Tools - I pointed you at Pathfinder because it has examples on how to use it, in the Pathfinder parts themselves.  Take a look at the config files for the Hacienda and the Golddigger, as well as the files in the Templates folder - what you need to do is create templates for your various converters and then have the part say which templates it can use.

MKS's are a bit simpler - and note I'm saying *MKS*, not USI: It's part of the recent MKS release.  For that you'll want to look at some of the Tundra parts configs or the drills - everything for each part is in it's own config file.

Share this post


Link to post
Share on other sites
22 minutes ago, DStaal said:

For the Wild Blue Tools - I pointed you at Pathfinder because it has examples on how to use it, in the Pathfinder parts themselves.  Take a look at the config files for the Hacienda and the Golddigger, as well as the files in the Templates folder - what you need to do is create templates for your various converters and then have the part say which templates it can use.

MKS's are a bit simpler - and note I'm saying *MKS*, not USI: It's part of the recent MKS release.  For that you'll want to look at some of the Tundra parts configs or the drills - everything for each part is in it's own config file.

Nice. Thanks, that helped a lot. But I don't know what the kPad does.

Share this post


Link to post
Share on other sites
3 minutes ago, StygianBlack said:

Nice. Thanks, that helped a lot. But I don't know what the kPad does.

It's intended to allow you to see images from cameras you place around your vehicle I believe, though I don't think he's ever gotten that to work.  I believe it can be set to show a screenshot you've taken.  (Or another image in the same folder.)

Share this post


Link to post
Share on other sites

Another approach:

  • add multiple ModuleResourceConverters to the part, one for each recipe you want
  • write a custom module that:
    • allow the user to select an index in the editor, using one of the facilities that KSP provide (eg: a KSPEvent in the module UI)
    • disable all converter modules except the one at index specified, by setting their 'isEnabled' property to false
  • add the custom module to the part

Share this post


Link to post
Share on other sites

What @ShotgunNinja just detailed is what USI Tools does with ModuleSwappableConverter.  But yeah, for what you are trying to achieve, a part module that overrides or enhances a converter is the way to go (USITools has examples where I override harvesters and converters to add a bit of sugar to them).

Share this post


Link to post
Share on other sites
31 minutes ago, RoverDude said:

What @ShotgunNinja just detailed is what USI Tools does with ModuleSwappableConverter.  But yeah, for what you are trying to achieve, a part module that overrides or enhances a converter is the way to go (USITools has examples where I override harvesters and converters to add a bit of sugar to them).

If you've read some of the previous of my comments, you might notice that I've described my coding skills as very very lacking.

Regardless, I've noticed once in a module (Science Full Reward) that it used a very simple method of applying its effect by making the science received equivalent to the science cap. I wondered whether it was possible to, say, use the Interstellar Fuel Switch's fuel switching capability to grab the name of the fuel tank content and apply it to the converter output resource. In other words, when I switch the fuel of the "tank", it also switches the fuel being processed.

Can KSP modules do that?

Edited by StygianBlack

Share this post


Link to post
Share on other sites
2 minutes ago, RoverDude said:

Not without coding.

Oh well, guess I'll have to just learn more coding in the future. Thanks, anyway.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now