Jump to content

[1.12.x] SimpleFuelSwitch v1.4.2: Toggle tanks' fuel type in the editor. Simple and lightweight.


Snark
 Share

Recommended Posts

The big-s wing strake has LF but was missed by this mod, so I added it to the Add_LFO_to_LF_tanks.cfg parts list

// For some parts that have LF on them, add the option to switch to LFO.
@PART[miniFuselage|noseConeAdapter|wingShuttleDelta|wingShuttleStrake|mk2FuselageShortLiquid|mk2Fuselage|mk3FuselageLF_25|mk3FuselageLF_50|mk3FuselageLF_100]:FOR[SimpleFuelSwitch]
{
	MODULE
	{
		name = ModuleSimpleFuelSwitch
	}

	MODULE
	{
		name = ModuleSwitchableResources
		resourcesId = liquid_fuel_only
		displayName = #SimpleFuelSwitch_LiquidFuel
		selectorFieldName = #SimpleFuelSwitch_fuelTypeLabel
		isDefault = true
		RESOURCE
		{
			name = LiquidFuel
			amount = #$/RESOURCE[LiquidFuel]/amount$
			maxAmount = #$/RESOURCE[LiquidFuel]/maxAmount$
		}
	}

	MODULE
	{
		name = ModuleSwitchableResources
		resourcesId = liquid_fuel_oxidizer
		displayName = #SimpleFuelSwitch_LiquidFuelAndOxidizer
		selectorFieldName = #SimpleFuelSwitch_fuelTypeLabel
		RESOURCE
		{
			name = LiquidFuel
			amount = #$/RESOURCE[LiquidFuel]/amount$
			@amount *= 0.45
			maxAmount = #$/RESOURCE[LiquidFuel]/maxAmount$
			@maxAmount *= 0.45
		}
		RESOURCE
		{
			name = Oxidizer
			amount = #$/RESOURCE[LiquidFuel]/amount$
			@amount *= 0.55
			maxAmount = #$/RESOURCE[LiquidFuel]/maxAmount$
			@maxAmount *= 0.55
		}
	}

	-RESOURCE[LiquidFuel] {}
	-RESOURCE[Oxidizer] {}
}

 

Link to comment
Share on other sites

  • 1 month later...

@Snark I'm troubleshooting a crash to desktop and I want to rule this out... I'm getting this error when a ship loads that does not have any fuel switched.

[ERR 17:33:20.712] Module ModuleSimpleFuelSwitch threw during OnStart: System.NullReferenceException: Object reference not set to an instance of an object
  at SimpleFuelSwitch.ModuleSimpleFuelSwitch.OnStart (PartModule+StartState state) [0x0000d] in <83adba40348745b29af7ae28ff479c61>:0 
  at Part.ModulesOnStart () [0x00120] in <06f13185617646e5bc801baeab53ab75>:0 

Is this normal?  I could reproduce it on a different ship. It doesn't seem to do it when launching a new ship but it does when switching back to an existing ship.

Edited by Krazy1
Link to comment
Share on other sites

11 hours ago, Krazy1 said:

Is this normal?

No, that's not normal.  No mod should ever be throwing NullReferenceException.  That generally indicates that the mod is assuming something about the state of the world (i.e. taking some condition for granted), when in fact what it needs to be checking whether that assumption is correct.  So, the fact that ModuleSimpleFuelSwitch is throwing that error means that there's a place where I missed a spot.  :blush:

I've looked into the code, and I suspect that I've identified where the problem is:

  • This mod works by adding modules (via config) to certain parts, to enable the functionality.
  • To enable SimpleFuelSwitch on a part, what one needs to add is,
    • a single ModuleSimpleFuelSwitch
    • two or more ModuleSwitchableResource (these are the options to switch among)
  • Normally, it would never be the case that one has a ModuleSimpleFuelSwitch but no ModuleSwitchableResource on a part.  (Because it's not going to work without ModuleSwitchableResource.  If one isn't going to add ModuleSwitchableResource, why add a ModuleSimpleFuelSwitch in the first place?)
  • However, it's possible that someone could add config that puts a ModuleSimpleFuelSwitch on a part, and forgets to add ModuleSwitchableResource.  So the mod should handle that case without blowing up, even though it's a case of mistaken config.
  • My code doesn't handle this case.  It blows up.  :blush:

So, that's a miss on my part.  I'll update the ModuleSimpleFuelSwitch code so that when such an abnormal situation happens, it will simply log a warning message and go inert for that part, rather than blowing up.  Thank you for bringing this to my attention!

That said... it would be interesting to know just how you (presumably) got into a situation where you've got a mis-configured SimpleFuelSwitch.  Some possibilities that spring to mind:

  • you added some config yourself?
  • there's some other mod you have installed, that interacts poorly with SimpleFuelSwitch in some way? perhaps it's mis-configured?
  • some part that I put config on, and screwed up, and the only reason I haven't noticed is because it's not a part I usually use while playing (this would be the most embarrassing)

Once I fix the bug so that SimpleFuelSwitch doesn't go kablooie when the config is wrong, this sort of situation will be easy to diagnose because you'll have a log message that will identify what part is causing the problem.

However, until that happens, the only way to figure it out would be some digging on your part.  Some questions for you:

  • Do you have any other mods (beside SimpleFuelSwitch itself) that add SimpleFuelSwitch config to anything?
  • Have you added any SimpleFuelSwitch to anything, yourself?
  • Can you narrow it down which part is causing the problem?  e.g. try making a very simple ship with just one fuel tank on it, does that reproduce the problem?  which part needs to be on there for this to happen?
Link to comment
Share on other sites

11 hours ago, Snark said:

However, until that happens, the only way to figure it out would be some digging on your part.

Yes sir. I have about 40 mods BUT almost entirely QOL stuff, not part mods. I like to keep it to a minimum; that's why I like this mod so much. I haven't tried to mod any parts myself before. So TweakScale and/ or Recall are the only other mods I could suspect. I know Mr. @Lisias has  had to write some TweakScale companions for other mod interactions before so maybe it needs one here?  I'll go make a test build with just these mods to see if I can find a good example. 

 

 

Link to comment
Share on other sites

7 minutes ago, Krazy1 said:

I know Mr. @Lisias has  had to write some TweakScale companions for other mod interactions before so maybe it needs one here?  I'll go make a test build with just these mods to see if I can find a good example. 

I don't think TweakScale would be playing a part on this one - to tell you the true, there's just no support at all for ModuleSimpleFuelSwitch neither ModuleSwitchableResource, these modules/sections are plain ignored.

But Recall may have a hole on this, as there're two workarounds that mangle Resources - but, again, disregarding these two modules what makes them perhaps a trigger, but not the perpetrator.

In which KSP this is happening? Depending of the Version, you would be using Resourceful or Refunding, and each one of these does different things on the Part's resources in different GameEvents...

Link to comment
Share on other sites

I did a clean install by copying 1.12.2 from Steam install with CKAN and just installed TweakScale, KSP Recall, MM and SFS...  First test test with a Mk1 capsule and FLT200 was good - no errors.

Thanks @Lisias  It was first found on 1.11.2. I've been troubleshooting a crash to desktop over here:

crash post

I just found a prior exception in that log I missed before, so I have more hunting to do there. 

It could be the prior exception or maybe corrupted savegame somehow? 

Only other complete guess is TAC Fuel Balancer because it happened to have a log entry just before the error and it has something to do with fuel tanks too:

[LOG 17:33:20.708] -INFO- Tac.FuelBalanceController[FFDA91D6][5194.36]: Rebuilding resource lists.
[ERR 17:33:20.712] Module ModuleSimpleFuelSwitch threw during OnStart: System.NullReferenceException: Object reference not set to an instance of an object
  at SimpleFuelSwitch.ModuleSimpleFuelSwitch.OnStart (PartModule+StartState state) [0x0000d] in <83adba40348745b29af7ae28ff479c61>:0 
  at Part.ModulesOnStart () [0x00120] in <06f13185617646e5bc801baeab53ab75>:0 

 

Link to comment
Share on other sites

On 7/15/2021 at 11:28 AM, VTOL Frog said:

The big-s wing strake has LF but was missed by this mod

Actually, I think  the whole aerodynamics tab was skipped: engine nacelle, engine precooler, Mk1 divertless supersonic intake, big-s delta wing, FAT-455 wing

 

 

 

 

Link to comment
Share on other sites

On 8/24/2021 at 2:18 AM, Krazy1 said:

Actually, I think  the whole aerodynamics tab was skipped: engine nacelle, engine precooler, Mk1 divertless supersonic intake

Yes, this was done deliberately.  That's why, if you look at Add_LFO_to_LF_tanks.cfg, I call out specific parts by name, rather than using a wildcard to just "add it to everything" as I did with LFO.

Rationale:  There are a lot of LF parts which, to me, make no sense to add LFO to.

