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:
{{DISPLAYTITLE:PatchOperations}}
 
 
{{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 patch files in whatever manner you wish. Individual patches themselves are a standard XML file with <tt><Patch></tt> as the root tag:
+
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".
 
=== Targeting Attributes ===
 
  
 
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>
  
You can use the same technique to target all Defs that inherit from a common base. For example, you could use the following xpath to target all <code>ThingDef</code>s that inherit from <code>ApparelBase</code>:
+
Additional XPath resources:
 
 
<code>Defs/ThingDef[@ParentName="ApparelBase"]</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 (<code>Append</code>). You can use <code><order>Prepend</order></code> in the patch operation to insert them before existing child nodes instead.
+
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>
+
       <key>Value</exampleValue>
 
     </li>
 
     </li>
 
   </value>
 
   </value>
Line 436: Line 428:
 
   <modExtensions>
 
   <modExtensions>
 
     <li Class="MyNamespace.MyModExtension">
 
     <li Class="MyNamespace.MyModExtension">
       <key>Value</key>
+
       <key>Value</exampleValue>
 
     </li>
 
     </li>
 
   </modExtensions>
 
   </modExtensions>
Line 528: Line 520:
 
</source>
 
</source>
  
As mentioned, you can use [[Modding_Tutorials/MayRequire|MayRequire]] on child operations of a PatchOperationSequence, but you should test them individually before adding them to said Sequence:
+
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">

Please note that all contributions to RimWorld Wiki are considered to be released under the CC BY-SA 3.0 (see RimWorld Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)