From d04ad493935879babe20a05d5529a0accb641f76 Mon Sep 17 00:00:00 2001 From: c0ffee Date: Sun, 16 Jan 2022 16:42:31 -0800 Subject: [PATCH] patch operation add or replace --- 1.3/Patches/CompatibilityPatch_HCSK.xml | 21 ++++--- .../{ => Utilities}/AnimationUtility.cs | 0 .../Utilities/PatchOperationAddOrReplace.cs | 59 +++++++++++++++++++ Rimworld-Animations.csproj | 3 +- 4 files changed, 75 insertions(+), 8 deletions(-) rename 1.3/Source/{ => Utilities}/AnimationUtility.cs (100%) create mode 100644 1.3/Source/Utilities/PatchOperationAddOrReplace.cs diff --git a/1.3/Patches/CompatibilityPatch_HCSK.xml b/1.3/Patches/CompatibilityPatch_HCSK.xml index 2c0b7a0..ead8783 100644 --- a/1.3/Patches/CompatibilityPatch_HCSK.xml +++ b/1.3/Patches/CompatibilityPatch_HCSK.xml @@ -9,20 +9,27 @@ Always
  • - /Defs/Verse.ThingDef/comps + /Defs/ThingDef/comps Always - /Defs/Verse.ThingDef - - - + /Defs/ThingDef + + + +
  • + +
  • + /Defs/ThingDef[@Name="SK_BasePawn"]/comps + +
  • +
  • - /Defs/Verse.ThingDef/comps + /Defs/ThingDef[@Name="BaseAnimalPawn"]/comps -
  • +
  • diff --git a/1.3/Source/AnimationUtility.cs b/1.3/Source/Utilities/AnimationUtility.cs similarity index 100% rename from 1.3/Source/AnimationUtility.cs rename to 1.3/Source/Utilities/AnimationUtility.cs diff --git a/1.3/Source/Utilities/PatchOperationAddOrReplace.cs b/1.3/Source/Utilities/PatchOperationAddOrReplace.cs new file mode 100644 index 0000000..4e1bd85 --- /dev/null +++ b/1.3/Source/Utilities/PatchOperationAddOrReplace.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; +using Verse; + +namespace Rimworld_Animations +{ + public class PatchOperationAddOrReplace : PatchOperationPathed + { + + protected string key; + private XmlContainer value; + + protected override bool ApplyWorker(XmlDocument xml) + { + XmlNode valNode = value.node; + bool result = false; + IEnumerator enumerator = xml.SelectNodes(xpath).GetEnumerator(); + try + { + while (enumerator.MoveNext()) + { + object obj = enumerator.Current; + result = true; + XmlNode parentNode = obj as XmlNode; + XmlNode xmlNode = parentNode.SelectSingleNode(key); + if (xmlNode == null) + { + // Add - Add node if not existing + xmlNode = 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 + { + IDisposable disposable = enumerator as IDisposable; + if (disposable != null) + { + disposable.Dispose(); + } + } + return result; + } + + } + +} diff --git a/Rimworld-Animations.csproj b/Rimworld-Animations.csproj index 1d6c58a..196c846 100644 --- a/Rimworld-Animations.csproj +++ b/Rimworld-Animations.csproj @@ -65,6 +65,7 @@ + @@ -76,7 +77,7 @@ - +