Skip to content

XPath Patching

Tahvohck edited this page Mar 18, 2021 · 5 revisions

Overview

Full documentation on this feature should always reference the Rimworld API. If an operation is incorrectly supported please open a new issue.

The patch operations use XPath to identify which node to edit. A tutorial on how XPath works can be found here.

If you want to include a patch file but have the modloader skip it, add a <NoLoad /> tag inside the <Patch>

Specifics

All patches go in the patches/ folder.
Patches can be applied to any of the files supported by clobber-patching. The modloader will load any files starting with the name of a valid file to edit, so for example: haven_MyFancyPatch.xml will edit the haven file.

Operations

As a reminder, the PatchOperation prefix is dropped in this implementation. The following operations are supported:

  • Add adds a provided child node to the selected node
  • Insert adds a provided sibling node to the selected node
  • Remove deletes the selected node
  • Replace replaces the selected node with the provided node
  • AttributeAdd adds a provided attribute to the selected node if and only if the attribute name is not already present
  • AttributeSet sets a provided attribute for the selected node, overwriting the attribute value if the attribute name is already present
  • AttributeRemove removes an attribute for the selected node

In addition, a custom operation specific to the modloader is also supported: AttributeMath
It can perform add, subtract, multiply, and divide mathematics on a given attribute.
Example:

<Patch>
    <!-- This patch multiplies the capacity of any structure that has a powergrid node with a capacity attribute. -->
    <Operation Class="AttributeMath">
        <xpath>/data/Element/me/data/l/element/features/powerGrid[@capacity]</xpath>
        <attribute>capacity</attribute>
        <value opType="multiply">4</value>
    </Operation>
</Patch>
Clone this wiki locally