Compare commits

...

3 Commits

Author SHA1 Message Date
c0ffee 66f84a00f3 better error handling for checkandplaysounds 2024-04-22 17:38:30 -07:00
c0ffee 3f7a7bfdc3 better error handling for missing rootnodes or rendernode animationworkers 2024-04-22 17:31:20 -07:00
c0ffee c800084a32 playable sounds 2024-04-22 16:14:04 -07:00
4 changed files with 57 additions and 0 deletions

View File

@ -12,6 +12,7 @@
<workerClass>Rimworld_Animations.AnimationWorker_KeyframesExtended</workerClass>
<keyframes>
<li Class="Rimworld_Animations.ExtendedKeyframe">
<sound>Fuck</sound>
<tick>30</tick>
<angle>0</angle>
<visible>true</visible>

View File

@ -22,6 +22,23 @@ namespace Rimworld_Animations
return base.OffsetAtTick(tick, parms);
}
public SoundDef soundAtTick(int tick)
{
//Verse.Keyframe keyframe = this.part.keyframes[0];
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).sound;
}
}
return null;
}
//use extendedkeyframes to determine addon facing

View File

@ -93,6 +93,9 @@ namespace Rimworld_Animations {
StopAnimating();
}
}
CheckAndPlaySounds();
}
@ -198,6 +201,42 @@ namespace Rimworld_Animations {
}
public void CheckAndPlaySounds()
{
PawnRenderNode rootNode = pawn.Drawer?.renderer?.renderTree?.rootNode;
//check if the rootnode has sounds; if so play it
if (rootNode?.AnimationWorker is AnimationWorker_KeyframesExtended animWorker)
{
SoundDef sound = animWorker.soundAtTick(rootNode.tree.AnimationTick);
if (sound != null)
{
sound.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map));
}
}
if (rootNode?.children != null)
{
foreach (PawnRenderNode node in rootNode?.children)
{
if (node?.AnimationWorker is AnimationWorker_KeyframesExtended childrenAnimWorker)
{
SoundDef sound = childrenAnimWorker.soundAtTick(node.tree.AnimationTick);
if (sound != null)
{
sound.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map));
}
}
}
}
//do the same for all the child nodes
}
public bool AnimationMakesUseOfProp(AnimationPropDef animationProp)
{
// never true if not animating; anim props shouldn't be attached