mirror of
				https://gitgud.io/c0ffeeeeeeee/rimworld-animations.git
				synced 2024-08-15 00:43:45 +00:00 
			
		
		
		
	Added Sound Framework
This commit is contained in:
		
							parent
							
								
									abb3c1fe18
								
							
						
					
					
						commit
						96986104d5
					
				
					 6 changed files with 117 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -22,6 +22,23 @@ namespace Rimworld_Animations
 | 
			
		|||
            return base.OffsetAtTick(tick, parms);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public VoiceTagDef voiceAtTick(int tick)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            Verse.Keyframe keyframe2 = this.part.keyframes[this.part.keyframes.Count - 1];
 | 
			
		||||
            foreach (Verse.Keyframe keyframe in this.part.keyframes)
 | 
			
		||||
            {
 | 
			
		||||
                if (tick == keyframe.tick)
 | 
			
		||||
                {
 | 
			
		||||
                    return (keyframe as ExtendedKeyframe).voice;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return null;
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public SoundDef soundAtTick(int tick)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,7 @@ namespace Rimworld_Animations
 | 
			
		|||
        public int? variant;
 | 
			
		||||
        public Rot4 rotation = Rot4.North;
 | 
			
		||||
        public SoundDef sound = null;
 | 
			
		||||
        public VoiceTagDef voice = null;
 | 
			
		||||
        public bool visible = true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,11 +19,11 @@ namespace Rimworld_Animations {
 | 
			
		|||
 | 
			
		||||
        private List<AnimationDef> animationQueue;
 | 
			
		||||
        private BaseExtendedAnimatorAnchor anchor;
 | 
			
		||||
        private int? rotation;
 | 
			
		||||
        private Vector3? offset;
 | 
			
		||||
        private bool isAnimating = false;
 | 
			
		||||
        private VoiceDef voice;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        private bool isAnimating = false;
 | 
			
		||||
 | 
			
		||||
        public bool IsAnimating
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
| 
						 | 
				
			
			@ -40,6 +40,8 @@ namespace Rimworld_Animations {
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private Vector3? offset;
 | 
			
		||||
 | 
			
		||||
        public Vector3? Offset
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
| 
						 | 
				
			
			@ -52,6 +54,8 @@ namespace Rimworld_Animations {
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private int? rotation;
 | 
			
		||||
 | 
			
		||||
        public int? Rotation
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
| 
						 | 
				
			
			@ -90,6 +94,15 @@ namespace Rimworld_Animations {
 | 
			
		|||
        
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override void PostSpawnSetup(bool respawningAfterLoad)
 | 
			
		||||
        {
 | 
			
		||||
            if (voice == null)
 | 
			
		||||
            {
 | 
			
		||||
                AssignNewVoice();
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Vector3 getAnchor()
 | 
			
		||||
        {
 | 
			
		||||
            return anchor.getDrawPos();
 | 
			
		||||
| 
						 | 
				
			
			@ -184,6 +197,7 @@ namespace Rimworld_Animations {
 | 
			
		|||
            Scribe_Values.Look<int>(ref this.animationTicks, "animations_ticks", 0);
 | 
			
		||||
            Scribe_Collections.Look<AnimationDef>(ref animationQueue, "animations_queue");
 | 
			
		||||
            Scribe_Deep.Look<BaseExtendedAnimatorAnchor>(ref this.anchor, "animations_anchor");
 | 
			
		||||
            Scribe_Defs.Look<VoiceDef>(ref this.voice, "animations_voice");
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -233,6 +247,29 @@ namespace Rimworld_Animations {
 | 
			
		|||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void AssignNewVoice()
 | 
			
		||||
        {
 | 
			
		||||
            //all voice options
 | 
			
		||||
            List<VoiceDef> voiceOptions =
 | 
			
		||||
                DefDatabase<VoiceDef>.AllDefsListForReading
 | 
			
		||||
                .FindAll(voiceDef => voice.VoiceFitsPawn(pawn));
 | 
			
		||||
 | 
			
		||||
            //all voice options, with priority (for traitdef specific voices)
 | 
			
		||||
            List<VoiceDef> voiceOptionsWithPriority =
 | 
			
		||||
                voiceOptions.FindAll(voiceDef => voice.takesPriority);
 | 
			
		||||
 | 
			
		||||
            if (!voiceOptionsWithPriority.NullOrEmpty())
 | 
			
		||||
            {
 | 
			
		||||
                voice = voiceOptionsWithPriority.RandomElementByWeight(x => x.randomChanceFactor);
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            else if (!voiceOptions.NullOrEmpty())
 | 
			
		||||
            {
 | 
			
		||||
                voice = voiceOptions.RandomElementByWeight(x => x.randomChanceFactor);
 | 
			
		||||
            }
 | 
			
		||||
                
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void CheckAndPlaySounds()
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -247,9 +284,32 @@ namespace Rimworld_Animations {
 | 
			
		|||
                    sound.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                //play voice sounds
 | 
			
		||||
                VoiceTagDef voiceTag = animWorker.voiceAtTick(rootNode.tree.AnimationTick);
 | 
			
		||||
                if (voiceTag != null)
 | 
			
		||||
                {
 | 
			
		||||
                    if (voice != null && voice.sounds.ContainsKey(voiceTag))
 | 
			
		||||
                    {
 | 
			
		||||
                        voice.sounds[voiceTag].PlayOneShot(new TargetInfo(pawn.Position, pawn.Map));
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    else if (pawn.RaceProps.Humanlike && RJWAnimationSettings.playHumanlikeVoicesAsDefault)
 | 
			
		||||
                    {
 | 
			
		||||
                        //play default voice
 | 
			
		||||
                        VoiceDef pawnDefaultVoice = (pawn.gender == Gender.Male ? VoiceDefOf.Voice_HumanMale : VoiceDefOf.Voice_HumanFemale);
 | 
			
		||||
                        if (pawnDefaultVoice.sounds.ContainsKey(voiceTag))
 | 
			
		||||
                        {
 | 
			
		||||
                            pawnDefaultVoice.sounds[voiceTag].PlayOneShot(new TargetInfo(pawn.Position, pawn.Map));
 | 
			
		||||
                        }
 | 
			
		||||
                        
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            //check rootnodes and children
 | 
			
		||||
            if (rootNode?.children != null)
 | 
			
		||||
            {
 | 
			
		||||
                foreach (PawnRenderNode node in rootNode?.children)
 | 
			
		||||
| 
						 | 
				
			
			@ -262,6 +322,25 @@ namespace Rimworld_Animations {
 | 
			
		|||
                            sound.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map));
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        //play voice sounds
 | 
			
		||||
                        VoiceTagDef voiceTag = childrenAnimWorker.voiceAtTick(rootNode.tree.AnimationTick);
 | 
			
		||||
                        if (voiceTag != null)
 | 
			
		||||
                        {
 | 
			
		||||
                            if (voice != null && voice.sounds.ContainsKey(voiceTag))
 | 
			
		||||
                            {
 | 
			
		||||
                                voice.sounds[voiceTag].PlayOneShot(new TargetInfo(pawn.Position, pawn.Map));
 | 
			
		||||
                            }
 | 
			
		||||
                            else if (pawn.RaceProps.Humanlike && RJWAnimationSettings.playHumanlikeVoicesAsDefault)
 | 
			
		||||
                            {
 | 
			
		||||
 | 
			
		||||
                                VoiceDef pawnDefaultVoice = (pawn.gender == Gender.Male ? VoiceDefOf.Voice_HumanMale : VoiceDefOf.Voice_HumanFemale);
 | 
			
		||||
                                if (pawnDefaultVoice.sounds.ContainsKey(voiceTag))
 | 
			
		||||
                                {
 | 
			
		||||
                                    pawnDefaultVoice.sounds[voiceTag].PlayOneShot(new TargetInfo(pawn.Position, pawn.Map));
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -269,6 +348,9 @@ namespace Rimworld_Animations {
 | 
			
		|||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public bool AnimationMakesUseOfProp(AnimationPropDef animationProp)
 | 
			
		||||
        {
 | 
			
		||||
            // never true if not animating; anim props shouldn't be attached
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,9 @@ namespace Rimworld_Animations {
 | 
			
		|||
        public static bool orgasmQuiver, rapeShiver, soundOverride = true, hearts = true, controlGenitalRotation = false,
 | 
			
		||||
            PlayAnimForNonsexualActs = true;
 | 
			
		||||
 | 
			
		||||
        //probably move this setting to a different mod menu if moving rjw parts of code
 | 
			
		||||
        public static bool playHumanlikeVoicesAsDefault = true;
 | 
			
		||||
 | 
			
		||||
        public static bool offsetTab = false, debugMode = false;
 | 
			
		||||
        public static float shiverIntensity = 2f;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -21,6 +24,7 @@ namespace Rimworld_Animations {
 | 
			
		|||
 | 
			
		||||
            base.ExposeData();
 | 
			
		||||
 | 
			
		||||
            Scribe_Values.Look(ref playHumanlikeVoicesAsDefault, "RJWAnimations-playHumanlikeVoicesAsDefault", true);
 | 
			
		||||
            Scribe_Values.Look(ref debugMode, "RJWAnimations-AnimsDebugMode", false);
 | 
			
		||||
            Scribe_Values.Look(ref offsetTab, "RJWAnimations-EnableOffsetTab", false);
 | 
			
		||||
            Scribe_Values.Look(ref controlGenitalRotation, "RJWAnimations-controlGenitalRotation", false);
 | 
			
		||||
| 
						 | 
				
			
			@ -55,6 +59,7 @@ namespace Rimworld_Animations {
 | 
			
		|||
            listingStandard.CheckboxLabeled("RimAnim_HeartsDuringLovin".Translate(), ref RJWAnimationSettings.hearts);
 | 
			
		||||
            listingStandard.CheckboxLabeled("RimAnim_PlayNonsexual".Translate(), ref RJWAnimationSettings.PlayAnimForNonsexualActs);
 | 
			
		||||
            listingStandard.CheckboxLabeled("RimAnim_AnimManagerTab".Translate(), ref RJWAnimationSettings.offsetTab);
 | 
			
		||||
            listingStandard.CheckboxLabeled("RimAnim_HumanlikeVoicesDefault".Translate(), ref RJWAnimationSettings.playHumanlikeVoicesAsDefault);
 | 
			
		||||
            listingStandard.Label("RimAnim_ShiverIntensity".Translate() + RJWAnimationSettings.shiverIntensity);
 | 
			
		||||
            RJWAnimationSettings.shiverIntensity = listingStandard.Slider(RJWAnimationSettings.shiverIntensity, 0.0f, 12f);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,6 +11,7 @@
 | 
			
		|||
	<RimAnim_PlayNonsexual>Play animation for nonsexual acts (handholding, makeout)</RimAnim_PlayNonsexual>
 | 
			
		||||
	<RimAnim_AnimManagerTab>Enable Animation Manager Tab</RimAnim_AnimManagerTab>
 | 
			
		||||
	<RimAnim_ShiverIntensity>Shiver/Quiver Intensity (default 2): </RimAnim_ShiverIntensity>
 | 
			
		||||
	<RimAnim_HumanlikeVoicesDefault>Play humanlike voices by default</RimAnim_HumanlikeVoicesDefault>
 | 
			
		||||
	<RimAnim_DebugMode>Debug Mode</RimAnim_DebugMode>
 | 
			
		||||
	
 | 
			
		||||
	<!-- Main Tab Window -->
 | 
			
		||||
| 
						 | 
				
			
			@ -19,4 +20,5 @@
 | 
			
		|||
	<RimAnims_CopyToClipboard>Copy Offset to Clipboard</RimAnims_CopyToClipboard>
 | 
			
		||||
	<RimAnims_ShareSettings>Paste offset values in OffsetDef, or share in Discord</RimAnims_ShareSettings>
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
</LanguageData>
 | 
			
		||||
| 
						 | 
				
			
			@ -134,6 +134,9 @@
 | 
			
		|||
    <Compile Include="1.5\Source\RenderSubWorkers\PawnRenderSubWorker_ChangeOffset.cs" />
 | 
			
		||||
    <Compile Include="1.5\Source\Patches\RJWPatches\RJWAnimationSettings.cs" />
 | 
			
		||||
    <Compile Include="1.5\Source\Utilities\AnimationUtility.cs" />
 | 
			
		||||
    <Compile Include="1.5\Source\Voices\VoiceDef.cs" />
 | 
			
		||||
    <Compile Include="1.5\Source\Voices\VoiceDefOf.cs" />
 | 
			
		||||
    <Compile Include="1.5\Source\Voices\VoiceTagDef.cs" />
 | 
			
		||||
    <Compile Include="Properties\AssemblyInfo.cs" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
| 
						 | 
				
			
			@ -193,6 +196,9 @@
 | 
			
		|||
    <Content Include="1.5\Defs\TexPathVariantsDefs\TexPathVariants_Xray_Inside.xml" />
 | 
			
		||||
    <Content Include="1.5\Defs\TexPathVariantsDefs\TexPathVariants_XrayPenis_Horse.xml" />
 | 
			
		||||
    <Content Include="1.5\Defs\AnimationDefs\Cowgirl\TexPathVariants_Cowgirl.xml" />
 | 
			
		||||
    <Content Include="1.5\Defs\VoiceDefs\VoiceDef_Human.xml" />
 | 
			
		||||
    <Content Include="1.5\Defs\VoiceDefs\VoiceDef_Orassan.xml" />
 | 
			
		||||
    <Content Include="1.5\Defs\VoiceDefs\VoiceTagDef.xml" />
 | 
			
		||||
    <Content Include="1.5\Patches\AnimationPatchHSK.xml" />
 | 
			
		||||
    <Content Include="1.5\Patches\AnimationPatch_CompExtendedAnimator.xml" />
 | 
			
		||||
    <Content Include="1.5\Patches\AnimationPatch_PawnRenderTree_OffsetSubWorker.xml" />
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue