@@ -10,6 +10,7 @@ import funkin.audio.FunkinSound;
10
10
import funkin .data .notestyle .NoteStyleRegistry ;
11
11
import funkin .play .notes .notestyle .NoteStyle ;
12
12
13
+ @:nullSafety
13
14
class Countdown
14
15
{
15
16
/**
@@ -31,14 +32,14 @@ class Countdown
31
32
*/
32
33
public static var graphicSuffix : String = ' ' ;
33
34
34
- static var noteStyle : NoteStyle ;
35
+ static var noteStyle : Null < NoteStyle > ;
35
36
36
37
static var fallbackNoteStyle : Null <NoteStyle >;
37
38
38
39
/**
39
40
* The currently running countdown. This will be null if there is no countdown running.
40
41
*/
41
- static var countdownTimer : FlxTimer = null ;
42
+ static var countdownTimer : Null < FlxTimer > = null ;
42
43
43
44
/**
44
45
* Performs the countdown.
@@ -58,8 +59,8 @@ class Countdown
58
59
// Stop any existing countdown.
59
60
stopCountdown ();
60
61
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 );
63
64
// Handle onBeatHit events manually
64
65
// @:privateAccess
65
66
// PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0));
@@ -124,7 +125,7 @@ class Countdown
124
125
125
126
// Modules, stages, characters.
126
127
@:privateAccess
127
- PlayState .instance .dispatchEvent (event );
128
+ PlayState .instance ? .dispatchEvent (event );
128
129
129
130
return event .eventCanceled ;
130
131
}
@@ -211,7 +212,7 @@ class Countdown
211
212
212
213
if (noteStyleId == null ) noteStyleId = PlayState .instance ?. currentChart ?. noteStyle ;
213
214
214
- noteStyle = NoteStyleRegistry .instance .fetchEntry (noteStyleId );
215
+ if ( noteStyleId != null ) noteStyle = NoteStyleRegistry .instance .fetchEntry (noteStyleId );
215
216
if (noteStyle == null ) noteStyle = NoteStyleRegistry .instance .fetchDefault ();
216
217
}
217
218
@@ -222,10 +223,13 @@ class Countdown
222
223
{
223
224
fetchNoteStyle ();
224
225
225
- var countdownSprite = noteStyle .buildCountdownSprite (index );
226
+ var countdownSprite = noteStyle ? .buildCountdownSprite (index );
226
227
if (countdownSprite == null ) return ;
227
228
228
229
var fadeEase = FlxEase .cubeInOut ;
230
+
231
+ // fetchNoteStyle will always set notestyle to default if null, so no need to worry here
232
+ @:nullSafety (Off )
229
233
if (noteStyle .isCountdownSpritePixel (index )) fadeEase = EaseUtil .stepped (8 );
230
234
231
235
// Fade sprite in, then out, then destroy it.
@@ -237,25 +241,25 @@ class Countdown
237
241
}
238
242
});
239
243
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 );
242
246
countdownSprite .screenCenter ();
243
247
248
+ // fetchNoteStyle will always set notestyle to default if null, so no need to worry here
249
+ @:nullSafety (Off )
244
250
var offsets = noteStyle .getCountdownSpriteOffsets (index );
245
251
countdownSprite .x + = offsets [0 ];
246
252
countdownSprite .y + = offsets [1 ];
247
253
}
248
254
249
255
/**
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.
251
257
*/
252
- public static function playCountdownSound (step : CountdownStep ): FunkinSound
258
+ public static function playCountdownSound (step : CountdownStep ): Void
253
259
{
254
260
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 );
259
263
}
260
264
261
265
public static function decrement (step : CountdownStep ): CountdownStep
0 commit comments