There are a bunch of them that are directly and clearly tied to atmospheric air-breathing flight, for example.  Basically, anything that has an air intake on it, seemed to me to belong to the category of "this part is overwhelmingly used in contexts where only LF is needed", so I figured it's better not to add the switch on there, because, 1. adding any UI to anything is clutter, and 2. I loathe clutter, and 3. therefore I only add clutter if the benefit of the feature is worth the added clutter in the UI.  Since these seemed like parts that would rarely need to be switched (I certainly never switch them in my own gameplay), I figured it was better to leave it off.

On 8/24/2021 at 2:18 AM, Krazy1 said:

big-s delta wing

This one was not skipped, and I deliberately added a switch for it.  It's in there.  ;)

I added this because it's a high-temperature part that isn't necessarily used for atmospheric flight, and would be a handy place to stash LFO for a spaceplane.

The strake is missing-- I didn't notice that it contains fuel, and would have added it if I had.  This was an oversight, thanks to @VTOL Frog for pointing it out.  I'll add this.

On 8/24/2021 at 2:18 AM, Krazy1 said:

FAT-455 wing

Main reason I didn't add LFO to this one is that this part's temperature tolerance is so incredibly low that I've found it very hard to use for anything that needs to go fast enough to escape atmosphere.  In other words, my experience has been that any craft that needs LFO engines is going to be going so fast that it would burn off the FAT-455 wing anyway.  Therefore, there didn't seem to me to be much need of a switch for this one-- i.e. in my opinion, the value the switch adds would be less than the "clutter cost", so it didn't meet the bar.

 

 

That said, of course I realize that other people have play styles of their own who might prefer these deliberately-omitted parts to have the switch available.  My rationale for omitting them still applies, as far as I'm concerned, so I'd be somewhat loath to go ahead and add it to the default install.  One thing that occurs to me I could do, however, would be to create an "optional config" file (similar to what I've done with DefaultActionGroups, for example) that would be available for installing for anyone who wants it, thus saving people the need to cobble together config on their own.  Let me mull this over.

(And if anyone has ideas for other optional config that would be good to have, I'm open to suggestions, though I make no promises.) ;)

Link to comment
Share on other sites

3 hours ago, Snark said:

My rationale for omitting them still applies

Makes sense to me. I didn't know the strake had fuel. I actually looked at it when I checked the others. Time to get new glasses. :cool:

About the null ref I reported, I found that whatever is causing the crash to desktop is in the base KSP game. I hope there's still a dev around to fix this!

 

Link to comment
Share on other sites

Yeah your reasoning for the omitted parts makes sense to me, it is SIMPLEfuelswitch so a more minimalist design/reduced clutter is the idea.  There are other mods for those that want all the options. 

If you wanted to make an optional config for all LF tanks that might be kind of nice, as it would extend to mod LF tanks as well.  I skimmed some older pages before posting and realized this had been addressed.  Did the community config extensions/library idea ever come to fruition?  I may try my hand at making a config for monopropellant and some mod fuels that I could contribute.

I also wanted to say (as someone with no coding experience and who has recently started tinkering with MM patches) I greatly appreciate your extensive comments and examples.  They have helped me wrap my head around module manager a little better! o7

Link to comment
Share on other sites

  • 3 weeks later...

Just a request for a "stealth feature" sort of. If a part does not have fuel switched, it would be nice if it didn't push modules onto the part in the craft file. It would just help keep the file smaller and may help avoid issues like craft sharing on stock or differently modded installs. I am NOT having any explicit issue. Sharing craft on KerbalX through CraftManager with no switched tanks is showing up correctly as "pure stock" on KerbalX. (Lisias did this for the last version of TweakScale and there's more discussion over there.)

BTW I haven't found what mod was instigating the NRE I reported before.

Link to comment
Share on other sites

21 hours ago, Krazy1 said:

Just a request for a "stealth feature" sort of. If a part does not have fuel switched, it would be nice if it didn't push modules onto the part in the craft file. It would just help keep the file smaller and may help avoid issues like craft sharing on stock or differently modded installs. I am NOT having any explicit issue. Sharing craft on KerbalX through CraftManager with no switched tanks is showing up correctly as "pure stock" on KerbalX. (Lisias did this for the last version of TweakScale and there's more discussion over there.)

BTW I haven't found what mod was instigating the NRE I reported before.

Relevant code is here

You instrument the OnSave callback to just return (without calling base.OnSave) when:

  • Your Module is disabled; and/or
  • Your Module is on the default state; and
  • You are saving the Node into a Craft File
    • Saving it anywhere else may be problematic - or may not, but why take the risk on mangling savegames and quicksaves?

