Change ThingDef texpath based on in-game setting

Started by Mlie, February 28, 2020, 04:59:06 PM

Previous topic - Next topic

Mlie

How can I modify a ThingDef texpath based on a mod-setting?
I cant seem to find a way to replace the path in my ThingDef/GraphicData/texpath via C#.
Can anyone please give me an example of this?

LWM

Is this something like "User changes setting, and then the item looks blue instead of red?"

One way to do it is to have optional PatchOperations that get called based on settings.  It requires a restart to take effect, but it does work.

You can see how I did it here:  https://github.com/lilwhitemouse/RimWorld-LWM.MinorChanges/blob/master/Source/Settings.cs

More elegant is setting the textures directly, but I haven't ever done that so....dunno?  I assume you'd create a new Graphic_ of the appropriate kind and attach it to the def?

Good luck :)

Mlie

That could work, but I cannot see from your link how you implemented the PatchOperation?

LWM

There's several moving parts:

1.  The Mod Settings page.
2.  The static function IsOptionSet(string optionName) (which does MAGIC!)  (it grabs the non-static settings boolean variables "smelterIsHot" etc.
3.  The associated patch operation:  https://github.com/lilwhitemouse/RimWorld-LWM.MinorChanges/blob/master/Source/PatchOpLWMMC.cs  (PatchOperationLittleWhiteMouseMinorChanges) - which is a PatchOperationSequence that only gets applied if the mod setting associated with the optionKey is true (<optionKey>smelterIsHot</optionKey>)
4.  And the Patch operations that actually use it (https://github.com/lilwhitemouse/RimWorld-LWM.MinorChanges/blob/master/Patches/SmithiesAndComputersGetHot.xml)

You are welcome to ruthlessly copy the PatchOpLWMMC.cs (do be good and use some sort of open source license in your mod, eh? So helpful!) and then set up some sort of Mod Settings, and then copy the static function IsOptionSet from the settings page ("Settings.IsOptionSet(...)" is referring to "LWM.MinorChanges.Settings.IsOptionSet()" by the way, not to an Ludeon Settings.IsOptionSet())

Is that a more helpful walkthru (run-thru - I was still brief)?

--LWM