diff --git a/source/funkin/backend/MusicBeatState.hx b/source/funkin/backend/MusicBeatState.hx index 38d51281..74d95366 100644 --- a/source/funkin/backend/MusicBeatState.hx +++ b/source/funkin/backend/MusicBeatState.hx @@ -11,13 +11,14 @@ import funkin.backend.system.Controls; import funkin.backend.system.GraphicCacheSprite; import funkin.backend.system.framerate.Framerate; import funkin.backend.system.interfaces.IBeatReceiver; +import funkin.backend.system.interfaces.IBeatCancellableReceiver; import funkin.options.PlayerSettings; /** * Base class for all the states. * Handles the scripts, the transitions, and the beat and step events. **/ -class MusicBeatState extends FlxState implements IBeatReceiver +class MusicBeatState extends FlxState implements IBeatCancellableReceiver { private var lastBeat:Float = 0; private var lastStep:Float = 0; diff --git a/source/funkin/backend/MusicBeatSubstate.hx b/source/funkin/backend/MusicBeatSubstate.hx index 5ad900d4..78157efd 100644 --- a/source/funkin/backend/MusicBeatSubstate.hx +++ b/source/funkin/backend/MusicBeatSubstate.hx @@ -9,17 +9,23 @@ import funkin.backend.scripting.events.*; import funkin.backend.system.Conductor; import funkin.backend.system.Controls; import funkin.backend.system.interfaces.IBeatReceiver; +import funkin.backend.system.interfaces.IBeatCancellableReceiver; import funkin.options.PlayerSettings; /** * Base class for all the sub states. * Handles the scripts, the transitions, and the beat and step events. **/ -class MusicBeatSubstate extends FlxSubState implements IBeatReceiver +class MusicBeatSubstate extends FlxSubState implements IBeatCancellableReceiver { private var lastBeat:Float = 0; private var lastStep:Float = 0; + /** + * Whenever the Conductor auto update should be enabled or not. + */ + public var cancelConductorUpdate:Bool = false; + /** * Whether this specific substate can open custom transitions */ diff --git a/source/funkin/backend/system/Conductor.hx b/source/funkin/backend/system/Conductor.hx index cdfc854f..e3048139 100644 --- a/source/funkin/backend/system/Conductor.hx +++ b/source/funkin/backend/system/Conductor.hx @@ -4,6 +4,7 @@ import flixel.FlxState; import flixel.util.FlxSignal.FlxTypedSignal; import funkin.backend.chart.ChartData; import funkin.backend.system.interfaces.IBeatReceiver; +import funkin.backend.system.interfaces.IBeatCancellableReceiver; import funkin.editors.charter.Charter; enum BeatType { @@ -371,8 +372,14 @@ final class Conductor private static var __updateMeasure:Bool; private static function update() { - if (FlxG.state != null && FlxG.state is MusicBeatState && cast(FlxG.state, MusicBeatState).cancelConductorUpdate) return; - + if (FlxG.state == null) return; + else { + var state = FlxG.state; + while (state != null) { + if (state is IBeatCancellableReceiver && cast(FlxG.state, IBeatCancellableReceiver).cancelConductorUpdate) return; + state = state.subState; + } + } __updateSongPos(FlxG.elapsed); var oldStep = curStep, oldBeat = curBeat, oldMeasure = curMeasure, oldChangeIndex = curChangeIndex; diff --git a/source/funkin/backend/system/interfaces/IBeatCancellableReceiver.hx b/source/funkin/backend/system/interfaces/IBeatCancellableReceiver.hx new file mode 100644 index 00000000..c04f4455 --- /dev/null +++ b/source/funkin/backend/system/interfaces/IBeatCancellableReceiver.hx @@ -0,0 +1,5 @@ +package funkin.backend.system.interfaces; + +interface IBeatCancellableReceiver extends IBeatReceiver { + public var cancelConductorUpdate:Bool; +} \ No newline at end of file diff --git a/source/funkin/game/GameOverSubstate.hx b/source/funkin/game/GameOverSubstate.hx index a98c0640..56de5d26 100644 --- a/source/funkin/game/GameOverSubstate.hx +++ b/source/funkin/game/GameOverSubstate.hx @@ -87,6 +87,7 @@ class GameOverSubstate extends MusicBeatSubstate lossSFX = FlxG.sound.play(Paths.sound(lossSFXName)); Conductor.changeBPM(gameOverSongBPM); + cancelConductorUpdate = true; DiscordUtil.call("onGameOver", []); gameoverScript.call("postCreate"); @@ -106,22 +107,21 @@ class GameOverSubstate extends MusicBeatSubstate if (!isEnding && ((!lossSFX.playing) || (character.getAnimName() == "firstDeath" && character.isAnimFinished())) && (FlxG.sound.music == null || !FlxG.sound.music.playing)) { + var event = new CancellableEvent(); + gameoverScript.call("deathStart", [event]); + + if (event.cancelled) return; + CoolUtil.playMusic(Paths.music(gameOverSong), false, 1, true, Flags.DEFAULT_BPM); - beatHit(0); + character.playAnim("deathLoop", true, DANCE); + cancelConductorUpdate = false; } } override function beatHit(curBeat:Int) { super.beatHit(curBeat); - gameoverScript.call("beatHit", [curBeat]); - - if (__cancelDefault) - return; - - if (FlxG.sound.music != null && FlxG.sound.music.playing) - character.playAnim("deathLoop", true, DANCE); } override function stepHit(curStep:Int)