When loading the craft, the UpgradePipeline will reinject the missing modules with default values - what, essentially, it would be what you have there anyway,

The tricky part is to detect when the craft is being saved into a file, and some trial and error (and lots of stackdumps) suggests that this code does the trick. If anyone else finds a better way, I'm hearing - I don't have any love for the code, only by what it does! :) 

Cheers.

 

Edited by Lisias
Tyops, as usulla.
Link to comment
Share on other sites

On 9/13/2021 at 3:17 PM, Krazy1 said:

Just a request for a "stealth feature" sort of. If a part does not have fuel switched, it would be nice if it didn't push modules onto the part in the craft file. It would just help keep the file smaller and may help avoid issues like craft sharing on stock or differently modded installs.

Interesting!  Thanks for the suggestion, I'll consider it next time I update SimpleFuelSwitch.

20 hours ago, Lisias said:

Saving it anywhere else may be problematic - or may not, but why take the risk on mangling savegames and quicksaves?

Thanks for the concrete code examples.  Out of curiosity, though:  why the specific concern about "craft being saved into a file"?  i.e. what's the reason for thinking it's okay in a craft file, but not anywhere else?  Also, even granting that concern, why is it needed to check that ShipConstruct.SaveShip() is in the stack trace?  For example, if you're checking that HighLogic.LoadedSceneIsEditor, why is that not sufficient to cover that condition?

Link to comment
Share on other sites

24 minutes ago, Snark said:

Thanks for the concrete code examples.  Out of curiosity, though:  why the specific concern about "craft being saved into a file"?  i.e. what's the reason for thinking it's okay in a craft file, but not anywhere else?  

The goal of the stunt is to allow easier sharing of craft and less friction when switching games - why would a craft that does not use TweakScale (besides having it installed) yell on the user when TweakScale is not installed? The same for everything else.

(and it worth to mention that some changes on TweakScale internals are planned, and they may break the current assumptions about when TweakScale is not used - what would break 3rd parties that relies on that assumption, as Kerbal-X).

But on SFS files, however, why bother? These data structures are living artefacts inside the game, and definitively they are not meant to be easily shareable. Not to mention they are really more complex data structures than a craft file, so the chances of something going wrong are considerably bigger. In the end, to much at stake for virtually nothing beneficial in return.

Additionally, the OnSave thingy is used by everyone that wants to persist the craft somewhere. KCT, for example, dumps the craft into some internal data store to later put it back on the game. If I mangle the OnSave for everyone, I would potentially break 3rd-parties as KCT that trust the dumped data is exactly what the game would have in memory. They would have to call the UpgradePipeline themselves on their dumps - without any gaining, because, on this example, internal KCT data structures are definitively not meant to be shareable.

On the bottom line,  it would inject a theoretical point of failure on very critical code without any benefit. So, from the defensive point of view, any effort to minimize this risk by only applying the stunt on craft files worths the pain.

 

24 minutes ago, Snark said:

Also, even granting that concern, why is it needed to check that ShipConstruct.SaveShip() is in the stack trace?  For example, if you're checking that HighLogic.LoadedSceneIsEditor, why is that not sufficient to cover that condition?

Because some 3rd-parties works on the Editor Scene too. So, instead of trying to figure out every caller that would not want the craft mangled, I choose to detect the only situation where I know I want the craft mangled. :)

 

Edited by Lisias
Brute force post merging
Link to comment
Share on other sites

  • 3 weeks later...

Found another error message. KSP 1.12.2. I was landed on Minmus, in EVA construction mode and removed a tank and dropped it on the ground.

[LOG 15:03:06.537] [FL-T200 Fuel Tank]: landed - waiting for ground contact to resume physics...
[ERR 15:03:06.538] Module ModuleSimpleFuelSwitch threw during OnStart: System.NullReferenceException: Object reference not set to an instance of an object
  at SimpleFuelSwitch.ModuleSimpleFuelSwitch.OnStart (PartModule+StartState state) [0x0000d] in <83adba40348745b29af7ae28ff479c61>:0 
  at Part.ModulesOnStart () [0x00120] in <cd473063d3a2482f8d93d388d0c95035>:0 

The error shows up in orange text in-game. The tank was empty and was set to default LFO. Doesn't seem to be a functional issue though.  I can try to reproduce it if you want.

Link to comment
Share on other sites

  • 2 months later...

Hey Snark,

i have create a localisation fr-fr.cfg for people playing in french :)

here the brut texte. Noting special but maybe some french player will appreciate.

French Traduction :)

*******************************************

Localization
{
    fr-fr
    {
        // Labels displayed in the PAW showing what you can choose from.
        #SimpleFuelSwitch_resourceLabel = Ressource
        #SimpleFuelSwitch_fuelTypeLabel = Types de Carburant
        
        // Short display names for various resource combinations
        #SimpleFuelSwitch_LiquidFuelAndOxidizer = ELO
        #SimpleFuelSwitch_LiquidFuel = EL
        
        // Formats "primary info" display in the part info panel in the editor.
        // [0] is the label (e.g. fuelTypeLabel above).
        // [1] is the display name of the fuel option (e.g. "LFO" or whatever)
        // [2] is the quantity of resource involved.
        #SimpleFuelSwitch_primaryInfoFormat = [0] [1]: [2]
        
        // Formats the title of each of the option panes in the part info panel.
        // [0] is the label (e.g. fuelTypeLabel above).
        // [1] is the display name of the resource combination.
        #SimpleFuelSwitch_titleFormat = [0]: [1]
        
        // Same as titleFormat, except this one's applied to the default selection.
        #SimpleFuelSwitch_titleFormatDefault = [0]: [1] (Par defaut)
        
        // Formats "detailed info" for one resource in the info panel at right.
        // [0] is the display name of the resource (e.g. "Liquid Fuel")
        // [1] is the quantity (e.g. "0.3 t")
        #SimpleFuelSwitch_detailedInfoFormat = [0]: [1]
        
        // Formats a number in tons to a displayable version, with units.
        #SimpleFuelSwitch_massTonsFormat = [0:0.0##] t

        // Display name to use for a selection that has no resources in it.
        #SimpleFuelSwitch_noResources = Aucune Ressource
    }
}

********************************************

Edited by Vspace
Link to comment
Share on other sites

  • 2 months later...

Hi all,

After a very long delay (sorry about that!) :blush: I'm pleased to announce the relase of SimpleFuelSwitch v1.4.1.

New with this release:

  • Add config for the big-S wing strake.  (Thanks to @VTOL Frog for pointing out the oversight.)
  • Fix a bug in which ModuleSimpleFuelSwitch would blow up if no ModuleSwitchableResources is configured.  (Thanks to @Krazy1 for reporting.)
  • Added French localization.  (Thank you to @Vspace for generously providing!)
  • Change the display of units and mass (in the info panel in the editor) to track the max amount of resources rather than the configured amount. (Relevant for resource containers that are, for example, empty by default.)
  • Update to ModuleManager 4.2.1.

Thank you to the various folks who made helpful contributions, and again, sorry it took so long to get around to the release.  Enjoy!  :)

Link to comment
Share on other sites

  • 1 month later...
15 hours ago, sirOrange17 said:

Does this work with restock/restock+?

It will work. Restock only changes how parts look. Restock+ adds parts (which are outside the scope of this mod. This mod is not setup to catch all parts and install itself into them).

Link to comment
Share on other sites

Hi all,

I've released SimpleFuelSwitch v1.4.2.  No major new functionality; this update includes the following:

  • Correctly handles resource cost when switching resource types.
  • Now with German localization!  Thank you to @Sqeep91 for generously providing.  (A mea culpa on my part, there-- they actually provided it a couple of years ago, and I didn't notice until just recently. My apologies for being so slow on the uptake.)

That's it, that's all there is.  If you're not playing in German, and if you're only using it to work with the default switching between LFO-versus-LF, then this update does nothing for you and it's entirely optional to update.

(I never noticed, before, that the mod wasn't handling resource cost at all, because the default behavior is just to switch between LFO-versus-LF, and those are the same cost as each other per unit and therefore it makes no difference.  And in any case, most resources are pretty cheap per unit, so any errors would be not super noticeable.  What finally prompted this update was that I was playing a career with Karbonite Plus, which includes a super expensive resource in it, and I tried to use it with SimpleFuelSwitch and the part costs were bananas.  So now it works the way it ought to.)

Link to comment
Share on other sites

Question: If I change a tank with this mod, then send the craft to a friend with a vanilla install, will it still work?

I really like simple mod concepts like this one, but for the sake of compatability and share-ability I hope fuel-swapped tanks still work elsewhere.

Link to comment
Share on other sites

20 hours ago, It&#x27;snorocketscience said:

Question: If I change a tank with this mod, then send the craft to a friend with a vanilla install, will it still work?

I believe not.  Weird buggy stuff would happen.  The friend would need to have SimpleFuelSwitch installed.

Any tanks that you haven't switched and are still in their default (stock) configuration should be fine, though.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...