mirror of
				https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
				synced 2024-08-15 00:43:45 +00:00 
			
		
		
		
	added priority-based anim selection
This commit is contained in:
		
							parent
							
								
									319979b0f3
								
							
						
					
					
						commit
						990d27d4b1
					
				
					 10 changed files with 80 additions and 20 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,8 +16,9 @@ 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");
 | 
			
		||||
| 
						 | 
				
			
			@ -26,16 +27,41 @@ namespace Rimworld_Animations
 | 
			
		|||
 | 
			
		||||
            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>();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue