A17; changes

Started by Fluffy (l2032), May 06, 2017, 08:40:27 AM

Previous topic - Next topic

AngleWyrm

My 5-point rating system: Yay, Kay, Meh, Erm, Bleh

SihvMan

Something to note, having made a half dozen patches recently. This might be a "no duh" for some, but I'll include it for completeness' sake.

When patching using the <Patch> method, you cannot patch to an Base/Abstract. The way RimWorld loads mods makes it load Abstract->Def->Patch, such that the inheritors receive the un-patched abstract.

That being said, you can patch Defs that have inherited abstracts, as though the stuff in the abstract is actually in the inheritor's Def. Ex: If the abstract has <comps>, but the inheritor does not, a patch's <xpath> can be
<xpath>//ThingDef[defName = "InheritorDef"]/comps</xpath>
but not
<xpath>//ThingDef[defName = "AbstractDef"]/comps</xpath>

Also, when patching to <comps> you can patch to specific comps with
<xpath>//ThingDef[defName = "ExampleDef"]/comps/li[@Class="CompProperties_ExampleProperty"]</xpath>

This can used in the place of li(#) if you're patching multiple things with similar comps, in case the comp being patched is in multiple Defs at different list #'s (fringe case, but was useful when I made the patch for Anonemous2's MoreFurniture).

NoImageAvailable

#17
Quote from: SihvMan on May 22, 2017, 07:45:09 AM
When patching using the <Patch> method, you cannot patch to an Base/Abstract. The way RimWorld loads mods makes it load Abstract->Def->Patch, such that the inheritors receive the un-patched abstract.

Just did a test mod and this is not the case as of 0.17.1543. For reference, the patch I used was:

<?xml version="1.0" encoding="utf-8" ?>
<Patch>

<Operation Class="PatchOperationReplace">
  <xpath>//DamageDef[@Name = "LocalInjuryBase"]/workerClass</xpath>
  <value>
    <workerClass>DamageWorker_Flame</workerClass>
  </value>
</Operation>

</Patch>


The change carried through to all child defs.

From what I've been told the under-the-hood process is XML files are loaded into memory, patches are applied and then the XML parser interprets things like abstracts into actual game objects.

Edit: Another thing you can do with def inheritance is use PatchOperationAddAttribute to add a Name to a vanilla def, then have your own defs inherit from it. I imagine you could also use that method to mess around with inheritance of vanilla defs to change their base defs and such (didn't test this one though).
"The power of friendship destroyed the jellyfish."