Skip to content

Commit

Permalink
feat: Show end of run comparison after saving the new run
Browse files Browse the repository at this point in the history
Showing the end of run menu on timer finish might be preferable,
but the timer state change event doesn't include the run time needed
to generate the final zone split.
  • Loading branch information
Panzerhandschuh committed Dec 28, 2024
1 parent 91cfd35 commit 2a33530
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 17 additions & 15 deletions scripts/pages/end-of-run/end-of-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,13 @@ class EndOfRunHandler {
selectedSplit: Timer.ComparisonSplit;

constructor() {
// TODO: I'm using undefined rather than null here, which should be right for datamap usage (mixing null and
// undefined can be confusing, using `undefined` when unsure)
// $.RegisterForUnhandledEvent('EndOfRun_CompareRuns', (baseRun, compareRun) =>
// this.setComparison(baseRun, compareRun)
// );
$.RegisterForUnhandledEvent('EndOfRun_Show', (reason) => this.showNewEndOfRun(reason));
$.RegisterForUnhandledEvent('EndOfRun_Result_RunUpload', (uploaded, cosXP, rankXP, lvlGain) =>
this.updateRunUploadStatus(uploaded, cosXP, rankXP, lvlGain)
);
$.RegisterForUnhandledEvent('EndOfRun_Result_RunSave', (saved) => this.updateRunSavedStatus(saved));
$.RegisterForUnhandledEvent('EndOfRun_Result_RunSave', (saved, run) => this.updateRunSavedStatus(saved, run));
$.RegisterForUnhandledEvent('Leaderboards_MapDataSet', (isOfficial) => this.initOnMapLoad(isOfficial));
}

/** Set the current base run and comparison run */
setComparison(base: Timer.RunMetadata, comparison?: Timer.RunMetadata) {
this.baseRun = base;
this.comparisonRun = comparison;
}

/** Hides the end of run panel, when a new map is loaded. */
initOnMapLoad(isOfficial: boolean) {
this.panels.uploadStatus.SetHasClass('hide', !isOfficial);
Expand Down Expand Up @@ -106,7 +94,17 @@ class EndOfRunHandler {
}
}

updateRunSavedStatus(saved: boolean) {
updateRunSavedStatus(saved: boolean, run: Timer.RunMetadata) {
const observedStatus = MomentumTimerAPI.GetObservedTimerStatus();
if (observedStatus.trackId.type !== run.trackId.type || observedStatus.trackId.number !== run.trackId.number) {
return;
}

this.baseRun = run;
this.comparisonRun = RunComparisonsAPI.GetComparisonRun();

this.showNewEndOfRun(Timer.EndOfRunShowReason.PLAYER_FINISHED_RUN);

this.updateRunStatusIndicator(
saved ? Timer.RunStatusStates.SUCCESS : Timer.RunStatusStates.ERROR,
Timer.RunStatusTypes.SAVE
Expand Down Expand Up @@ -177,7 +175,11 @@ class EndOfRunHandler {
this.panels.cp.SetDialogVariableFloat('run_time', this.baseRun.runTime);

// If we have a comparison, make the full stats, otherwise just simple page without graph
if (this.comparisonRun) {
if (
this.comparisonRun &&
this.comparisonRun.trackId.type === this.baseRun.trackId.type &&
this.comparisonRun.trackId.number === this.baseRun.trackId.number
) {
this.setComparisionStats();
} else {
this.setSingleRunStats();
Expand Down
2 changes: 1 addition & 1 deletion scripts/types-mom/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ interface GlobalEventNameMap {
EndOfRun_Hide: () => void;

/** Fired when the replay recording finishes and passes whether writing the file was successful */
EndOfRun_Result_RunSave: (saved: boolean) => void;
EndOfRun_Result_RunSave: (saved: boolean, run: RunMetadata) => void;

/** Fired when the replay recording finishes and passes whether writing the file was successful */
EndOfRun_Result_RunUpload: (uploaded: boolean, cosXP: number, rankXP: number, lvlGain: number) => void;
Expand Down

0 comments on commit 2a33530

Please sign in to comment.