diff --git a/1.5/Assemblies/Rimworld-Animations.dll b/1.5/Assemblies/Rimworld-Animations.dll index 3c23703..494f83d 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/TestAnimation2.xml b/1.5/Defs/AnimationDefs/TestAnimation2.xml index 8125f0c..abda22f 100644 --- a/1.5/Defs/AnimationDefs/TestAnimation2.xml +++ b/1.5/Defs/AnimationDefs/TestAnimation2.xml @@ -2,7 +2,7 @@ TestAnimation2 - 120 + 400 False False @@ -13,32 +13,35 @@ Rimworld_Animations.AnimationWorker_KeyframesExtended
  • - (1, 0, 0) 0 0 - North + South
  • - (0, 0, 0) - 30 - 15 - North + 100 + 45 + South
  • - (-1, 0, 0) - 60 + 0 + (-0.73, 0, -0.02) 0 - North + East
  • - (0, 0, 0) - 90 - -15 - North + 200 + 90 + South +
  • +
  • + 300 + 135 + South
  • +
    diff --git a/1.5/Defs/GroupAnimationDefs/TestGroupAnimation1.xml b/1.5/Defs/GroupAnimationDefs/TestGroupAnimation1.xml index ea2061e..05c541b 100644 --- a/1.5/Defs/GroupAnimationDefs/TestGroupAnimation1.xml +++ b/1.5/Defs/GroupAnimationDefs/TestGroupAnimation1.xml @@ -10,16 +10,16 @@
  • 3 -
  • TestAnimation3
  • -
  • TestAnimation3
  • +
  • TestAnimation2
  • +
  • TestAnimation2
  • 1 -
  • TestAnimation3
  • -
  • TestAnimation3
  • +
  • TestAnimation2
  • +
  • TestAnimation2
  • diff --git a/1.5/Source/Comps/CompExtendedAnimator.cs b/1.5/Source/Comps/CompExtendedAnimator.cs index 46951c6..2a6dfd2 100644 --- a/1.5/Source/Comps/CompExtendedAnimator.cs +++ b/1.5/Source/Comps/CompExtendedAnimator.cs @@ -197,6 +197,12 @@ namespace Rimworld_Animations { PawnRenderNodeProperties props = animationProp.animPropProperties; + if (props.texPath.NullOrEmpty()) + { + props.texPath = "AnimationProps/MissingTexture/MissingTexture"; + } + + //create new render node PawnRenderNode animRenderNode = (PawnRenderNode)Activator.CreateInstance(props.nodeClass, new object[] { this.pawn, diff --git a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs index a0741cd..7e30364 100644 --- a/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs +++ b/1.5/Source/Patches/RimworldPatches/HarmonyPatch_PawnRenderNode.cs @@ -41,7 +41,9 @@ namespace Rimworld_Animations } } - + /* + * no longer needed; taken care of by graphic variants + * // For changing texture path of thing to variant [HarmonyPatch(typeof(PawnRenderNode), "TexPathFor")] public static class HarmonyPatch_PawnRenderNode2 @@ -54,4 +56,6 @@ namespace Rimworld_Animations } } } + + */ } diff --git a/1.5/Source/PawnRenderNode/GraphicBodyTypeVariants/PawnRenderNode_GraphicBodyTypeVariants.cs b/1.5/Source/PawnRenderNode/GraphicBodyTypeVariants/PawnRenderNode_GraphicBodyTypeVariants.cs index 6164782..ed26039 100644 --- a/1.5/Source/PawnRenderNode/GraphicBodyTypeVariants/PawnRenderNode_GraphicBodyTypeVariants.cs +++ b/1.5/Source/PawnRenderNode/GraphicBodyTypeVariants/PawnRenderNode_GraphicBodyTypeVariants.cs @@ -11,6 +11,7 @@ namespace Rimworld_Animations public class PawnRenderNode_BodyTypeVariants : PawnRenderNode_GraphicVariants { + private BodyTypeDef bodyType; protected new PawnRenderNodeProperties_BodyTypeVariants props; public PawnRenderNode_BodyTypeVariants(Pawn pawn, PawnRenderNodeProperties props, PawnRenderTree tree) : base(pawn, props, tree) @@ -20,35 +21,39 @@ namespace Rimworld_Animations } - protected override Dictionary GraphicVariantsFor(Pawn pawn) + protected Dictionary GraphicBodyTypeVariantsFor(Pawn pawn) { if (props.bodyTypeVariantsDef == null) { - Log.ErrorOnce("[Anims] Error: Tried to use BodyTypeVariants node, but bodyTypeVariants weren't given", 211341349); + Log.Error("[Anims] Error: Tried to use BodyTypeVariants node, but bodyTypeVariants weren't given"); return null; } //for each different hediff-based texpathvariants, foreach (TexPathVariants_BodyType texPathVariant_BodyType in props.bodyTypeVariantsDef) { - if (pawn.story.bodyType == texPathVariant_BodyType.bodyType) + if (pawn.story?.bodyType == texPathVariant_BodyType.bodyType) { //return that specific variant + bodyType = texPathVariant_BodyType.bodyType; return GenerateVariants(pawn, texPathVariant_BodyType.texPathVariantsDef); } } - //otherwise just use default - return base.GraphicVariantsFor(pawn); + return null; } protected override void EnsureMaterialsInitialized() { - variants = GraphicVariantsFor(this.tree.pawn); + if (variants == null + || this.tree.pawn.story?.bodyType != bodyType) + variants = GraphicBodyTypeVariantsFor(this.tree.pawn); + + //call this in case variants wasn't set, and there is no graphic bodytype variants appropriate; it'll set variants based on default base.EnsureMaterialsInitialized(); } diff --git a/1.5/Source/PawnRenderNode/GraphicHediffSeverityVariants/PawnRenderNodeProperties_GraphicHediffSeverityVariants.cs b/1.5/Source/PawnRenderNode/GraphicHediffSeverityVariants/PawnRenderNodeProperties_GraphicHediffSeverityVariants.cs new file mode 100644 index 0000000..96e9779 --- /dev/null +++ b/1.5/Source/PawnRenderNode/GraphicHediffSeverityVariants/PawnRenderNodeProperties_GraphicHediffSeverityVariants.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Verse; + +namespace Rimworld_Animations +{ + public class PawnRenderNodeProperties_GraphicHediffSeverityVariants : PawnRenderNodeProperties_GraphicVariants + { + + public BodyPartDef bodyPart = null; + public List hediffSeverityVariants; + + } + + public class HediffWithSeverity + { + public HediffDef hediff; + public List severityVariants; + } + + public class TexPathVariants_Severity + { + public int severity; + public TexPathVariantsDef texPathVariantsDef; + + + } + + +} diff --git a/1.5/Source/PawnRenderNode/GraphicHediffSeverityVariants/PawnRenderNodeWorker_GraphicHediffSeverityVariants.cs b/1.5/Source/PawnRenderNode/GraphicHediffSeverityVariants/PawnRenderNodeWorker_GraphicHediffSeverityVariants.cs new file mode 100644 index 0000000..b8877a5 --- /dev/null +++ b/1.5/Source/PawnRenderNode/GraphicHediffSeverityVariants/PawnRenderNodeWorker_GraphicHediffSeverityVariants.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Rimworld_Animations +{ + public class PawnRenderNodeWorker_GraphicHediffSeverityVariants : PawnRenderNodeWorker_GraphicVariants + { + //same functionality as graphicvariants worker + //just here for readability + + } +} diff --git a/1.5/Source/PawnRenderNode/GraphicHediffSeverityVariants/PawnRenderNode_GraphicHediffSeverityVariants.cs b/1.5/Source/PawnRenderNode/GraphicHediffSeverityVariants/PawnRenderNode_GraphicHediffSeverityVariants.cs new file mode 100644 index 0000000..44ce6fd --- /dev/null +++ b/1.5/Source/PawnRenderNode/GraphicHediffSeverityVariants/PawnRenderNode_GraphicHediffSeverityVariants.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Verse; + +namespace Rimworld_Animations +{ + public class PawnRenderNode_GraphicHediffSeverityVariants : PawnRenderNode_GraphicVariants + { + + protected HediffDef hediffWithSeverity; + protected float curSeverity; + + protected new PawnRenderNodeProperties_GraphicHediffSeverityVariants props; + private HediffDef curHediff; + + public PawnRenderNode_GraphicHediffSeverityVariants(Pawn pawn, PawnRenderNodeProperties props, PawnRenderTree tree) : base(pawn, props, tree) + { + + this.props = (PawnRenderNodeProperties_GraphicHediffSeverityVariants)props; + + } + + protected Dictionary GraphicHediffSeverityVariantsFor(Pawn pawn) + { + + + if (props.hediffSeverityVariants == null) + { + Log.Error("[Anims] Error: Tried to use GraphicBodyPartHediffSeverityVariants node, but hediffSeverityVariants weren't given"); + } + + + Hediff idealHediff = null; + HediffWithSeverity idealHediffSeverity = null; + + if (props.bodyPart == null) + { + //search the entire body for the hediff because no bodypart was set + for (int i = 0; i < props.hediffSeverityVariants.Count; i++) + { + idealHediff = pawn.health.hediffSet.hediffs.Find((Hediff hediffWithSeverity) => + hediffWithSeverity.def == props.hediffSeverityVariants[i].hediff); + + if (idealHediff != null) + { + //get the ideal hediff severity variants, to iterate through and find the right one for the severity + idealHediffSeverity = props.hediffSeverityVariants[i]; + break; + + } + + } + } + + else + { + //search for a hediff with a specific body part + + for (int i = 0; i < props.hediffSeverityVariants.Count; i++) + { + //right hediff with the right hediff and right body part + + idealHediff = pawn.health.hediffSet.hediffs.Find((Hediff hediffWithSeverity) => + hediffWithSeverity.def == props.hediffSeverityVariants[i].hediff + && hediffWithSeverity.Part.def == props.bodyPart); + + if (idealHediff != null) { + + //get the ideal hediff severity variants, to iterate through and find the right one for the severity + idealHediffSeverity = props.hediffSeverityVariants[i]; + break; + } + } + } + + if (idealHediff != null) + { + //set severity so that recache when this is different + curSeverity = idealHediff.Severity; + + //look for the right severity-based texpathvariants + TexPathVariants_Severity texPathVariants_Severity = idealHediffSeverity.severityVariants.Find((TexPathVariants_Severity texPathVariants) => + texPathVariants.severity < idealHediff.Severity); + + //if null, assume value is really too small + if (texPathVariants_Severity == null) + { + //return largest value + return GenerateVariants(pawn, idealHediffSeverity.severityVariants.First().texPathVariantsDef); + } + + //return right severity variants + return GenerateVariants(pawn, texPathVariants_Severity.texPathVariantsDef); + + } + + //there is no graphic hediff variants appropriate + curHediff = null; + return null; + + } + + protected override void EnsureMaterialsInitialized() + { + //if pawn no longer has the hediff, + if (variants == null || + !(this.tree.pawn.health?.hediffSet?.hediffs is List hediffs + && hediffs.Any((Hediff hediff) => hediff.def == curHediff && hediff.Severity == curSeverity))) + { + //do graphicvariantsfor + variants = GraphicHediffSeverityVariantsFor(this.tree.pawn); + } + + //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(); + } + } +} diff --git a/1.5/Source/PawnRenderNode/GraphicHediffVariants/PawnRenderNode_GraphicHediffVariants.cs b/1.5/Source/PawnRenderNode/GraphicHediffVariants/PawnRenderNode_GraphicHediffVariants.cs index e73b1cc..5382373 100644 --- a/1.5/Source/PawnRenderNode/GraphicHediffVariants/PawnRenderNode_GraphicHediffVariants.cs +++ b/1.5/Source/PawnRenderNode/GraphicHediffVariants/PawnRenderNode_GraphicHediffVariants.cs @@ -20,12 +20,12 @@ namespace Rimworld_Animations } - protected override Dictionary GraphicVariantsFor(Pawn pawn) + protected Dictionary GraphicHediffVariantsFor(Pawn pawn) { if (props.hediffVariants == null) { - Log.ErrorOnce("[Anims] Error: Tried to use GraphicHediffVariants node, but hediffVariants weren't given", 231321349); + Log.Error("[Anims] Error: Tried to use GraphicHediffVariants node, but hediffVariants weren't given"); return null; } @@ -36,10 +36,10 @@ namespace Rimworld_Animations foreach (HediffDef hediffDef in texPathVariant_Hediff.hediffs) { //if the pawn has that hediff, - if (pawn.health.hediffSet.hediffs.Any((Hediff hediff) => hediff.def == hediffDef)) + if (pawn?.health?.hediffSet?.hediffs is List pawnHediffs && pawnHediffs.Any((Hediff hediff) => hediff.def == hediffDef)) { //return that specific variant - curHediff = hediff.def; + curHediff = hediffDef; return GenerateVariants(pawn, texPathVariant_Hediff.texPathVariantsDef); } @@ -47,27 +47,25 @@ namespace Rimworld_Animations } - //otherwise just use default + //there is no graphic hediff variants appropriate curHediff = null; - return base.GraphicVariantsFor(pawn); + return null; } protected override void EnsureMaterialsInitialized() { //if pawn no longer has the hediff, - if (curHediff == null || - (this.tree.pawn.health?.hediffSet?.hediffs is List hediffs + if (variants == null || + !(this.tree.pawn.health?.hediffSet?.hediffs is List hediffs && hediffs.Any((Hediff hediff) => hediff.def == curHediff))) { - //redo graphicvariantsfor - variants = GraphicVariantsFor(this.tree.pawn); + //do graphicvariantsfor + variants = GraphicHediffVariantsFor(this.tree.pawn); } + //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(); } - - } - } diff --git a/1.5/Source/PawnRenderNode/GraphicVariants/PawnRenderNodeWorker_GraphicVariants.cs b/1.5/Source/PawnRenderNode/GraphicVariants/PawnRenderNodeWorker_GraphicVariants.cs index 9c3cf91..184caff 100644 --- a/1.5/Source/PawnRenderNode/GraphicVariants/PawnRenderNodeWorker_GraphicVariants.cs +++ b/1.5/Source/PawnRenderNode/GraphicVariants/PawnRenderNodeWorker_GraphicVariants.cs @@ -31,12 +31,10 @@ namespace Rimworld_Animations { //if node is animating, and is a graphic variant type of node + //and node is one with graphic variants + //and texpathvariant is set if ((node.AnimationWorker is AnimationWorker_KeyframesExtended extendedAnimWorker) - - //and node is one with graphic variants && (node is PawnRenderNode_GraphicVariants nodeWithGraphicVariants) - - //and texpathvariant is set && extendedAnimWorker.TexPathVariantAtTick(node.tree.AnimationTick) != null) { Material materialVariant = GetMaterialVariant(nodeWithGraphicVariants, parms, (int)extendedAnimWorker.TexPathVariantAtTick(node.tree.AnimationTick)); diff --git a/1.5/Source/PawnRenderNode/GraphicVariants/PawnRenderNode_GraphicVariants.cs b/1.5/Source/PawnRenderNode/GraphicVariants/PawnRenderNode_GraphicVariants.cs index da09317..0298c51 100644 --- a/1.5/Source/PawnRenderNode/GraphicVariants/PawnRenderNode_GraphicVariants.cs +++ b/1.5/Source/PawnRenderNode/GraphicVariants/PawnRenderNode_GraphicVariants.cs @@ -12,13 +12,14 @@ namespace Rimworld_Animations { protected new PawnRenderNodeProperties_GraphicVariants props; + protected Graphic missingTextureGraphic; protected Dictionary variants; public Graphic getGraphicVariant(int variant) { if (variants == null || !variants.ContainsKey(variant)) { - return null; + return missingTextureGraphic; } return variants[variant]; @@ -30,17 +31,6 @@ namespace Rimworld_Animations } - protected override void EnsureMaterialsInitialized() - { - - if (variants == null) - { - variants = GraphicVariantsFor(this.tree.pawn); - } - - base.EnsureMaterialsInitialized(); - } - protected virtual Dictionary GraphicVariantsFor(Pawn pawn) { @@ -53,6 +43,23 @@ namespace Rimworld_Animations } + protected override void EnsureMaterialsInitialized() + { + + if (variants == null) + { + variants = GraphicVariantsFor(this.tree.pawn); + } + if (missingTextureGraphic == null) + { + missingTextureGraphic = GenerateMissingTextureGraphic(); + } + + + base.EnsureMaterialsInitialized(); + } + + //used by all, including base classes, to create texPathVariants for pawn protected Dictionary GenerateVariants(Pawn pawn, TexPathVariantsDef texPathVariants) { @@ -75,6 +82,9 @@ namespace Rimworld_Animations } - + protected Graphic GenerateMissingTextureGraphic() + { + return GraphicDatabase.Get("AnimationProps/MissingTexture"); + } } } diff --git a/1.5/Textures/AnimationProps/MissingTexture/MissingTexture_east.png b/1.5/Textures/AnimationProps/MissingTexture/MissingTexture_east.png new file mode 100644 index 0000000..59958a9 Binary files /dev/null and b/1.5/Textures/AnimationProps/MissingTexture/MissingTexture_east.png differ diff --git a/1.5/Textures/AnimationProps/MissingTexture/MissingTexture_north.png b/1.5/Textures/AnimationProps/MissingTexture/MissingTexture_north.png new file mode 100644 index 0000000..59958a9 Binary files /dev/null and b/1.5/Textures/AnimationProps/MissingTexture/MissingTexture_north.png differ diff --git a/1.5/Textures/AnimationProps/MissingTexture/MissingTexture_south.png b/1.5/Textures/AnimationProps/MissingTexture/MissingTexture_south.png new file mode 100644 index 0000000..59958a9 Binary files /dev/null and b/1.5/Textures/AnimationProps/MissingTexture/MissingTexture_south.png differ diff --git a/1.5/Textures/AnimationProps/MissingTexture/MissingTexture_west.png b/1.5/Textures/AnimationProps/MissingTexture/MissingTexture_west.png new file mode 100644 index 0000000..59958a9 Binary files /dev/null and b/1.5/Textures/AnimationProps/MissingTexture/MissingTexture_west.png differ diff --git a/Rimworld-Animations.csproj b/Rimworld-Animations.csproj index 70e188e..1fad458 100644 --- a/Rimworld-Animations.csproj +++ b/Rimworld-Animations.csproj @@ -121,6 +121,9 @@ + + + @@ -197,6 +200,10 @@ + + + +