patch operation add or replace
This commit is contained in:
parent
c3a93a448f
commit
d04ad49393
|
@ -9,20 +9,27 @@
|
||||||
<success>Always</success>
|
<success>Always</success>
|
||||||
<operations>
|
<operations>
|
||||||
<li Class="PatchOperationConditional">
|
<li Class="PatchOperationConditional">
|
||||||
<xpath>/Defs/Verse.ThingDef/comps</xpath>
|
<xpath>/Defs/ThingDef/comps</xpath>
|
||||||
<success>Always</success>
|
<success>Always</success>
|
||||||
<nomatch Class="PatchOperationAdd">
|
<nomatch Class="PatchOperationAdd">
|
||||||
<xpath>/Defs/Verse.ThingDef</xpath>
|
<xpath>/Defs/ThingDef</xpath>
|
||||||
<value>
|
<value>
|
||||||
<comps />
|
<comps />
|
||||||
</value>
|
</value>
|
||||||
</nomatch>
|
</nomatch>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li Class="PatchOperationAdd">
|
||||||
|
<xpath>/Defs/ThingDef[@Name="SK_BasePawn"]/comps</xpath>
|
||||||
|
<value>
|
||||||
|
<li Class="Rimworld_Animations.CompProperties_BodyAnimator" />
|
||||||
|
</value>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li Class="PatchOperationAdd">
|
<li Class="PatchOperationAdd">
|
||||||
<xpath>/Defs/Verse.ThingDef/comps</xpath>
|
<xpath>/Defs/ThingDef[@Name="BaseAnimalPawn"]/comps</xpath>
|
||||||
<value>
|
<value>
|
||||||
<li Class="Rimworld_Animations.CompProperties_BodyAnimator" />
|
<li Class="Rimworld_Animations.CompProperties_BodyAnimator" />
|
||||||
</value>
|
</value>
|
||||||
</li>
|
</li>
|
||||||
</operations>
|
</operations>
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -65,6 +65,7 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="1.3\Source\Utilities\PatchOperationAddOrReplace.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="1.3\Source\Actors\Actor.cs" />
|
<Compile Include="1.3\Source\Actors\Actor.cs" />
|
||||||
<Compile Include="1.3\Source\Actors\AlienRaceOffset.cs" />
|
<Compile Include="1.3\Source\Actors\AlienRaceOffset.cs" />
|
||||||
|
@ -76,7 +77,7 @@
|
||||||
<Compile Include="1.3\Source\Animations\Keyframes\Keyframe.cs" />
|
<Compile Include="1.3\Source\Animations\Keyframes\Keyframe.cs" />
|
||||||
<Compile Include="1.3\Source\Animations\Keyframes\PawnKeyframe.cs" />
|
<Compile Include="1.3\Source\Animations\Keyframes\PawnKeyframe.cs" />
|
||||||
<Compile Include="1.3\Source\Animations\Keyframes\ThingKeyframe.cs" />
|
<Compile Include="1.3\Source\Animations\Keyframes\ThingKeyframe.cs" />
|
||||||
<Compile Include="1.3\Source\AnimationUtility.cs" />
|
<Compile Include="1.3\Source\Utilities\AnimationUtility.cs" />
|
||||||
<Compile Include="1.3\Source\Comps\CompBodyAnimator.cs" />
|
<Compile Include="1.3\Source\Comps\CompBodyAnimator.cs" />
|
||||||
<Compile Include="1.3\Source\Comps\CompProperties_BodyAnimator.cs" />
|
<Compile Include="1.3\Source\Comps\CompProperties_BodyAnimator.cs" />
|
||||||
<Compile Include="1.3\Source\Comps\CompProperties_ThingAnimator.cs" />
|
<Compile Include="1.3\Source\Comps\CompProperties_ThingAnimator.cs" />
|
||||||
|
|
Loading…
Reference in New Issue