rimworld-animations/1.5/Source/PawnRenderNode/GraphicHediffVariants/PawnRenderNode_GraphicHediffVariants.cs

72 lines
2.5 KiB
C#
Raw Normal View History

2024-04-22 17:56:34 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
namespace Rimworld_Animations
{
public class PawnRenderNode_GraphicHediffVariants : PawnRenderNode_GraphicVariants
{
protected new PawnRenderNodeProperties_GraphicHediffVariants props;
private HediffDef curHediff;
public PawnRenderNode_GraphicHediffVariants(Pawn pawn, PawnRenderNodeProperties props, PawnRenderTree tree) : base(pawn, props, tree)
{
this.props = (PawnRenderNodeProperties_GraphicHediffVariants)props;
}
protected Dictionary<int, Graphic> GraphicHediffVariantsFor(Pawn pawn)
2024-04-22 17:56:34 +00:00
{
if (props.hediffVariants == null)
{
2024-04-25 18:58:34 +00:00
Log.Error("[Anims] Error: Tried to use GraphicHediffVariants node, but hediffVariants weren't given");
return null;
}
2024-04-22 17:56:34 +00:00
//for each different hediff-based texpathvariants,
foreach (TexPathVariants_Hediff texPathVariant_Hediff in props.hediffVariants)
{
//for all the hediffs corresponding to that texpathvariant,
foreach (HediffDef hediffDef in texPathVariant_Hediff.hediffs)
{
//if the pawn has that hediff,
if (pawn?.health?.hediffSet?.hediffs is List<Hediff> pawnHediffs && pawnHediffs.Any((Hediff hediff) => hediff.def == hediffDef))
2024-04-22 17:56:34 +00:00
{
//return that specific variant
curHediff = hediffDef;
2024-04-22 17:56:34 +00:00
return GenerateVariants(pawn, texPathVariant_Hediff.texPathVariantsDef);
}
}
}
2024-04-25 18:58:34 +00:00
//there is no graphic hediff variants appropriate
2024-04-22 17:56:34 +00:00
curHediff = null;
2024-04-25 18:58:34 +00:00
return null;
2024-04-22 17:56:34 +00:00
}
protected override void EnsureMaterialsInitialized()
{
//if pawn no longer has the hediff,
if (variants == null ||
2024-04-22 17:56:34 +00:00
(this.tree.pawn.health?.hediffSet?.hediffs is List<Hediff> hediffs
&& hediffs.Any((Hediff hediff) => hediff.def == curHediff)))
{
2024-04-25 18:58:34 +00:00
//do graphicvariantsfor
variants = GraphicHediffVariantsFor(this.tree.pawn);
2024-04-22 17:56:34 +00:00
}
2024-04-25 18:58:34 +00:00
//call this in case variants wasn't set, and there is no graphic hediff variants appropriate; it'll set variants based on default
base.EnsureMaterialsInitialized();
2024-04-22 17:56:34 +00:00
}
}
}