Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions source/funkin/play/Countdown.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import funkin.audio.FunkinSound;
import funkin.data.notestyle.NoteStyleRegistry;
import funkin.play.notes.notestyle.NoteStyle;

@:nullSafety
class Countdown
{
/**
Expand All @@ -31,14 +32,14 @@ class Countdown
*/
public static var graphicSuffix:String = '';

static var noteStyle:NoteStyle;
static var noteStyle:Null<NoteStyle>;

static var fallbackNoteStyle:Null<NoteStyle>;

/**
* The currently running countdown. This will be null if there is no countdown running.
*/
static var countdownTimer:FlxTimer = null;
static var countdownTimer:Null<FlxTimer> = null;

/**
* Performs the countdown.
Expand All @@ -58,8 +59,8 @@ class Countdown
// Stop any existing countdown.
stopCountdown();

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

// Modules, stages, characters.
@:privateAccess
PlayState.instance.dispatchEvent(event);
PlayState.instance?.dispatchEvent(event);

return event.eventCanceled;
}
Expand Down Expand Up @@ -211,7 +212,7 @@ class Countdown

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

noteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyleId);
if (noteStyleId != null) noteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyleId);
if (noteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault();
}

Expand All @@ -222,10 +223,13 @@ class Countdown
{
fetchNoteStyle();

var countdownSprite = noteStyle.buildCountdownSprite(index);
var countdownSprite = noteStyle?.buildCountdownSprite(index);
if (countdownSprite == null) return;

var fadeEase = FlxEase.cubeInOut;

// fetchNoteStyle will always set notestyle to default if null, so no need to worry here
@:nullSafety(Off)
if (noteStyle.isCountdownSpritePixel(index)) fadeEase = EaseUtil.stepped(8);

// Fade sprite in, then out, then destroy it.
Expand All @@ -237,25 +241,25 @@ class Countdown
}
});

countdownSprite.cameras = [PlayState.instance.camHUD];
PlayState.instance.add(countdownSprite);
if (PlayState.instance != null) countdownSprite.cameras = [PlayState.instance.camHUD];
PlayState.instance?.add(countdownSprite);
countdownSprite.screenCenter();

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

/**
* Retrieves the sound file to use for this step of the countdown.
* Retrieves and plays the sound file to use for this step of the countdown.
*/
public static function playCountdownSound(step:CountdownStep):FunkinSound
public static function playCountdownSound(step:CountdownStep):Void
{
fetchNoteStyle();
var path = noteStyle.getCountdownSoundPath(step);
if (path == null) return null;

return FunkinSound.playOnce(path, Constants.COUNTDOWN_VOLUME, null, null, true);
var path = noteStyle?.getCountdownSoundPath(step);
if (path != null) FunkinSound.playOnce(path, Constants.COUNTDOWN_VOLUME, null, null, true);
}

public static function decrement(step:CountdownStep):CountdownStep
Expand Down
6 changes: 4 additions & 2 deletions source/funkin/play/GitarooPause.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import funkin.util.TouchUtil;
import funkin.util.SwipeUtil;
#end

@:nullSafety
class GitarooPause extends MusicBeatState
{
var replayButton:FlxSprite;
Expand All @@ -25,13 +26,16 @@ class GitarooPause extends MusicBeatState
super();

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

override function create():Void
{
if (FlxG.sound.music != null)
{
FlxG.sound.music.destroy();
@:nullSafety(Off)
FlxG.sound.music = null;
}

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

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

cancelButton = FunkinSprite.createSparrow(FlxG.width * 0.58, replayButton.y, 'pauseAlt/pauseUI');
cancelButton.animation.addByPrefix('selected', 'bluecancel', 0, false);
cancelButton.animation.appendByPrefix('selected', 'cancelyellow');
cancelButton.animation.play('selected');
Expand Down
Loading