Skip to content

Commit 68b1bea

Browse files
committed
fix shapeshifter rumble sound persisting
1 parent b78dc90 commit 68b1bea

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/CommunalHelperModule.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public override void Load()
119119
AffectSpriteTrigger.Load();
120120

121121
MelvinTargetable.Load();
122+
123+
Shapeshifter.Load();
122124

123125
#region Imports
124126

@@ -217,6 +219,8 @@ public override void Unload()
217219
AffectSpriteTrigger.Unload();
218220

219221
MelvinTargetable.Unload();
222+
223+
Shapeshifter.Unload();
220224

221225
LaserEmitter.Unload();
222226
}

src/Entities/Shapeshifter/Shapeshifter.cs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Celeste.Mod.CommunalHelper.Components;
22
using Celeste.Mod.CommunalHelper.Utils;
3+
using FMOD.Studio;
34
using System.Collections;
45
using System.Linq;
56

@@ -89,6 +90,7 @@ public class Shapeshifter : Solid
8990
private readonly float rainbowMix;
9091

9192
private readonly SoundSource sfx;
93+
private EventInstance quakeSfx;
9294

9395
public Shapeshifter(EntityData data, Vector2 offset, EntityID id)
9496
: this
@@ -244,10 +246,11 @@ private IEnumerator Sequence(ShapeshifterPath path)
244246

245247
if (path.QuakeTime > 0.0f)
246248
{
247-
var quakeSfx = Audio.Play(CustomSFX.game_shapeshifter_shake, Position);
249+
quakeSfx = Audio.Play(CustomSFX.game_shapeshifter_shake, Position);
248250
StartShaking(path.QuakeTime);
249251
yield return path.QuakeTime;
250-
quakeSfx.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
252+
quakeSfx.stop(STOP_MODE.ALLOWFADEOUT);
253+
quakeSfx = null;
251254
}
252255

253256
Audio.Play(startSound, Position);
@@ -372,4 +375,45 @@ public override void Update()
372375
base.Update();
373376
mesh.Matrix = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll);
374377
}
378+
379+
private void StopSfx()
380+
{
381+
sfx?.Stop();
382+
quakeSfx?.stop(STOP_MODE.IMMEDIATE);
383+
}
384+
385+
public override void Removed(Scene scene)
386+
{
387+
StopSfx();
388+
base.Removed(scene);
389+
}
390+
391+
public override void SceneEnd(Scene scene)
392+
{
393+
StopSfx();
394+
base.SceneEnd(scene);
395+
}
396+
397+
#region Hooks
398+
399+
internal static void Load()
400+
{
401+
Everest.Events.Player.OnDie += OnDie;
402+
}
403+
404+
internal static void Unload()
405+
{
406+
Everest.Events.Player.OnDie -= OnDie;
407+
}
408+
409+
private static void OnDie(Player player)
410+
{
411+
if (player.Scene?.Tracker?.GetEntities<Shapeshifter>()?.Cast<Shapeshifter>() is not { } shapeshifters)
412+
return;
413+
414+
foreach (Shapeshifter shapeshifter in shapeshifters)
415+
shapeshifter.StopSfx();
416+
}
417+
418+
#endregion
375419
}

0 commit comments

Comments
 (0)