2024-04-17 23:57:18 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-04-20 04:38:04 +00:00
|
|
|
|
|
2024-04-17 23:57:18 +00:00
|
|
|
|
[HarmonyPatch(typeof(PawnRenderTree), "TryGetMatrix")]
|
|
|
|
|
public class HarmonyPatch_PawnRenderTree
|
|
|
|
|
{
|
2024-04-20 04:38:04 +00:00
|
|
|
|
public static void Prefix(PawnRenderTree __instance, Dictionary<PawnRenderNodeTagDef, PawnRenderNode> ___nodesByTag, PawnRenderNode node, ref PawnDrawParms parms)
|
2024-04-17 23:57:18 +00:00
|
|
|
|
{
|
|
|
|
|
|
2024-04-20 04:38:04 +00:00
|
|
|
|
//find lowest parent that is animating, or nothing if not animating
|
|
|
|
|
PawnRenderNode animatingNode = node;
|
|
|
|
|
while (animatingNode != null
|
|
|
|
|
&& !(animatingNode.AnimationWorker is AnimationWorker_KeyframesExtended))
|
|
|
|
|
{
|
|
|
|
|
animatingNode = animatingNode.parent;
|
|
|
|
|
}
|
2024-04-17 23:57:18 +00:00
|
|
|
|
|
2024-04-20 04:38:04 +00:00
|
|
|
|
//if animating parent node found,
|
|
|
|
|
if (animatingNode?.AnimationWorker is AnimationWorker_KeyframesExtended animatingNodeAnimationWorker)
|
2024-04-17 23:57:18 +00:00
|
|
|
|
{
|
2024-04-20 04:38:04 +00:00
|
|
|
|
//change parm to facing to animate correctly
|
|
|
|
|
parms.facing = animatingNodeAnimationWorker.facingAtTick(__instance.AnimationTick);
|
2024-04-17 23:57:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-20 04:38:04 +00:00
|
|
|
|
|
2024-04-17 23:57:18 +00:00
|
|
|
|
}
|
2024-04-19 00:40:06 +00:00
|
|
|
|
|
|
|
|
|
|
2024-04-20 04:38:04 +00:00
|
|
|
|
|
|
|
|
|
//recaching
|
|
|
|
|
//done here because changing parms causes recaching anyway, so might as well do it here
|
2024-04-19 00:40:06 +00:00
|
|
|
|
[HarmonyPatch(typeof(PawnRenderTree), "AdjustParms")]
|
|
|
|
|
public class HarmonyPatch_PawnRenderTree2
|
|
|
|
|
{
|
|
|
|
|
public static void Prefix(PawnRenderTree __instance, ref PawnDrawParms parms)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int animationTick = __instance.AnimationTick;
|
|
|
|
|
|
|
|
|
|
if (__instance.rootNode.AnimationWorker is AnimationWorker_KeyframesExtended rootAnimWorkerExtended)
|
|
|
|
|
{
|
|
|
|
|
//recache during facing turn
|
|
|
|
|
if (rootAnimWorkerExtended.shouldRecache(animationTick))
|
|
|
|
|
{
|
|
|
|
|
__instance.rootNode.requestRecache = true;
|
2024-04-19 00:43:49 +00:00
|
|
|
|
return;
|
2024-04-19 00:40:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (PawnRenderNode node in __instance.rootNode.children)
|
|
|
|
|
{
|
|
|
|
|
if (node.AnimationWorker is AnimationWorker_KeyframesExtended animWorkerExtended)
|
|
|
|
|
{
|
2024-04-20 04:38:04 +00:00
|
|
|
|
//recache during flicker on/off
|
2024-04-19 00:40:06 +00:00
|
|
|
|
if (animWorkerExtended.shouldRecache(animationTick))
|
|
|
|
|
{
|
|
|
|
|
node.requestRecache = true;
|
2024-04-19 00:43:49 +00:00
|
|
|
|
return;
|
2024-04-19 00:40:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-17 23:57:18 +00:00
|
|
|
|
}
|