mirror of
				https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
				synced 2024-08-15 00:43:45 +00:00 
			
		
		
		
	Bugfixing involving animation reordering
This commit is contained in:
		
							parent
							
								
									a458f3b83f
								
							
						
					
					
						commit
						3ab5a96ce5
					
				
					 4 changed files with 55 additions and 7 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -0,0 +1,27 @@
 | 
				
			||||||
 | 
					<?xml version="1.0" encoding="utf-8" ?>
 | 
				
			||||||
 | 
					<Patch>
 | 
				
			||||||
 | 
						<!--
 | 
				
			||||||
 | 
						<Operation Class="PatchOperationSequence">
 | 
				
			||||||
 | 
							<success>Always</success>
 | 
				
			||||||
 | 
							<operations>
 | 
				
			||||||
 | 
								<li Class="PatchOperationAdd">
 | 
				
			||||||
 | 
									<success>Always</success>
 | 
				
			||||||
 | 
									<xpath>Defs/OffsetDef[defName="OffsetDefNameHere"]/Offsets</xpath>
 | 
				
			||||||
 | 
									<value>
 | 
				
			||||||
 | 
										<li Class="Rimworld_Animations.AnimationOffset_BodyType">
 | 
				
			||||||
 | 
											<races>
 | 
				
			||||||
 | 
												<li>YourAlienRace</li>
 | 
				
			||||||
 | 
											</races>
 | 
				
			||||||
 | 
											<offsets>
 | 
				
			||||||
 | 
												<li>
 | 
				
			||||||
 | 
													<bodyType>Thin</bodyType>
 | 
				
			||||||
 | 
													<offset>(0, 0, 0)</offset>
 | 
				
			||||||
 | 
												</li>
 | 
				
			||||||
 | 
											</offsets>
 | 
				
			||||||
 | 
										</li>
 | 
				
			||||||
 | 
									</value>
 | 
				
			||||||
 | 
								</li>
 | 
				
			||||||
 | 
							</operations>
 | 
				
			||||||
 | 
						</Operation>
 | 
				
			||||||
 | 
						-->
 | 
				
			||||||
 | 
					</Patch>
 | 
				
			||||||
| 
						 | 
					@ -36,10 +36,9 @@ namespace Rimworld_Animations
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public int Priority(List<Pawn> actors, out int reorder)
 | 
					        public int Priority(List<Pawn> actors)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            int priority = -999999999;
 | 
					            int priority = -999999999;
 | 
				
			||||||
            reorder = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            foreach (BaseGroupAnimationContext context in contexts)
 | 
					            foreach (BaseGroupAnimationContext context in contexts)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
| 
						 | 
					@ -47,7 +46,30 @@ namespace Rimworld_Animations
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    if (context.AnimationPriority() > priority)
 | 
					                    if (context.AnimationPriority() > priority)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        //get highest priority context for fitting animation, and its reorder
 | 
					                        //get highest priority context for fitting animation
 | 
				
			||||||
 | 
					                        priority = context.AnimationPriority();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return priority;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public int Reorder(List<Pawn> actors)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            int priority = -999999999;
 | 
				
			||||||
 | 
					            int reorder = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            foreach (BaseGroupAnimationContext context in contexts)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                if (context.CanAnimationBeUsed(actors, numActors))
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    if (context.AnimationPriority() > priority)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        //get the reorder for highest priority context for fitting animation
 | 
				
			||||||
                        priority = context.AnimationPriority();
 | 
					                        priority = context.AnimationPriority();
 | 
				
			||||||
                        reorder = context.AnimationReorder();
 | 
					                        reorder = context.AnimationReorder();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,7 +78,7 @@ namespace Rimworld_Animations
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return priority;
 | 
					            return reorder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -88,16 +88,15 @@ namespace Rimworld_Animations {
 | 
				
			||||||
            // if you find one where it returns canAnimationBeUsed (and reorders),
 | 
					            // if you find one where it returns canAnimationBeUsed (and reorders),
 | 
				
			||||||
            // return that animation
 | 
					            // return that animation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            int reorder2 = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //find all, reorder randomly, then find max priority context
 | 
					            //find all, reorder randomly, then find max priority context
 | 
				
			||||||
            DefDatabase<GroupAnimationDef>.AllDefsListForReading
 | 
					            DefDatabase<GroupAnimationDef>.AllDefsListForReading
 | 
				
			||||||
                .FindAll((GroupAnimationDef x) => x.canAnimationBeUsed(participants))
 | 
					                .FindAll((GroupAnimationDef x) => x.canAnimationBeUsed(participants))
 | 
				
			||||||
                .OrderBy(_ => Rand.Int)
 | 
					                .OrderBy(_ => Rand.Int)
 | 
				
			||||||
                .TryMaxBy((GroupAnimationDef x) => x.Priority(participants, out reorder2), out GroupAnimationDef result);
 | 
					                .TryMaxBy((GroupAnimationDef x) => x.Priority(participants), out GroupAnimationDef result);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            reorder = reorder2;
 | 
					            reorder = result.Reorder(participants);
 | 
				
			||||||
            return result;
 | 
					            return result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue