diff --git a/1.5/Assemblies/Rimworld-Animations.dll b/1.5/Assemblies/Rimworld-Animations.dll
index 5d55c62..87dd739 100644
Binary files a/1.5/Assemblies/Rimworld-Animations.dll and b/1.5/Assemblies/Rimworld-Animations.dll differ
diff --git a/1.5/Defs/AnimationDefs/TestAnimation1.xml b/1.5/Defs/AnimationDefs/TestAnimation1.xml
index d29a4fd..caee678 100644
--- a/1.5/Defs/AnimationDefs/TestAnimation1.xml
+++ b/1.5/Defs/AnimationDefs/TestAnimation1.xml
@@ -43,7 +43,7 @@
0
0
North
- false
+ true
50
@@ -55,7 +55,7 @@
100
30
East
- false
+ true
@@ -110,16 +110,19 @@
true
+ 1
100
0
false
+ 2
200
0
true
+ 1
300
0
true
diff --git a/1.5/Defs/AnimationPropDefs/AnimationPropDef.xml b/1.5/Defs/AnimationPropDefs/AnimationPropDef.xml
index f635ce5..df53d62 100644
--- a/1.5/Defs/AnimationPropDefs/AnimationPropDef.xml
+++ b/1.5/Defs/AnimationPropDefs/AnimationPropDef.xml
@@ -12,13 +12,20 @@
AnimProp_Banana
- Rimworld_Animations.PawnRenderNodeWorker_AnimationProp
+ Rimworld_Animations.PawnRenderNode_GraphicVariants
+ Rimworld_Animations.PawnRenderNodeWorker_GraphicVariants
+
RenderNodeTag_Banana
Body
AnimationProps/Banana/Banana
Head
95
+
+
+ AnimationProps/Cat/Cat1
+ AnimationProps/Cat/Cat2
+
diff --git a/1.5/Source/AnimationProps/AnimationPropDef.cs b/1.5/Source/AnimationProps/AnimationPropDef.cs
index 9acab99..1b4c1c3 100644
--- a/1.5/Source/AnimationProps/AnimationPropDef.cs
+++ b/1.5/Source/AnimationProps/AnimationPropDef.cs
@@ -10,7 +10,7 @@ namespace Rimworld_Animations
public class AnimationPropDef : Def
{
- public PawnRenderNodeProperties animPropProperties;
+ public PawnRenderNodeProperties_GraphicVariants animPropProperties;
}
}
diff --git a/1.5/Source/AnimationWorkers/AnimationWorker_KeyframesExtended.cs b/1.5/Source/AnimationWorkers/AnimationWorker_KeyframesExtended.cs
index acc531f..ae12151 100644
--- a/1.5/Source/AnimationWorkers/AnimationWorker_KeyframesExtended.cs
+++ b/1.5/Source/AnimationWorkers/AnimationWorker_KeyframesExtended.cs
@@ -8,7 +8,7 @@ using Verse;
namespace Rimworld_Animations
{
- class AnimationWorker_KeyframesExtended : AnimationWorker_Keyframes
+ public class AnimationWorker_KeyframesExtended : AnimationWorker_Keyframes
{
public AnimationWorker_KeyframesExtended(AnimationDef def, Pawn pawn, AnimationPart part, PawnRenderNode node) : base(def, pawn, part, node)
@@ -110,14 +110,59 @@ namespace Rimworld_Animations
}
- public bool shouldRecache(int tick)
+ public virtual bool shouldRecache(int tick)
{
- if (facingAtTick(tick) != facingAtTick(tick - 1) || visibleAtTick(tick) != visibleAtTick(tick - 1))
+ if (facingAtTick(tick) != facingAtTick(tick - 1)
+ || visibleAtTick(tick) != visibleAtTick(tick - 1)
+ || TexPathVariantAtTick(tick) != TexPathVariantAtTick(tick - 1))
{
return true;
}
return true;
}
+
+ public int? TexPathVariantAtTick(int tick)
+ {
+
+ //if ticks are < first keyframe tick, just be stuck to first keyframe rot
+ if (tick <= this.part.keyframes[0].tick)
+ {
+
+ return (this.part.keyframes[0] as ExtendedKeyframe).variant;
+
+ }
+
+ //if ticks are > last keyframe tick, just be stuck to last keyframe rot
+ if (tick >= this.part.keyframes[this.part.keyframes.Count - 1].tick)
+ {
+
+ return (this.part.keyframes[this.part.keyframes.Count - 1] as ExtendedKeyframe).variant;
+
+ }
+ Verse.Keyframe keyframe = this.part.keyframes[0];
+ Verse.Keyframe keyframe2 = this.part.keyframes[this.part.keyframes.Count - 1];
+ int i = 0;
+ while (i < this.part.keyframes.Count)
+ {
+ if (tick <= this.part.keyframes[i].tick)
+ {
+ keyframe2 = this.part.keyframes[i];
+ if (i > 0)
+ {
+ keyframe = this.part.keyframes[i - 1];
+ break;
+ }
+ break;
+ }
+ else
+ {
+ i++;
+ }
+ }
+
+ return (keyframe as ExtendedKeyframe).variant;
+
+ }
}
}
diff --git a/1.5/Source/Comps/CompExtendedAnimator.cs b/1.5/Source/Comps/CompExtendedAnimator.cs
index 212f81f..a34c8ed 100644
--- a/1.5/Source/Comps/CompExtendedAnimator.cs
+++ b/1.5/Source/Comps/CompExtendedAnimator.cs
@@ -138,7 +138,7 @@ namespace Rimworld_Animations {
if (AnimationMakesUseOfProp(animationProp))
{
//create new render node
- PawnRenderNode animRenderNode = new PawnRenderNode(pawn, animationProp.animPropProperties, pawn.Drawer.renderer.renderTree);
+ PawnRenderNode_GraphicVariants animRenderNode = new PawnRenderNode_GraphicVariants(pawn, animationProp.animPropProperties, pawn.Drawer.renderer.renderTree);
animRenderNodes.Add(animRenderNode);
}
@@ -160,20 +160,17 @@ namespace Rimworld_Animations {
// never true if not animating; anim props shouldn't be attached
if (!IsAnimating) return false;
- //for all queued animations,
- foreach (AnimationDef animation in animationQueue)
+ //for ONLY THE CURRENT animation,
+ foreach (PawnRenderNodeTagDef propTag in animationQueue[0].animationParts.Keys)
{
- // for each prop tag in the currently playing animation,
- foreach (PawnRenderNodeTagDef propTag in animation.animationParts.Keys)
+ // if that proptag is the same as the one for animationProp,
+ if (propTag == animationProp.animPropProperties.tagDef)
{
- // if that proptag is the same as the one for animationProp,
- if (propTag == animationProp.animPropProperties.tagDef)
- {
- //that prop is being used in the animation
- return true;
- }
+ //that prop is being used in the animation
+ return true;
}
}
+
return false;
}
diff --git a/1.5/Source/Keyframes/ExtendedKeyframe.cs b/1.5/Source/Keyframes/ExtendedKeyframe.cs
index ef08e9b..642fc63 100644
--- a/1.5/Source/Keyframes/ExtendedKeyframe.cs
+++ b/1.5/Source/Keyframes/ExtendedKeyframe.cs
@@ -10,9 +10,9 @@ namespace Rimworld_Animations
{
public class ExtendedKeyframe : Verse.Keyframe
{
+ public int? variant;
public Rot4 rotation = Rot4.North;
public SoundDef sound = null;
public bool visible = true;
-
}
}
diff --git a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs
index 81c9fa4..a0741cd 100644
--- a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs
+++ b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs
@@ -32,7 +32,8 @@ namespace Rimworld_Animations
//cheaper call now comparing prev tick to cur tick
//not necessary because of new rendernodeworker hiding props now
- //return extendedAnimWorker.visibleAtTick(__instance.tree.AnimationTick);
+ //nvm, keep it because you can hide head and body too, if need be
+ return extendedAnimWorker.visibleAtTick(__instance.tree.AnimationTick);
}
@@ -40,4 +41,17 @@ namespace Rimworld_Animations
}
}
+
+ // For changing texture path of thing to variant
+ [HarmonyPatch(typeof(PawnRenderNode), "TexPathFor")]
+ public static class HarmonyPatch_PawnRenderNode2
+ {
+ public static void Postfix(ref PawnRenderNode __instance, ref string __result)
+ {
+ if (__instance.AnimationWorker is AnimationWorker_KeyframesExtended animWorker)
+ {
+ __result += animWorker.TexPathVariantAtTick(__instance.tree.AnimationTick);
+ }
+ }
+ }
}
diff --git a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNodeWorker.cs b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNodeWorker.cs
new file mode 100644
index 0000000..0612d8b
--- /dev/null
+++ b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNodeWorker.cs
@@ -0,0 +1,37 @@
+using HarmonyLib;
+using RimWorld;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Verse;
+
+namespace Rimworld_Animations
+{
+
+ [HarmonyPatch(typeof(PawnRenderNodeWorker), "CanDrawNow")]
+ public class HarmonyPatch_PawnRenderTreeWorker
+ {
+ public static bool Prefix(PawnRenderNode node, ref bool __result)
+ {
+ //switching to this system so that head or body can be hidden separate from other nodes
+ //(hide head but not addons, etc)
+ //in case someone wanted to do that
+
+ if (node.AnimationWorker is AnimationWorker_KeyframesExtended animWorker)
+ {
+ if (!animWorker.visibleAtTick(node.tree.AnimationTick))
+ {
+ __result = false;
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ }
+
+}
+
diff --git a/1.5/Source/PawnRenderNode/PawnRenderNodeProperties_GraphicVariants.cs b/1.5/Source/PawnRenderNode/PawnRenderNodeProperties_GraphicVariants.cs
new file mode 100644
index 0000000..7667a26
--- /dev/null
+++ b/1.5/Source/PawnRenderNode/PawnRenderNodeProperties_GraphicVariants.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Verse;
+
+namespace Rimworld_Animations
+{
+ public class PawnRenderNodeProperties_GraphicVariants : PawnRenderNodeProperties
+ {
+
+ public List texPathVariants;
+
+ }
+}
diff --git a/1.5/Source/PawnRenderNode/PawnRenderNodeWorker_AnimationProp.cs b/1.5/Source/PawnRenderNode/PawnRenderNodeWorker_AnimationProp.cs
deleted file mode 100644
index c2d7622..0000000
--- a/1.5/Source/PawnRenderNode/PawnRenderNodeWorker_AnimationProp.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Verse;
-
-namespace Rimworld_Animations
-{
- public class PawnRenderNodeWorker_AnimationProp : PawnRenderNodeWorker
- {
- public override bool CanDrawNow(PawnRenderNode node, PawnDrawParms parms)
- {
- if (node.AnimationWorker is AnimationWorker_KeyframesExtended propAnimator)
- {
- return propAnimator.visibleAtTick(node.tree.AnimationTick);
- }
-
- return false;
- }
-
- }
-}
diff --git a/1.5/Source/PawnRenderNode/PawnRenderNodeWorker_GraphicVariants.cs b/1.5/Source/PawnRenderNode/PawnRenderNodeWorker_GraphicVariants.cs
new file mode 100644
index 0000000..15b5a92
--- /dev/null
+++ b/1.5/Source/PawnRenderNode/PawnRenderNodeWorker_GraphicVariants.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using UnityEngine;
+using Verse;
+
+namespace Rimworld_Animations
+{
+ public class PawnRenderNodeWorker_GraphicVariants : PawnRenderNodeWorker
+ {
+
+ public override bool CanDrawNow(PawnRenderNode node, PawnDrawParms parms)
+ {
+ if (parms.Portrait) return false;
+
+ //don't draw if not visible at tick
+ if (node.AnimationWorker is AnimationWorker_KeyframesExtended extendedAnimator
+ && !extendedAnimator.visibleAtTick(node.tree.AnimationTick))
+ {
+ return false;
+ }
+
+
+ return base.CanDrawNow(node, parms);
+ }
+ protected override Material GetMaterial(PawnRenderNode node, PawnDrawParms parms)
+ {
+
+ //if node is animating, and is a graphic variant type of node
+ if ((node.AnimationWorker is AnimationWorker_KeyframesExtended extendedAnimWorker)
+ && (node is PawnRenderNode_GraphicVariants nodeWithGraphicVariants)
+ && extendedAnimWorker.TexPathVariantAtTick(node.tree.AnimationTick) != null)
+ {
+ //if node has a graphic variant,
+ int variant = (int)extendedAnimWorker.TexPathVariantAtTick(node.tree.AnimationTick);
+
+ //return the variant
+ return GetMaterialVariant(nodeWithGraphicVariants, parms, variant);
+ }
+
+ //otherwise return original texture
+ return base.GetMaterial(node, parms);
+ }
+
+ public virtual Material GetMaterialVariant(PawnRenderNode_GraphicVariants node, PawnDrawParms parms, int variant)
+ {
+ Material material = node.getGraphicVariant(variant).NodeGetMat(parms);
+ if (material != null && !parms.Portrait && parms.flags.FlagSet(PawnRenderFlags.Invisible))
+ {
+ material = InvisibilityMatPool.GetInvisibleMat(material);
+ }
+
+ return material;
+
+
+ }
+
+
+ }
+}
diff --git a/1.5/Source/PawnRenderNode/PawnRenderNode_GraphicVariants.cs b/1.5/Source/PawnRenderNode/PawnRenderNode_GraphicVariants.cs
new file mode 100644
index 0000000..fa46ce7
--- /dev/null
+++ b/1.5/Source/PawnRenderNode/PawnRenderNode_GraphicVariants.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using UnityEngine;
+using Verse;
+
+namespace Rimworld_Animations
+{
+ public class PawnRenderNode_GraphicVariants : PawnRenderNode
+ {
+
+ private new PawnRenderNodeProperties_GraphicVariants props;
+ private Dictionary variants;
+
+ public Graphic getGraphicVariant(int variant)
+ {
+ return variants[variant];
+ }
+
+ public PawnRenderNode_GraphicVariants(Pawn pawn, PawnRenderNodeProperties props, PawnRenderTree tree) : base(pawn, props, tree) {
+
+ this.props = (PawnRenderNodeProperties_GraphicVariants)props;
+
+ }
+
+ protected override void EnsureMaterialsInitialized()
+ {
+
+ if (variants == null)
+ {
+ variants = GraphicVariantsFor(this.tree.pawn);
+ }
+
+ base.EnsureMaterialsInitialized();
+ }
+
+ protected virtual Dictionary GraphicVariantsFor(Pawn pawn)
+ {
+ Dictionary variantGraphics = new Dictionary();
+ Shader shader = this.ShaderFor(pawn);
+
+ //for each graphic variant
+ for (int i = 0; i < props.texPathVariants.Count; i++)
+ {
+ //get new graphic
+ Graphic variant = GraphicDatabase.Get(props.texPathVariants[i], shader, Vector2.one, this.ColorFor(pawn));
+
+ //add it to the variants dictionary; i + 1 for easier readability in logs
+ variantGraphics.Add(i + 1, variant);
+
+ }
+
+ return variantGraphics;
+ }
+
+
+ }
+}
diff --git a/1.5/Textures/AnimationProps/Cat/Cat1_north.png b/1.5/Textures/AnimationProps/Cat/Cat1_north.png
new file mode 100644
index 0000000..e9303f5
Binary files /dev/null and b/1.5/Textures/AnimationProps/Cat/Cat1_north.png differ
diff --git a/1.5/Textures/AnimationProps/Cat/Cat2_north.png b/1.5/Textures/AnimationProps/Cat/Cat2_north.png
new file mode 100644
index 0000000..caa4969
Binary files /dev/null and b/1.5/Textures/AnimationProps/Cat/Cat2_north.png differ
diff --git a/Rimworld-Animations.csproj b/Rimworld-Animations.csproj
index 405e2e6..5663d12 100644
--- a/Rimworld-Animations.csproj
+++ b/Rimworld-Animations.csproj
@@ -95,6 +95,7 @@
+
@@ -106,7 +107,9 @@
-
+
+
+
@@ -175,6 +178,7 @@
+
\ No newline at end of file