Value editing

Started by Azuraal, September 08, 2016, 02:55:19 PM

Previous topic - Next topic

Azuraal

How do i properly make a mod that edits a value of a thing defined in core?
I want to make a mod that will make metals not flammable, i tried this:
<ThingDefs>

  <ThingDef ParentName="ResourceBase">
    <defName>Steel</defName>
    <stuffProps>
      <statFactors>
        <Flammability>0</Flammability>
      </statFactors>
    </stuffProps>
  </ThingDef>

</ThingDefs>

This, instead of refedefining steel's flammability to 0, redefines steel as something that's only property is that it's flammability is 0, which is not that surprising.
I could just brute force it and redefine it as the exact same thing with change to flammability but,
1. it is very inelegant
2. it can couse compatibility issues

So, how do i do this properly?

Master Bucketsmith

You could check out Mod Friendly Overrides in the Miniaturisation Overloaded thread.

kaptain_kavern

I try to explain :
In the xml files for your mod if you only  use the code you posted : Notice the ParentName="ResourceBase".

This mean the "game" looks for another <ThingDefs> in order to inherit it's values and add the one you wrote/change after.
(That is the "normal" behaviour in Core".)

But I'm pretty sure you haven't defined the "ResourceBase" in your mod folder. So the it can't inherit other values and the game overwrite metal defs with only the defvalue you specified.

Sorry for my bad english. Look at this post for a better explanation

CannibarRechter

So here's the deal.

#1. "ResourceBase" is found (strangely) in Items_Luxury.xml.

#2. Abstract classes are private to scope of their mod. In the case of Steel, which inherits from ResourceBase, if you want a mod to work, you must also have a copy of ResourceBase.

#3. Repeat: abstract classes are private to the scope of their mod. That means if you are tempted to modify ResourceBase, don't expect it to impact everything else in the core that inherits from ResourceBase. It won't. The only way to impact everything in the core that inherits from ResourceBase is to take a copy of everything in the core into your own mod, and have it be along side the ResourceBase copy you made.

I hope I'm stating all this correctly. I'm 100% sure of #1 and #3, and am fuzzy-sure on #2. ;-P
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

kaptain_kavern

More clear than my try. Thanks CannibarRechter

Azuraal

As a matter of fact i did define ResourceBase (just copied it really), i didn't include it because it isn't relevant to my problem and there no point in making posts longer.
Question stands.

Master Bucketsmith

You need the entire thing to change it. Otherwise, like you found out, it will think the edit you made is the ONLY data between the def tags.

That MFO found a way to override tags in defs without the need to define everything. Hence, it could be used for one mod changing parts of another mod.
I.e. you make an add-on patch for EPOE to not use it's new metals, but plasteel instead. Without having an entire copy of EPOE.

Shinzy


CannibarRechter

Oh yes. Stupid me. Didn't look carefully enough. The Rimworld modding system doesn't do line-item exceptions. It redefines the entire object. So copy the entire object, and then modify only what you want to modify.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

Azuraal

There is no such functionality? I find this kinda hard to believe,
but considering that such thing as friendly overrides exists it's hard to doubt.

ppumkin

I think defining base is like like overriding and implementing an entire class.
Unfortunate it doesn't sound like you can inherit from another class and override only the values you need.
Just commenting on how I understand it. Not entirely sure my self.
'Sharing is caring'
- Unknown

Master Bucketsmith

Quote from: ppumkin on September 10, 2016, 07:23:52 AM
I think defining base is like like overriding and implementing an entire class.
Unfortunate it doesn't sound like you can inherit from another class and override only the values you need.
Just commenting on how I understand it. Not entirely sure my self.
Sounds like you're talking about C#, but this thread's focus is on XML. ;)
The logic is the same though; you can make a child from a parent(like extending a class in C#) and you can selectively alter the data within that thingdef to use for your new instance.

CannibarRechter

> Sounds like you're talking about C#, but this thread's focus is on XML. The logic is the same though.

Indeed it is. I was surprised when I first started modding RW to find that there is an extremely tight tie between the XML and the class infrastructure. I am uncertain, but I suspect that the XML is compiled by the CLR into CLR objects much the way a C# class would be.

This is contrasted with a properties system, wherein the by-exception statements would be expected to work....
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

ppumkin

From what I understand, the XML file is used to override the values defined in the DLL. So yes, there is a 1 to 1 relation of property names in XML to what I can see in the code.

The parser of XML must be custom, because of the way you include <li> list of items and also how in the tag you define the class name. Now how far you get away with inheritance in the XML depends on the parser - But certainly it seems like you define the Base class settings and then Define a Thing of that Base class.

From what I imagine, all the parser is doing is loading values, then late binding to the already constructed object of what you have created. A bit like automapper (if you ever used that) or Dependancy Injection, but this is more like Property Injection? (Dont shoot me for that analogy please)

To actually change the behaviour of these Classes, you actually need to write your own code in C#. I am learning the source code now, and basically the Tutorials I did in XML - Map to the same properties in C#. Just in C# you can override behaviour for certain things. Like RareTick, Or drawing Positions.. and hopefully some UI related stuff, like lighting effects. I am trying to figure out how to get to that.

I have very good experience with .NET but none with Unity. From I what I see these Building types are just a massive ladder of Inheritance... but I cannot see/ or don't understand where the Unity part is manipulated. Early days though. Good learning experience though. :)
'Sharing is caring'
- Unknown

Master Bucketsmith

I don't think I've ever seen a mod that directly interacts with Unity or its assets. :O