mirror of
https://github.com/sndrec/WebMonkeyBall.git
synced 2026-02-03 10:13:33 +00:00
replays!
This commit is contained in:
20
src/game.ts
20
src/game.ts
@@ -342,6 +342,7 @@ export class Game {
|
||||
public autoRecordInputs: boolean;
|
||||
public inputStartTick: number;
|
||||
public replayInputStartTick: number | null;
|
||||
public replayAutoFastForward: boolean;
|
||||
|
||||
constructor({
|
||||
hud,
|
||||
@@ -440,6 +441,7 @@ export class Game {
|
||||
this.autoRecordInputs = true;
|
||||
this.inputStartTick = 0;
|
||||
this.replayInputStartTick = null;
|
||||
this.replayAutoFastForward = false;
|
||||
}
|
||||
|
||||
setGameSource(source: GameSource) {
|
||||
@@ -464,10 +466,12 @@ export class Game {
|
||||
if (enabled) {
|
||||
this.inputRecord = null;
|
||||
this.replayInputStartTick = 0;
|
||||
this.replayAutoFastForward = true;
|
||||
} else {
|
||||
this.inputFeed = null;
|
||||
this.inputFeedIndex = 0;
|
||||
this.replayInputStartTick = null;
|
||||
this.replayAutoFastForward = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1308,6 +1312,16 @@ export class Game {
|
||||
}
|
||||
|
||||
this.resetBallForStage({ withIntro: true });
|
||||
if (this.replayInputStartTick !== null) {
|
||||
const startTick = Math.max(0, this.replayInputStartTick);
|
||||
this.introTotalFrames = startTick;
|
||||
this.introTimerFrames = startTick;
|
||||
if (this.ball) {
|
||||
this.cameraController?.initForStage(this.ball, this.ball.startRotY, this.stageRuntime);
|
||||
}
|
||||
this.replayAutoFastForward = true;
|
||||
this.setFixedTickMode(true, 1);
|
||||
}
|
||||
|
||||
void this.audio?.playMusicForStage(stageId, this.gameSource);
|
||||
this.statusText = '';
|
||||
@@ -2023,6 +2037,12 @@ export class Game {
|
||||
this.simPerf.tickCount += 1;
|
||||
}
|
||||
this.simTick += 1;
|
||||
if (this.replayAutoFastForward && this.replayInputStartTick !== null) {
|
||||
if (this.simTick >= this.replayInputStartTick) {
|
||||
this.replayAutoFastForward = false;
|
||||
this.setFixedTickMode(false, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.simPerf.enabled && this.simPerf.tickCount >= this.simPerf.logEvery) {
|
||||
|
||||
@@ -895,6 +895,11 @@ async function startReplay(replay: ReplayData) {
|
||||
hudStatus.textContent = '';
|
||||
}
|
||||
game.setReplayMode(true, true);
|
||||
activeGameSource = replay.gameSource;
|
||||
if (gameSourceSelect) {
|
||||
gameSourceSelect.value = replay.gameSource;
|
||||
}
|
||||
updateGameSourceFields();
|
||||
game.setGameSource(replay.gameSource);
|
||||
game.stageBasePath = getStageBasePath(replay.gameSource);
|
||||
currentSmb2LikeMode = null;
|
||||
@@ -913,6 +918,7 @@ async function startReplay(replay: ReplayData) {
|
||||
while (game.simTick < game.replayInputStartTick) {
|
||||
game.update(game.fixedStep);
|
||||
}
|
||||
game.replayAutoFastForward = false;
|
||||
game.setFixedTickMode(false, 1);
|
||||
setReplayStatus(`Replay loaded (stage ${replay.stageId})`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user