Compare commits

...

5 Commits

17 changed files with 256 additions and 55 deletions

View File

@ -2,7 +2,7 @@
<Defs> <Defs>
<AnimationDef> <AnimationDef>
<defName>TestAnimation2</defName> <defName>TestAnimation2</defName>
<durationTicks>120</durationTicks> <durationTicks>400</durationTicks>
<startOnRandomTick>False</startOnRandomTick> <startOnRandomTick>False</startOnRandomTick>
<playWhenDowned>False</playWhenDowned> <playWhenDowned>False</playWhenDowned>
@ -13,32 +13,35 @@
<workerClass>Rimworld_Animations.AnimationWorker_KeyframesExtended</workerClass> <workerClass>Rimworld_Animations.AnimationWorker_KeyframesExtended</workerClass>
<keyframes> <keyframes>
<li Class="Rimworld_Animations.ExtendedKeyframe"> <li Class="Rimworld_Animations.ExtendedKeyframe">
<offset>(1, 0, 0)</offset>
<tick>0</tick> <tick>0</tick>
<angle>0</angle> <angle>0</angle>
<rotation>North</rotation> <rotation>South</rotation>
</li> </li>
<li Class="Rimworld_Animations.ExtendedKeyframe"> <li Class="Rimworld_Animations.ExtendedKeyframe">
<offset>(0, 0, 0)</offset> <tick>100</tick>
<tick>30</tick> <angle>45</angle>
<angle>15</angle> <rotation>South</rotation>
<rotation>North</rotation>
</li> </li>
<li Class="Rimworld_Animations.ExtendedKeyframe"> <li Class="Rimworld_Animations.ExtendedKeyframe">
<offset>(-1, 0, 0)</offset> <tick>0</tick>
<tick>60</tick> <offset>(-0.73, 0, -0.02)</offset>
<angle>0</angle> <angle>0</angle>
<rotation>North</rotation> <rotation>East</rotation>
</li> </li>
<li Class="Rimworld_Animations.ExtendedKeyframe"> <li Class="Rimworld_Animations.ExtendedKeyframe">
<offset>(0, 0, 0)</offset> <tick>200</tick>
<tick>90</tick> <angle>90</angle>
<angle>-15</angle> <rotation>South</rotation>
<rotation>North</rotation> </li>
<li Class="Rimworld_Animations.ExtendedKeyframe">
<tick>300</tick>
<angle>135</angle>
<rotation>South</rotation>
</li> </li>
</keyframes> </keyframes>
</value> </value>
</li> </li>
<!--
<li> <li>
<key>Head</key> <key>Head</key>
<value> <value>
@ -67,6 +70,7 @@
</keyframes> </keyframes>
</value> </value>
</li> </li>
-->
</animationParts> </animationParts>
</AnimationDef> </AnimationDef>
</Defs> </Defs>

View File

@ -10,16 +10,16 @@
<li> <li>
<probability>3</probability> <probability>3</probability>
<animationDefs> <animationDefs>
<li>TestAnimation3</li> <li>TestAnimation2</li>
<li>TestAnimation3</li> <li>TestAnimation2</li>
</animationDefs> </animationDefs>
</li> </li>
<li> <li>
<probability>1</probability> <probability>1</probability>
<animationDefs> <animationDefs>
<li>TestAnimation3</li> <li>TestAnimation2</li>
<li>TestAnimation3</li> <li>TestAnimation2</li>
</animationDefs> </animationDefs>
</li> </li>
</loopOptions> </loopOptions>

View File

@ -197,6 +197,12 @@ namespace Rimworld_Animations {
PawnRenderNodeProperties props = animationProp.animPropProperties; PawnRenderNodeProperties props = animationProp.animPropProperties;
if (props.texPath.NullOrEmpty())
{
props.texPath = "AnimationProps/MissingTexture/MissingTexture";
}
//create new render node //create new render node
PawnRenderNode animRenderNode = (PawnRenderNode)Activator.CreateInstance(props.nodeClass, new object[] { PawnRenderNode animRenderNode = (PawnRenderNode)Activator.CreateInstance(props.nodeClass, new object[] {
this.pawn, this.pawn,

View File

@ -41,7 +41,9 @@ namespace Rimworld_Animations
} }
} }
/*
* no longer needed; taken care of by graphic variants
*
// For changing texture path of thing to variant // For changing texture path of thing to variant
[HarmonyPatch(typeof(PawnRenderNode), "TexPathFor")] [HarmonyPatch(typeof(PawnRenderNode), "TexPathFor")]
public static class HarmonyPatch_PawnRenderNode2 public static class HarmonyPatch_PawnRenderNode2
@ -54,4 +56,6 @@ namespace Rimworld_Animations
} }
} }
} }
*/
} }

View File

@ -11,6 +11,7 @@ namespace Rimworld_Animations
public class PawnRenderNode_BodyTypeVariants : PawnRenderNode_GraphicVariants public class PawnRenderNode_BodyTypeVariants : PawnRenderNode_GraphicVariants
{ {
private BodyTypeDef bodyType;
protected new PawnRenderNodeProperties_BodyTypeVariants props; protected new PawnRenderNodeProperties_BodyTypeVariants props;
public PawnRenderNode_BodyTypeVariants(Pawn pawn, PawnRenderNodeProperties props, PawnRenderTree tree) : base(pawn, props, tree) public PawnRenderNode_BodyTypeVariants(Pawn pawn, PawnRenderNodeProperties props, PawnRenderTree tree) : base(pawn, props, tree)
@ -20,35 +21,39 @@ namespace Rimworld_Animations
} }
protected override Dictionary<int, Graphic> GraphicVariantsFor(Pawn pawn) protected Dictionary<int, Graphic> GraphicBodyTypeVariantsFor(Pawn pawn)
{ {
if (props.bodyTypeVariantsDef == null) 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; return null;
} }
//for each different hediff-based texpathvariants, //for each different hediff-based texpathvariants,
foreach (TexPathVariants_BodyType texPathVariant_BodyType in props.bodyTypeVariantsDef) 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 //return that specific variant
bodyType = texPathVariant_BodyType.bodyType;
return GenerateVariants(pawn, texPathVariant_BodyType.texPathVariantsDef); return GenerateVariants(pawn, texPathVariant_BodyType.texPathVariantsDef);
} }
} }
//otherwise just use default return null;
return base.GraphicVariantsFor(pawn);
} }
protected override void EnsureMaterialsInitialized() 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(); base.EnsureMaterialsInitialized();
} }

View File

@ -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<HediffWithSeverity> hediffSeverityVariants;
}
public class HediffWithSeverity
{
public HediffDef hediff;
public List<TexPathVariants_Severity> severityVariants;
}
public class TexPathVariants_Severity
{
public int severity;
public TexPathVariantsDef texPathVariantsDef;
}
}

View File

@ -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
}
}

View File

@ -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<int, Graphic> 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<Hediff> 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();
}
}
}

View File

@ -20,12 +20,12 @@ namespace Rimworld_Animations
} }
protected override Dictionary<int, Graphic> GraphicVariantsFor(Pawn pawn) protected Dictionary<int, Graphic> GraphicHediffVariantsFor(Pawn pawn)
{ {
if (props.hediffVariants == null) 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; return null;
} }
@ -36,10 +36,10 @@ namespace Rimworld_Animations
foreach (HediffDef hediffDef in texPathVariant_Hediff.hediffs) foreach (HediffDef hediffDef in texPathVariant_Hediff.hediffs)
{ {
//if the pawn has that hediff, //if the pawn has that hediff,
if (pawn.health.hediffSet.hediffs.Any((Hediff hediff) => hediff.def == hediffDef)) if (pawn?.health?.hediffSet?.hediffs is List<Hediff> pawnHediffs && pawnHediffs.Any((Hediff hediff) => hediff.def == hediffDef))
{ {
//return that specific variant //return that specific variant
curHediff = hediff.def; curHediff = hediffDef;
return GenerateVariants(pawn, texPathVariant_Hediff.texPathVariantsDef); 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; curHediff = null;
return base.GraphicVariantsFor(pawn); return null;
} }
protected override void EnsureMaterialsInitialized() protected override void EnsureMaterialsInitialized()
{ {
//if pawn no longer has the hediff, //if pawn no longer has the hediff,
if (curHediff == null || if (variants == null ||
(this.tree.pawn.health?.hediffSet?.hediffs is List<Hediff> hediffs !(this.tree.pawn.health?.hediffSet?.hediffs is List<Hediff> hediffs
&& hediffs.Any((Hediff hediff) => hediff.def == curHediff))) && hediffs.Any((Hediff hediff) => hediff.def == curHediff)))
{ {
//redo graphicvariantsfor //do graphicvariantsfor
variants = GraphicVariantsFor(this.tree.pawn); 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(); base.EnsureMaterialsInitialized();
} }
} }
} }

View File

@ -31,12 +31,10 @@ namespace Rimworld_Animations
{ {
//if node is animating, and is a graphic variant type of node //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) if ((node.AnimationWorker is AnimationWorker_KeyframesExtended extendedAnimWorker)
//and node is one with graphic variants
&& (node is PawnRenderNode_GraphicVariants nodeWithGraphicVariants) && (node is PawnRenderNode_GraphicVariants nodeWithGraphicVariants)
//and texpathvariant is set
&& extendedAnimWorker.TexPathVariantAtTick(node.tree.AnimationTick) != null) && extendedAnimWorker.TexPathVariantAtTick(node.tree.AnimationTick) != null)
{ {
Material materialVariant = GetMaterialVariant(nodeWithGraphicVariants, parms, (int)extendedAnimWorker.TexPathVariantAtTick(node.tree.AnimationTick)); Material materialVariant = GetMaterialVariant(nodeWithGraphicVariants, parms, (int)extendedAnimWorker.TexPathVariantAtTick(node.tree.AnimationTick));

View File

@ -12,13 +12,14 @@ namespace Rimworld_Animations
{ {
protected new PawnRenderNodeProperties_GraphicVariants props; protected new PawnRenderNodeProperties_GraphicVariants props;
protected Graphic missingTextureGraphic;
protected Dictionary<int, Graphic> variants; protected Dictionary<int, Graphic> variants;
public Graphic getGraphicVariant(int variant) public Graphic getGraphicVariant(int variant)
{ {
if (variants == null || !variants.ContainsKey(variant)) if (variants == null || !variants.ContainsKey(variant))
{ {
return null; return missingTextureGraphic;
} }
return variants[variant]; 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<int, Graphic> GraphicVariantsFor(Pawn pawn) protected virtual Dictionary<int, Graphic> 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 //used by all, including base classes, to create texPathVariants for pawn
protected Dictionary<int, Graphic> GenerateVariants(Pawn pawn, TexPathVariantsDef texPathVariants) protected Dictionary<int, Graphic> GenerateVariants(Pawn pawn, TexPathVariantsDef texPathVariants)
{ {
@ -75,6 +82,9 @@ namespace Rimworld_Animations
} }
protected Graphic GenerateMissingTextureGraphic()
{
return GraphicDatabase.Get<Graphic_Multi>("AnimationProps/MissingTexture");
}
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 KiB

View File

@ -121,6 +121,9 @@
<Compile Include="1.5\Source\PawnRenderNode\GraphicBodyTypeVariants\PawnRenderNodeProperties_GraphicBodyTypeVariants.cs" /> <Compile Include="1.5\Source\PawnRenderNode\GraphicBodyTypeVariants\PawnRenderNodeProperties_GraphicBodyTypeVariants.cs" />
<Compile Include="1.5\Source\PawnRenderNode\GraphicBodyTypeVariants\PawnRenderNodeWorker_GraphicBodyTypeVariants.cs" /> <Compile Include="1.5\Source\PawnRenderNode\GraphicBodyTypeVariants\PawnRenderNodeWorker_GraphicBodyTypeVariants.cs" />
<Compile Include="1.5\Source\PawnRenderNode\GraphicBodyTypeVariants\PawnRenderNode_GraphicBodyTypeVariants.cs" /> <Compile Include="1.5\Source\PawnRenderNode\GraphicBodyTypeVariants\PawnRenderNode_GraphicBodyTypeVariants.cs" />
<Compile Include="1.5\Source\PawnRenderNode\GraphicHediffSeverityVariants\PawnRenderNodeProperties_GraphicHediffSeverityVariants.cs" />
<Compile Include="1.5\Source\PawnRenderNode\GraphicHediffSeverityVariants\PawnRenderNodeWorker_GraphicHediffSeverityVariants.cs" />
<Compile Include="1.5\Source\PawnRenderNode\GraphicHediffSeverityVariants\PawnRenderNode_GraphicHediffSeverityVariants.cs" />
<Compile Include="1.5\Source\PawnRenderNode\GraphicHediffVariants\PawnRenderNodeProperties_GraphicHediffVariants.cs" /> <Compile Include="1.5\Source\PawnRenderNode\GraphicHediffVariants\PawnRenderNodeProperties_GraphicHediffVariants.cs" />
<Compile Include="1.5\Source\PawnRenderNode\GraphicHediffVariants\PawnRenderNodeWorker_GraphicHediffVariants.cs" /> <Compile Include="1.5\Source\PawnRenderNode\GraphicHediffVariants\PawnRenderNodeWorker_GraphicHediffVariants.cs" />
<Compile Include="1.5\Source\PawnRenderNode\GraphicHediffVariants\PawnRenderNode_GraphicHediffVariants.cs" /> <Compile Include="1.5\Source\PawnRenderNode\GraphicHediffVariants\PawnRenderNode_GraphicHediffVariants.cs" />
@ -197,6 +200,10 @@
<Content Include="1.5\Textures\AnimationProps\Banana\Banana_west.png" /> <Content Include="1.5\Textures\AnimationProps\Banana\Banana_west.png" />
<Content Include="1.5\Textures\AnimationProps\Doggystyle\Doggy_Arms_north.png" /> <Content Include="1.5\Textures\AnimationProps\Doggystyle\Doggy_Arms_north.png" />
<Content Include="1.5\Textures\AnimationProps\Doggystyle\Doggy_Legs_north.png" /> <Content Include="1.5\Textures\AnimationProps\Doggystyle\Doggy_Legs_north.png" />
<Content Include="1.5\Textures\AnimationProps\MissingTexture\MissingTexture_east.png" />
<Content Include="1.5\Textures\AnimationProps\MissingTexture\MissingTexture_north.png" />
<Content Include="1.5\Textures\AnimationProps\MissingTexture\MissingTexture_south.png" />
<Content Include="1.5\Textures\AnimationProps\MissingTexture\MissingTexture_west.png" />
<Content Include="1.5\Textures\UI\MainTab.png" /> <Content Include="1.5\Textures\UI\MainTab.png" />
<Content Include="About\About.xml" /> <Content Include="About\About.xml" />
<Content Include="About\Manifest.xml" /> <Content Include="About\Manifest.xml" />