Skip to content

Commit 17539a6

Browse files
committed
Add cancelConductorUpdate, deathStart
1 parent 16b080b commit 17539a6

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

source/funkin/backend/MusicBeatState.hx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import funkin.backend.system.Controls;
1111
import funkin.backend.system.GraphicCacheSprite;
1212
import funkin.backend.system.framerate.Framerate;
1313
import funkin.backend.system.interfaces.IBeatReceiver;
14+
import funkin.backend.system.interfaces.IBeatCancellableReceiver;
1415
import funkin.options.PlayerSettings;
1516

1617
/**
1718
* Base class for all the states.
1819
* Handles the scripts, the transitions, and the beat and step events.
1920
**/
20-
class MusicBeatState extends FlxState implements IBeatReceiver
21+
class MusicBeatState extends FlxState implements IBeatCancellableReceiver
2122
{
2223
private var lastBeat:Float = 0;
2324
private var lastStep:Float = 0;

source/funkin/backend/MusicBeatSubstate.hx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@ import funkin.backend.scripting.events.*;
99
import funkin.backend.system.Conductor;
1010
import funkin.backend.system.Controls;
1111
import funkin.backend.system.interfaces.IBeatReceiver;
12+
import funkin.backend.system.interfaces.IBeatCancellableReceiver;
1213
import funkin.options.PlayerSettings;
1314

1415
/**
1516
* Base class for all the sub states.
1617
* Handles the scripts, the transitions, and the beat and step events.
1718
**/
18-
class MusicBeatSubstate extends FlxSubState implements IBeatReceiver
19+
class MusicBeatSubstate extends FlxSubState implements IBeatCancellableReceiver
1920
{
2021
private var lastBeat:Float = 0;
2122
private var lastStep:Float = 0;
2223

24+
/**
25+
* Whenever the Conductor auto update should be enabled or not.
26+
*/
27+
public var cancelConductorUpdate:Bool = false;
28+
2329
/**
2430
* Whether this specific substate can open custom transitions
2531
*/

source/funkin/backend/system/Conductor.hx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import flixel.FlxState;
44
import flixel.util.FlxSignal.FlxTypedSignal;
55
import funkin.backend.chart.ChartData;
66
import funkin.backend.system.interfaces.IBeatReceiver;
7+
import funkin.backend.system.interfaces.IBeatCancellableReceiver;
78
import funkin.editors.charter.Charter;
89

910
enum BeatType {
@@ -371,8 +372,14 @@ final class Conductor
371372
private static var __updateMeasure:Bool;
372373

373374
private static function update() {
374-
if (FlxG.state != null && FlxG.state is MusicBeatState && cast(FlxG.state, MusicBeatState).cancelConductorUpdate) return;
375-
375+
if (FlxG.state == null) return;
376+
else {
377+
var state = FlxG.state;
378+
while (state != null) {
379+
if (state is IBeatCancellableReceiver && cast(FlxG.state, IBeatCancellableReceiver).cancelConductorUpdate) return;
380+
state = state.subState;
381+
}
382+
}
376383
__updateSongPos(FlxG.elapsed);
377384

378385
var oldStep = curStep, oldBeat = curBeat, oldMeasure = curMeasure, oldChangeIndex = curChangeIndex;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package funkin.backend.system.interfaces;
2+
3+
interface IBeatCancellableReceiver extends IBeatReceiver {
4+
public var cancelConductorUpdate:Bool;
5+
}

source/funkin/game/GameOverSubstate.hx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class GameOverSubstate extends MusicBeatSubstate
8787

8888
lossSFX = FlxG.sound.play(Paths.sound(lossSFXName));
8989
Conductor.changeBPM(gameOverSongBPM);
90+
cancelConductorUpdate = true;
9091

9192
DiscordUtil.call("onGameOver", []);
9293
gameoverScript.call("postCreate");
@@ -106,22 +107,21 @@ class GameOverSubstate extends MusicBeatSubstate
106107

107108
if (!isEnding && ((!lossSFX.playing) || (character.getAnimName() == "firstDeath" && character.isAnimFinished())) && (FlxG.sound.music == null || !FlxG.sound.music.playing))
108109
{
110+
var event = new CancellableEvent();
111+
gameoverScript.call("deathStart", [event]);
112+
113+
if (event.cancelled) return;
114+
109115
CoolUtil.playMusic(Paths.music(gameOverSong), false, 1, true, Flags.DEFAULT_BPM);
110-
beatHit(0);
116+
character.playAnim("deathLoop", true, DANCE);
117+
cancelConductorUpdate = false;
111118
}
112119
}
113120

114121
override function beatHit(curBeat:Int)
115122
{
116123
super.beatHit(curBeat);
117-
118124
gameoverScript.call("beatHit", [curBeat]);
119-
120-
if (__cancelDefault)
121-
return;
122-
123-
if (FlxG.sound.music != null && FlxG.sound.music.playing)
124-
character.playAnim("deathLoop", true, DANCE);
125125
}
126126

127127
override function stepHit(curStep:Int)

0 commit comments

Comments
 (0)