You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<OperationClass="[YOUR C# MOD NAMESPACE].PatchOperationAddOrReplace">
<xpath>/Defs/ThingDef[defName="Plant_TreeBirch"]/plant</xpath>
<key>growDays</key>
<value>22</value>
</Operation>
The class you need to add to your C# code
using System;using System.Collections;using System.Xml;using Verse;namespace[INSERT YOUR MOD NAMESPACE HERE]{/* * A custom patch operation to simplify sequence patch operations when defensively adding fields * Code by Lanilor (https://github.com/Lanilor) * This code is provided "as-is" without any warrenty whatsoever. Use it on your own risk. */publicclassPatchOperationAddOrReplace: PatchOperationPathed
{protectedstringkey;privateXmlContainervalue;protectedoverrideboolApplyWorker(XmlDocumentxml){XmlNodevalNode= value.node;boolresult=false;IEnumeratorenumerator= xml.SelectNodes(xpath).GetEnumerator();try{while(enumerator.MoveNext()){objectobj= enumerator.Current;result=true;XmlNodeparentNode= obj as XmlNode;XmlNodexmlNode= parentNode.SelectSingleNode(key);if(xmlNode==null){// Add - Add node if not existingxmlNode= parentNode.OwnerDocument.CreateElement(key);
parentNode.AppendChild(xmlNode);}else{// Replace - Clear existing children
xmlNode.RemoveAll();}// (Re)add value
xmlNode.AppendChild(parentNode.OwnerDocument.ImportNode(valNode.FirstChild,true));}}finally{IDisposabledisposable= enumerator as IDisposable;if(disposable!=null){
disposable.Dispose();}}returnresult;}}}