From ed0d4fa9c13c5c9cb9c09483a230ee647d16cea3 Mon Sep 17 00:00:00 2001 From: Terry Hearst Date: Sun, 5 Feb 2023 15:58:56 -0500 Subject: [PATCH] More natual replay saving system --- src/MarbleWorld.hx | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index f543e08d..b10a48e1 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -132,6 +132,7 @@ class MarbleWorld extends Scheduler { // Replay public var replay:Replay; public var isWatching:Bool = false; + public var wasRecording:Bool = false; public var isRecording:Bool = false; // Loading @@ -155,7 +156,7 @@ class MarbleWorld extends Scheduler { this.scene2d = scene2d; this.mission = mission; this.replay = new Replay(mission.path); - this.isRecording = record; + this.isRecording = this.wasRecording = record; } public function init() { @@ -1231,7 +1232,8 @@ class MarbleWorld extends Scheduler { this.finishYaw = this.marble.camera.CameraYaw; this.finishPitch = this.marble.camera.CameraPitch; displayAlert("Congratulations! You've finished!"); - this.schedule(this.timeState.currentAttemptTime + 2, () -> cast showFinishScreen()); + if (!this.isWatching) + this.schedule(this.timeState.currentAttemptTime + 2, () -> cast showFinishScreen()); // Stop the ongoing sounds if (timeTravelSound != null) { timeTravelSound.stop(); @@ -1241,15 +1243,16 @@ class MarbleWorld extends Scheduler { } function showFinishScreen() { + if (this.isWatching) + return 0; var egg:EndGameGui = null; #if js var pointercontainer = js.Browser.document.querySelector("#pointercontainer"); pointercontainer.hidden = false; #end - if (this.isRecording) { + this.schedule(this.timeState.currentAttemptTime + 3, () -> { this.isRecording = false; // Stop recording here - this.saveReplay(); - } + }, "stopRecordingTimeout"); if (Util.isTouchDevice()) { MarbleGame.instance.touchInput.setControlsEnabled(false); } @@ -1257,6 +1260,13 @@ class MarbleWorld extends Scheduler { if (Util.isTouchDevice()) { MarbleGame.instance.touchInput.hideControls(@:privateAccess this.playGui.playGuiCtrl); } + if (this.isRecording) { + this.isRecording = false; // Stop recording here if we haven't already + this.clearScheduleId("stopRecordingTimeout"); + } + if (this.wasRecording) { + this.saveReplay(); + } this.dispose(); var pmg = new PlayMissionGui(); PlayMissionGui.currentSelectionStatic = mission.index + 1; @@ -1266,6 +1276,13 @@ class MarbleWorld extends Scheduler { #end }, (sender) -> { MarbleGame.canvas.popDialog(egg); + if (this.isRecording) { + this.clearScheduleId("stopRecordingTimeout"); + } + if (this.wasRecording) { + this.saveReplay(); + this.isRecording = true; + } this.setCursorLock(true); this.restart(); #if js