Editing Modding Tutorials/PatchOperations
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | |||
{{BackToTutorials}} | {{BackToTutorials}} | ||
Line 21: | Line 20: | ||
</source> | </source> | ||
− | Just as with XML Defs, folder and file names do not matter and you can freely name and organize your | + | Just as with XML Defs, folder and file names do not matter and you can freely name and organize your patche files in whatever manner you wish. Individual patches themselves are a standard XML file with <tt><Patch></tt> as the root tag: |
<source lang="xml"> | <source lang="xml"> | ||
Line 41: | Line 40: | ||
* The first segment of any XPath targeting an XML Def will be <code>Defs/</code> as all XML Defs use the <code><Defs></code> root tag. | * The first segment of any XPath targeting an XML Def will be <code>Defs/</code> as all XML Defs use the <code><Defs></code> root tag. | ||
* The square brackets denote a predicate, or conditional match. In this case, we are looking for <code>ThingDef</code>s that have a child tag <code>defName</code> equal to "Wall". | * The square brackets denote a predicate, or conditional match. In this case, we are looking for <code>ThingDef</code>s that have a child tag <code>defName</code> equal to "Wall". | ||
− | |||
− | |||
You can target Defs that do not have a <code>defName</code> (such as abstract bases) by targeting their identifying attributes. For example, if you wanted to add another Stuff category to the abstract base Def for all shelves, you might use the following xpath: | You can target Defs that do not have a <code>defName</code> (such as abstract bases) by targeting their identifying attributes. For example, if you wanted to add another Stuff category to the abstract base Def for all shelves, you might use the following xpath: | ||
Line 48: | Line 45: | ||
<code>Defs/ThingDef[@Name="ShelfBase"]/stuffCategories</code> | <code>Defs/ThingDef[@Name="ShelfBase"]/stuffCategories</code> | ||
− | + | Additional XPath resources: | |
− | |||
− | |||
− | |||
− | |||
− | |||
* [https://developer.mozilla.org/en-US/docs/Web/XPath Mozilla Developer Network] | * [https://developer.mozilla.org/en-US/docs/Web/XPath Mozilla Developer Network] | ||
* [https://www.w3schools.com/xml/xml_xpath.asp W3Schools XPath Tutorial] | * [https://www.w3schools.com/xml/xml_xpath.asp W3Schools XPath Tutorial] | ||
Line 100: | Line 92: | ||
==PatchOperationAdd== | ==PatchOperationAdd== | ||
− | Inserts the specified <code>value</code>s as a child node of the XML nodes targeted by the operation's <code>xpath</code>. By default, the new nodes will be inserted after any existing child nodes | + | Inserts the specified <code>value</code>s as a child node of the XML nodes targeted by the operation's <code>xpath</code>. By default, the new nodes will be inserted after (appended to) any existing child nodes. You can use <code><order>Prepend</order></code> in the patch operation (order is Append by default). |
Note: PatchOperationAdd will not overwrite any existing tags. If one of your <code>value</code>s overlaps with an existing node and you are not targeting a list node, then it will cause an error on game load. | Note: PatchOperationAdd will not overwrite any existing tags. If one of your <code>value</code>s overlaps with an existing node and you are not targeting a list node, then it will cause an error on game load. | ||
Line 423: | Line 415: | ||
<value> | <value> | ||
<li Class="MyNamespace.MyModExtension"> | <li Class="MyNamespace.MyModExtension"> | ||
− | <key>Value</ | + | <key>Value</exampleValue> |
</li> | </li> | ||
</value> | </value> | ||
Line 436: | Line 428: | ||
<modExtensions> | <modExtensions> | ||
<li Class="MyNamespace.MyModExtension"> | <li Class="MyNamespace.MyModExtension"> | ||
− | <key>Value</ | + | <key>Value</exampleValue> |
</li> | </li> | ||
</modExtensions> | </modExtensions> | ||
Line 528: | Line 520: | ||
</source> | </source> | ||
− | As mentioned, you can use | + | As mentioned, you can use {{Modding_Tutorials/MayRequire}} on child operations of a PatchOperationSequence, but you should test them individually before adding them to said Sequence: |
<source lang="xml"> | <source lang="xml"> |