mirror of
https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
synced 2024-08-15 00:43:45 +00:00
0de9346eac
more robust pawnrendertree animating node selection
73 lines
2.4 KiB
C#
73 lines
2.4 KiB
C#
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(PawnRenderTree), "TryGetMatrix")]
|
|
public class HarmonyPatch_PawnRenderTree
|
|
{
|
|
public static void Prefix(PawnRenderTree __instance, Dictionary<PawnRenderNodeTagDef, PawnRenderNode> ___nodesByTag, PawnRenderNode node, ref PawnDrawParms parms)
|
|
{
|
|
|
|
//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;
|
|
}
|
|
|
|
//if animating parent node found,
|
|
if (animatingNode?.AnimationWorker is AnimationWorker_KeyframesExtended animatingNodeAnimationWorker)
|
|
{
|
|
//change parm to facing to animate correctly
|
|
parms.facing = animatingNodeAnimationWorker.facingAtTick(__instance.AnimationTick);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//recaching
|
|
//done here because changing parms causes recaching anyway, so might as well do it here
|
|
[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;
|
|
return;
|
|
}
|
|
}
|
|
|
|
foreach (PawnRenderNode node in __instance.rootNode.children)
|
|
{
|
|
if (node.AnimationWorker is AnimationWorker_KeyframesExtended animWorkerExtended)
|
|
{
|
|
//recache during flicker on/off
|
|
if (animWorkerExtended.shouldRecache(animationTick))
|
|
{
|
|
node.requestRecache = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|