Skip to content

Commit 9cb2864

Browse files
null safety for remaining base funkin.play classes
1 parent b9d6895 commit 9cb2864

File tree

4 files changed

+89
-66
lines changed

4 files changed

+89
-66
lines changed

source/funkin/play/Countdown.hx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import funkin.audio.FunkinSound;
1010
import funkin.data.notestyle.NoteStyleRegistry;
1111
import funkin.play.notes.notestyle.NoteStyle;
1212

13+
@:nullSafety
1314
class Countdown
1415
{
1516
/**
@@ -31,14 +32,14 @@ class Countdown
3132
*/
3233
public static var graphicSuffix:String = '';
3334

34-
static var noteStyle:NoteStyle;
35+
static var noteStyle:Null<NoteStyle>;
3536

3637
static var fallbackNoteStyle:Null<NoteStyle>;
3738

3839
/**
3940
* The currently running countdown. This will be null if there is no countdown running.
4041
*/
41-
static var countdownTimer:FlxTimer = null;
42+
static var countdownTimer:Null<FlxTimer> = null;
4243

4344
/**
4445
* Performs the countdown.
@@ -58,8 +59,8 @@ class Countdown
5859
// Stop any existing countdown.
5960
stopCountdown();
6061

61-
PlayState.instance.isInCountdown = true;
62-
Conductor.instance.update(PlayState.instance.startTimestamp + Conductor.instance.beatLengthMs * -5);
62+
if (PlayState.instance != null) PlayState.instance.isInCountdown = true;
63+
Conductor.instance.update((PlayState.instance?.startTimestamp ?? 0) + Conductor.instance.beatLengthMs * -5);
6364
// Handle onBeatHit events manually
6465
// @:privateAccess
6566
// PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0));
@@ -124,7 +125,7 @@ class Countdown
124125

125126
// Modules, stages, characters.
126127
@:privateAccess
127-
PlayState.instance.dispatchEvent(event);
128+
PlayState.instance?.dispatchEvent(event);
128129

129130
return event.eventCanceled;
130131
}
@@ -211,7 +212,7 @@ class Countdown
211212

212213
if (noteStyleId == null) noteStyleId = PlayState.instance?.currentChart?.noteStyle;
213214

214-
noteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyleId);
215+
if (noteStyleId != null) noteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyleId);
215216
if (noteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault();
216217
}
217218

@@ -222,10 +223,13 @@ class Countdown
222223
{
223224
fetchNoteStyle();
224225

225-
var countdownSprite = noteStyle.buildCountdownSprite(index);
226+
var countdownSprite = noteStyle?.buildCountdownSprite(index);
226227
if (countdownSprite == null) return;
227228

228229
var fadeEase = FlxEase.cubeInOut;
230+
231+
// fetchNoteStyle will always set notestyle to default if null, so no need to worry here
232+
@:nullSafety(Off)
229233
if (noteStyle.isCountdownSpritePixel(index)) fadeEase = EaseUtil.stepped(8);
230234

231235
// Fade sprite in, then out, then destroy it.
@@ -237,25 +241,25 @@ class Countdown
237241
}
238242
});
239243

240-
countdownSprite.cameras = [PlayState.instance.camHUD];
241-
PlayState.instance.add(countdownSprite);
244+
if (PlayState.instance != null) countdownSprite.cameras = [PlayState.instance.camHUD];
245+
PlayState.instance?.add(countdownSprite);
242246
countdownSprite.screenCenter();
243247

248+
// fetchNoteStyle will always set notestyle to default if null, so no need to worry here
249+
@:nullSafety(Off)
244250
var offsets = noteStyle.getCountdownSpriteOffsets(index);
245251
countdownSprite.x += offsets[0];
246252
countdownSprite.y += offsets[1];
247253
}
248254

249255
/**
250-
* Retrieves the sound file to use for this step of the countdown.
256+
* Retrieves and plays the sound file to use for this step of the countdown.
251257
*/
252-
public static function playCountdownSound(step:CountdownStep):FunkinSound
258+
public static function playCountdownSound(step:CountdownStep):Void
253259
{
254260
fetchNoteStyle();
255-
var path = noteStyle.getCountdownSoundPath(step);
256-
if (path == null) return null;
257-
258-
return FunkinSound.playOnce(path, Constants.COUNTDOWN_VOLUME, null, null, true);
261+
var path = noteStyle?.getCountdownSoundPath(step);
262+
if (path != null) FunkinSound.playOnce(path, Constants.COUNTDOWN_VOLUME, null, null, true);
259263
}
260264

261265
public static function decrement(step:CountdownStep):CountdownStep

source/funkin/play/GitarooPause.hx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import funkin.util.TouchUtil;
1111
import funkin.util.SwipeUtil;
1212
#end
1313

14+
@:nullSafety
1415
class GitarooPause extends MusicBeatState
1516
{
1617
var replayButton:FlxSprite;
@@ -25,13 +26,16 @@ class GitarooPause extends MusicBeatState
2526
super();
2627

2728
this.previousParams = previousParams;
29+
replayButton = FunkinSprite.createSparrow(FlxG.width * 0.25, FlxG.height * 0.7, 'pauseAlt/pauseUI');
30+
cancelButton = FunkinSprite.createSparrow(FlxG.width * 0.58, replayButton.y, 'pauseAlt/pauseUI');
2831
}
2932

3033
override function create():Void
3134
{
3235
if (FlxG.sound.music != null)
3336
{
3437
FlxG.sound.music.destroy();
38+
@:nullSafety(Off)
3539
FlxG.sound.music = null;
3640
}
3741

@@ -47,13 +51,11 @@ class GitarooPause extends MusicBeatState
4751
bf.screenCenter(X);
4852
add(bf);
4953

50-
replayButton = FunkinSprite.createSparrow(FlxG.width * 0.25, FlxG.height * 0.7, 'pauseAlt/pauseUI');
5154
replayButton.animation.addByPrefix('selected', 'bluereplay', 0, false);
5255
replayButton.animation.appendByPrefix('selected', 'yellowreplay');
5356
replayButton.animation.play('selected');
5457
add(replayButton);
5558

56-
cancelButton = FunkinSprite.createSparrow(FlxG.width * 0.58, replayButton.y, 'pauseAlt/pauseUI');
5759
cancelButton.animation.addByPrefix('selected', 'bluecancel', 0, false);
5860
cancelButton.animation.appendByPrefix('selected', 'cancelyellow');
5961
cancelButton.animation.play('selected');

0 commit comments

Comments
 (0)