다시 보기: 컴퓨터와 한 판·점수 문구 이전 게임도 다시 볼 수 있게(결과 비교를 순위·점수·이유·요약으로)

운영 DB 44판 중 21판이 '다시 볼 수 없어요'였던 원인: 저장 결과의 practice 표시와 새 scoreText 때문에 JSON 전체 비교가 실패.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-11 03:18:54 +09:00
parent 0fe7e27eb2
commit 65a0f34d93
3 changed files with 38 additions and 3 deletions

View File

@@ -41,6 +41,20 @@ function* replaySteps(def: AnyGameDefinition, input: ReplayInput): Generator<Ste
}
}
/**
* Did the rebuilt game end the way it was recorded? Compares the outcome (ranking, scores, reason, summary), not
* labels added around it: the store marks practice games (`practice`), and `scoreText` is display wording that games
* recorded before 2026-10-11 don't have. (Comparing the raw JSON made every practice game and every older scored
* game "not replayable".)
*/
export function sameOutcome(rebuilt: GameResult, stored: GameResult): boolean {
const core = (r: GameResult) => {
const { practice: _p, scoreText: _t, ...rest } = r as GameResult & { practice?: boolean };
return JSON.stringify(rest);
};
return core(rebuilt) === core(stored);
}
/** Final state of a rebuilt game. */
export function rebuildGame(def: AnyGameDefinition, input: ReplayInput): unknown {
let state: unknown;
@@ -233,10 +247,12 @@ export class Replays {
return { ok: false, status: 410, error: '이 게임은 다시 볼 수 없어요.' };
}
// The rebuilt game must end exactly as recorded; otherwise the replay would show a different game.
const result = JSON.parse(g.result_json) as GameResult;
const stored = JSON.parse(g.result_json) as GameResult;
const rebuilt = def.result(built.final);
const matches = g.end_reason === 'void' ? rebuilt === null : JSON.stringify(rebuilt) === g.result_json;
const matches = g.end_reason === 'void' ? rebuilt === null : !!rebuilt && sameOutcome(rebuilt, stored);
if (!matches) return { ok: false, status: 410, error: '이 게임은 다시 볼 수 없어요.' };
// Games recorded before the result screen showed final scores get them from the rebuilt game.
const result: GameResult = rebuilt?.scoreText && !stored.scoreText ? { ...stored, scoreText: rebuilt.scoreText } : stored;
const ids = this.idMap(start.players, seats.map((s) => s.user_id));
const players: Record<string, PublicUser> = {};