Fix several crashes when reaching a game over in minimal mode

This commit is contained in:
EliteMasterEric 2024-03-19 23:25:56 -04:00
parent 4c35b1d74f
commit 566a271a63

View file

@ -97,14 +97,14 @@ class GameOverSubState extends MusicBeatSubState
/** /**
* Reset the game over configuration to the default. * Reset the game over configuration to the default.
*/ */
public static function reset() public static function reset():Void
{ {
animationSuffix = ""; animationSuffix = '';
musicSuffix = ""; musicSuffix = '';
blueBallSuffix = ""; blueBallSuffix = '';
} }
override public function create() override public function create():Void
{ {
if (instance != null) if (instance != null)
{ {
@ -130,6 +130,9 @@ class GameOverSubState extends MusicBeatSubState
// Pluck Boyfriend from the PlayState and place him (in the same position) in the GameOverSubState. // Pluck Boyfriend from the PlayState and place him (in the same position) in the GameOverSubState.
// We can then play the character's `firstDeath` animation. // We can then play the character's `firstDeath` animation.
if (PlayState.instance.isMinimalMode) {}
else
{
boyfriend = PlayState.instance.currentStage.getBoyfriend(true); boyfriend = PlayState.instance.currentStage.getBoyfriend(true);
boyfriend.isDead = true; boyfriend.isDead = true;
add(boyfriend); add(boyfriend);
@ -147,6 +150,7 @@ class GameOverSubState extends MusicBeatSubState
FlxG.camera.target = null; FlxG.camera.target = null;
FlxG.camera.follow(cameraFollowPoint, LOCKON, 0.01); FlxG.camera.follow(cameraFollowPoint, LOCKON, 0.01);
targetCameraZoom = PlayState?.instance?.currentStage?.camZoom * boyfriend.getDeathCameraZoom(); targetCameraZoom = PlayState?.instance?.currentStage?.camZoom * boyfriend.getDeathCameraZoom();
}
// //
// Set up the audio // Set up the audio
@ -164,12 +168,19 @@ class GameOverSubState extends MusicBeatSubState
var hasStartedAnimation:Bool = false; var hasStartedAnimation:Bool = false;
override function update(elapsed:Float) override function update(elapsed:Float):Void
{ {
if (!hasStartedAnimation) if (!hasStartedAnimation)
{ {
hasStartedAnimation = true; hasStartedAnimation = true;
if (PlayState.instance.isMinimalMode)
{
// Play the "blue balled" sound. May play a variant if one has been assigned.
playBlueBalledSFX();
}
else
{
if (boyfriend.hasAnimation('fakeoutDeath') && FlxG.random.bool((1 / 4096) * 100)) if (boyfriend.hasAnimation('fakeoutDeath') && FlxG.random.bool((1 / 4096) * 100))
{ {
boyfriend.playAnimation('fakeoutDeath', true, false); boyfriend.playAnimation('fakeoutDeath', true, false);
@ -181,6 +192,7 @@ class GameOverSubState extends MusicBeatSubState
playBlueBalledSFX(); playBlueBalledSFX();
} }
} }
}
// Smoothly lerp the camera // Smoothly lerp the camera
FlxG.camera.zoom = MathUtil.smoothLerp(FlxG.camera.zoom, targetCameraZoom, elapsed, CAMERA_ZOOM_DURATION); FlxG.camera.zoom = MathUtil.smoothLerp(FlxG.camera.zoom, targetCameraZoom, elapsed, CAMERA_ZOOM_DURATION);
@ -240,13 +252,19 @@ class GameOverSubState extends MusicBeatSubState
Conductor.instance.update(gameOverMusic.time); Conductor.instance.update(gameOverMusic.time);
} }
else else
{
if (PlayState.instance.isMinimalMode)
{
// startDeathMusic(1.0, false);
}
else
{ {
// Music hasn't started yet. // Music hasn't started yet.
switch (PlayStatePlaylist.campaignId) switch (PlayStatePlaylist.campaignId)
{ {
// TODO: Make the behavior for playing Jeff's voicelines generic or un-hardcoded. // TODO: Make the behavior for playing Jeff's voicelines generic or un-hardcoded.
// This will simplify the class and make it easier for mods to add death quotes. // This will simplify the class and make it easier for mods to add death quotes.
case "week7": case 'week7':
if (boyfriend.getCurrentAnimation().startsWith('firstDeath') && boyfriend.isAnimationFinished() && !playingJeffQuote) if (boyfriend.getCurrentAnimation().startsWith('firstDeath') && boyfriend.isAnimationFinished() && !playingJeffQuote)
{ {
playingJeffQuote = true; playingJeffQuote = true;
@ -264,6 +282,7 @@ class GameOverSubState extends MusicBeatSubState
} }
} }
} }
}
// Start death music before firstDeath gets replaced // Start death music before firstDeath gets replaced
super.update(elapsed); super.update(elapsed);
@ -279,7 +298,11 @@ class GameOverSubState extends MusicBeatSubState
isEnding = true; isEnding = true;
startDeathMusic(1.0, true); // isEnding changes this function's behavior. startDeathMusic(1.0, true); // isEnding changes this function's behavior.
if (PlayState.instance.isMinimalMode) {}
else
{
boyfriend.playAnimation('deathConfirm' + animationSuffix, true); boyfriend.playAnimation('deathConfirm' + animationSuffix, true);
}
// After the animation finishes... // After the animation finishes...
new FlxTimer().start(0.7, function(tmr:FlxTimer) { new FlxTimer().start(0.7, function(tmr:FlxTimer) {
@ -289,10 +312,14 @@ class GameOverSubState extends MusicBeatSubState
FlxG.camera.fade(FlxColor.BLACK, 1, true, null, true); FlxG.camera.fade(FlxColor.BLACK, 1, true, null, true);
PlayState.instance.needsReset = true; PlayState.instance.needsReset = true;
if (PlayState.instance.isMinimalMode) {}
else
{
// Readd Boyfriend to the stage. // Readd Boyfriend to the stage.
boyfriend.isDead = false; boyfriend.isDead = false;
remove(boyfriend); remove(boyfriend);
PlayState.instance.currentStage.addCharacter(boyfriend, BF); PlayState.instance.currentStage.addCharacter(boyfriend, BF);
}
// Snap reset the camera which may have changed because of the player character data. // Snap reset the camera which may have changed because of the player character data.
resetCameraZoom(); resetCameraZoom();