mirror of
				https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
				synced 2024-08-15 00:43:45 +00:00 
			
		
		
		
	better location finding + mirroring
This commit is contained in:
		
							parent
							
								
									015a64928a
								
							
						
					
					
						commit
						ac5d37bdaf
					
				
					 4 changed files with 78 additions and 14 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -1,4 +1,5 @@
 | 
				
			||||||
using rjw;
 | 
					using RimWorld;
 | 
				
			||||||
 | 
					using rjw;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
| 
						 | 
					@ -14,7 +15,7 @@ namespace Rimworld_Animations {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Pawn pawn;
 | 
					        Pawn pawn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public bool isAnimating = false;
 | 
					        public bool isAnimating = false, mirror;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        int animTicks = 0, stageTicks = 0, clipTicks = 0, curStage = 0;
 | 
					        int animTicks = 0, stageTicks = 0, clipTicks = 0, curStage = 0;
 | 
				
			||||||
        float rotation = 0;
 | 
					        float rotation = 0;
 | 
				
			||||||
| 
						 | 
					@ -33,12 +34,13 @@ namespace Rimworld_Animations {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void StartAnimation(AnimationDef anim, Pawn pawn)
 | 
					        public void StartAnimation(AnimationDef anim, Pawn pawn, bool mirror = false)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            isAnimating = true;
 | 
					            isAnimating = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            this.anim = anim;
 | 
					            this.anim = anim;
 | 
				
			||||||
            this.pawn = pawn;
 | 
					            this.pawn = pawn;
 | 
				
			||||||
 | 
					            this.mirror = mirror;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            animTicks = 0;
 | 
					            animTicks = 0;
 | 
				
			||||||
            stageTicks = 0;
 | 
					            stageTicks = 0;
 | 
				
			||||||
| 
						 | 
					@ -151,18 +153,71 @@ namespace Rimworld_Animations {
 | 
				
			||||||
            calculateDrawValues();
 | 
					            calculateDrawValues();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void setAnchor(Thing thing)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            //center on bed
 | 
				
			||||||
 | 
					            if (thing is Building_Bed)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                anchor = thing.Position.ToVector3();
 | 
				
			||||||
 | 
					                if (((Building_Bed)thing).SleepingSlotsCount == 2)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    if (thing.Rotation.AsInt == 0)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        anchor.x += 1;
 | 
				
			||||||
 | 
					                        anchor.z += 1;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    else if (thing.Rotation.AsInt == 1)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        anchor.x += 1;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    else if (thing.Rotation.AsInt == 3)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        anchor.z += 1;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    if (thing.Rotation.AsInt == 0)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        anchor.x += 0.5f;
 | 
				
			||||||
 | 
					                        anchor.z += 1f;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    else if (thing.Rotation.AsInt == 1)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        anchor.x += 1f;
 | 
				
			||||||
 | 
					                        anchor.z += 0.5f;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    else if (thing.Rotation.AsInt == 2)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        anchor.x += 0.5f;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    else
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        anchor.z += 0.5f;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                anchor = thing.Position.ToVector3Shifted();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            anchor -= new Vector3(0.5f, 0, 0.5f);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        private void calculateDrawValues()
 | 
					        private void calculateDrawValues()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            //shift up and right 0.5f to align center
 | 
					            //shift up and right 0.5f to align center
 | 
				
			||||||
            deltaPos = new Vector3(clip.PositionX.Evaluate(clipPercent) + 0.5f/* todo * (mirror ? -1 : 1) */, AltitudeLayer.Item.AltitudeFor(), clip.PositionZ.Evaluate(clipPercent) + 0.5f);
 | 
					            deltaPos = new Vector3((clip.PositionX.Evaluate(clipPercent)) * (mirror ? -1 : 1) + 0.5f, AltitudeLayer.Item.AltitudeFor(), clip.PositionZ.Evaluate(clipPercent) + 0.5f);
 | 
				
			||||||
            Log.Message("Clip percent: " + clipPercent + " deltaPos: " + deltaPos);
 | 
					            Log.Message("Clip percent: " + clipPercent + " deltaPos: " + deltaPos);
 | 
				
			||||||
            rotation = clip.Rotation.Evaluate(clipPercent);
 | 
					            rotation = clip.Rotation.Evaluate(clipPercent) * (mirror ? -1 : 1);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void AnimateThing(Thing thing) 
 | 
					        public void AnimateThing(Thing thing) 
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            thing.Graphic.Draw(deltaPos + anchor, Rot4.North, thing, rotation);
 | 
					            thing.Graphic.Draw(deltaPos + anchor, mirror ? Rot4.West : Rot4.East, thing, rotation);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public bool LoopNeverending()
 | 
					        public bool LoopNeverending()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -20,33 +20,42 @@ namespace Patch_SexToysMasturbation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(__instance is JobDriver_MasturbateWithToy masturbateJobDriver)
 | 
					            if(__instance is JobDriver_MasturbateWithToy masturbateJobDriver)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                Log.Message("Rerolling animations...");
 | 
					                Log.Message("Rerolling animations...");
 | 
				
			||||||
                Pawn pawn = masturbateJobDriver.pawn;
 | 
					                Pawn pawn = masturbateJobDriver.pawn;
 | 
				
			||||||
                Thing sexToy = masturbateJobDriver.dildo;
 | 
					                Thing sexToy = masturbateJobDriver.dildo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                RerollAnimationsForSexToy(pawn, sexToy);
 | 
					                RerollAnimationsForSexToy(pawn, sexToy, masturbateJobDriver.Bed);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public static void RerollAnimationsForSexToy(Pawn pawn, Thing thing)
 | 
					        public static void RerollAnimationsForSexToy(Pawn pawn, Thing thing, Thing bed)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            CompSexToy sextoy = thing.TryGetComp<CompSexToy>();
 | 
					            CompSexToy sextoy = thing.TryGetComp<CompSexToy>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            SexToyAnimationDef anim = AnimSexToyUtility.tryFindAnimation(sextoy, pawn);
 | 
					            SexToyAnimationDef anim = AnimSexToyUtility.tryFindAnimation(sextoy, pawn);
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (anim != null)
 | 
					            if (anim != null)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Log.Message("Playing anim " + anim.defName);
 | 
					                Log.Message("Playing anim " + anim.defName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                pawn.TryGetComp<CompBodyAnimator>().setAnchor(pawn.Position);
 | 
					                if(bed != null)
 | 
				
			||||||
                thing.TryGetComp<CompThingAnimator>().setAnchor(pawn.Position);
 | 
					                {
 | 
				
			||||||
 | 
					                    pawn.TryGetComp<CompBodyAnimator>().setAnchor(bed);
 | 
				
			||||||
 | 
					                    thing.TryGetComp<CompThingAnimator>().setAnchor(bed);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    pawn.TryGetComp<CompBodyAnimator>().setAnchor(pawn.Position);
 | 
				
			||||||
 | 
					                    thing.TryGetComp<CompThingAnimator>().setAnchor(pawn.Position);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                pawn.TryGetComp<CompBodyAnimator>().StartAnimation(anim, new List<Pawn> { pawn }, 0);
 | 
					                bool mirror = GenTicks.TicksGame % 2 == 0;
 | 
				
			||||||
                thing.TryGetComp<CompThingAnimator>().StartAnimation(anim, pawn);
 | 
					
 | 
				
			||||||
 | 
					                pawn.TryGetComp<CompBodyAnimator>().StartAnimation(anim, new List<Pawn> { pawn }, 0, mirror);
 | 
				
			||||||
 | 
					                thing.TryGetComp<CompThingAnimator>().StartAnimation(anim, pawn, mirror);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                (pawn.jobs.curDriver as JobDriver_Sex).ticks_left = anim.animationTimeTicks;
 | 
					                (pawn.jobs.curDriver as JobDriver_Sex).ticks_left = anim.animationTimeTicks;
 | 
				
			||||||
                (pawn.jobs.curDriver as JobDriver_Sex).sex_ticks = anim.animationTimeTicks;
 | 
					                (pawn.jobs.curDriver as JobDriver_Sex).sex_ticks = anim.animationTimeTicks;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue