added priority-based anim selection

This commit is contained in:
c0ffee 2024-04-28 17:07:06 -07:00
parent 319979b0f3
commit 990d27d4b1
10 changed files with 80 additions and 20 deletions

View File

@ -107,6 +107,27 @@
</keyframes>
</value>
</li>
<li MayRequire="shauaputa.rimnudeworld">
<key>RimNude_Penis</key>
<value>
<workerClass>Rimworld_Animations.AnimationWorker_KeyframesExtended</workerClass>
<keyframes>
<li Class="Rimworld_Animations.ExtendedKeyframe">
<tick>0</tick>
<angle>-30</angle>
<visible>true</visible>
<rotation>East</rotation>
</li>
<li Class="Rimworld_Animations.ExtendedKeyframe">
<tick>400</tick>
<angle>-600</angle>
<visible>true</visible>
<rotation>East</rotation>
</li>
</keyframes>
</value>
</li>
</animationParts>
</AnimationDef>
</Defs>

View File

@ -38,18 +38,28 @@
<contexts>
<li Class="Rimworld_Animations.GroupAnimationContext_RJWSex">
<priority>1</priority>
<interactionDefs>
<li>Sex_Anal</li>
<li>Sex_Vaginal</li>
</interactionDefs>
</li>
<li Class="Rimworld_Animations.GroupAnimationContext_RJWSex">
<priority>1</priority>
<actorShift>1</actorShift>
<interactionDefs>
<li>Sex_Reverse_Anal</li>
<li>Sex_Reverse_Vaginal</li>
</interactionDefs>
</li>
<li Class="Rimworld_Animations.GroupAnimationContext_RJWSex">
<priority>0</priority>
<interactionDefs>
<!-- all other contexts go here -->
<!-- the ones that don't make sense but play an animation anyway -->
</interactionDefs>
</li>
</contexts>
<offsetDefs>

View File

@ -10,7 +10,16 @@ namespace Rimworld_Animations
public abstract class BaseGroupAnimationContext
{
public int actorShift = 0;
public abstract bool CanAnimationBeUsed(List<Pawn> actors, out int reorder);
public int priority = 0;
public abstract bool CanAnimationBeUsed(List<Pawn> actors);
public virtual int AnimationReorder()
{
return actorShift;
}
public virtual int AnimationPriority()
{
return priority;
}
public abstract string DebugMessage();
//cool class for designating contexts for animations

View File

@ -15,12 +15,10 @@ namespace Rimworld_Animations
public List<InteractionDef> interactionDefs;
public override bool CanAnimationBeUsed(List<Pawn> actors, out int reorder)
public override bool CanAnimationBeUsed(List<Pawn> actors)
{
JobDriver_SexBaseInitiator latestSexBaseInitiator = (actors.FindLast(x => x.jobs?.curDriver is JobDriver_SexBaseInitiator).jobs.curDriver as JobDriver_SexBaseInitiator);
reorder = base.actorShift;
return interactionDefs.Contains(latestSexBaseInitiator.Sexprops.dictionaryKey);
}

View File

@ -16,26 +16,52 @@ namespace Rimworld_Animations
public List<AnimationOffsetDef> offsetDefs;
public bool canAnimationBeUsed(List<Pawn> actors, out int reorder)
public bool canAnimationBeUsed(List<Pawn> actors)
{
if (RJWAnimationSettings.debugMode)
{
Log.Message("[anims] Checking if " + defName + " is valid animation");
}
foreach (BaseGroupAnimationContext context in contexts)
{
if (context.CanAnimationBeUsed(actors, out reorder))
if (context.CanAnimationBeUsed(actors))
{
//find all where context matches actors
return true;
}
}
reorder = 0;
return false;
}
public int Priority(List<Pawn> actors, out int reorder)
{
int priority = -999999999;
reorder = 0;
foreach (BaseGroupAnimationContext context in contexts)
{
if (context.CanAnimationBeUsed(actors))
{
if (context.AnimationPriority() > priority)
{
//get highest priority context for fitting animation
priority = context.AnimationPriority();
reorder = context.AnimationReorder();
}
}
}
return priority;
}
public List<AnimationDef> GetAllAnimationsForActor(int actor, int seed, int reorder = 0)
{
List<AnimationDef> animations = new List<AnimationDef>();

View File

@ -17,7 +17,7 @@ namespace Rimworld_Animations
public static bool Prefix(PawnRenderTree __instance, Dictionary<PawnRenderNodeTagDef, PawnRenderNode> ___nodesByTag, PawnRenderNode node, ref PawnDrawParms parms, ref Matrix4x4 matrix, ref bool __result)
{
/*
* Facing fix
* Facing offsets fix
*/
//find lowest parent that is animating, or nothing if not animating
PawnRenderNode animatingNode = node;

View File

@ -44,7 +44,6 @@ namespace Rimworld_Animations
}
}
}
//there is no graphic hediff variants appropriate
@ -63,7 +62,6 @@ namespace Rimworld_Animations
//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();
}

View File

@ -29,7 +29,6 @@ namespace Rimworld_Animations
public override void TransformRotation(PawnRenderNode node, PawnDrawParms parms, ref Quaternion rotation)
{
if (node.AnimationWorker is AnimationWorker_KeyframesExtended
&& node.tree.pawn.TryGetComp<CompExtendedAnimator>(out CompExtendedAnimator extendedAnimator)
&& extendedAnimator.IsAnimating)

View File

@ -84,15 +84,14 @@ namespace Rimworld_Animations {
int reorder2 = 0;
DefDatabase<GroupAnimationDef>.AllDefsListForReading.TryRandomElement((GroupAnimationDef x) =>
x.canAnimationBeUsed(participants, out reorder2), out GroupAnimationDef result);
//find all, then find max priority context
GroupAnimationDef result = DefDatabase<GroupAnimationDef>.AllDefsListForReading
.FindAll((GroupAnimationDef x) => x.canAnimationBeUsed(participants))
.MaxBy((GroupAnimationDef x) => x.Priority(participants, out reorder2));
reorder = reorder2;
if (result != null) return result;
return null;
return result;
}