From 80ee46c81dda5331f66aa401435447f22ff187cd Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 21 Mar 2025 09:23:01 +0900 Subject: feat(frontend): show game result in 1v1 watch --- frontend/app/api/schema.d.ts | 2 ++ frontend/app/components/GolfWatchApp.tsx | 1 - .../GolfWatchApps/GolfWatchAppGaming1v1.tsx | 23 +++++++++------- frontend/app/states/watch.ts | 32 ++++++++++++++++++++++ 4 files changed, 47 insertions(+), 11 deletions(-) (limited to 'frontend') diff --git a/frontend/app/api/schema.d.ts b/frontend/app/api/schema.d.ts index 0cace21..6f69292 100644 --- a/frontend/app/api/schema.d.ts +++ b/frontend/app/api/schema.d.ts @@ -201,6 +201,8 @@ export interface components { code: string; /** @example 100 */ score: number | null; + /** @example 946684800 */ + best_score_submitted_at: number | null; status: components["schemas"]["ExecutionStatus"]; }; RankingEntry: { diff --git a/frontend/app/components/GolfWatchApp.tsx b/frontend/app/components/GolfWatchApp.tsx index cfd5e74..492d555 100644 --- a/frontend/app/components/GolfWatchApp.tsx +++ b/frontend/app/components/GolfWatchApp.tsx @@ -138,7 +138,6 @@ export default function GolfWatchApp({ problemTitle={game.problem.title} problemDescription={game.problem.description} sampleCode={game.problem.sample_code} - gameResult={null /* TODO */} /> ) : (
{gameDisplayName}
- {gameResult ? ( + {gameResultKind ? (
- {gameResult === "winA" + {gameResultKind === "winA" ? `勝者 ${playerProfileA.displayName}` - : gameResult === "winB" + : gameResultKind === "winB" ? `勝者 ${playerProfileB.displayName}` : "引き分け"}
diff --git a/frontend/app/states/watch.ts b/frontend/app/states/watch.ts index 8c7faa7..2c255f4 100644 --- a/frontend/app/states/watch.ts +++ b/frontend/app/states/watch.ts @@ -93,3 +93,35 @@ export function calcCodeSize(code: string): number { const utf8Encoded = new TextEncoder().encode(trimmed); return utf8Encoded.length; } + +export type GameResultKind = "winA" | "winB" | "draw"; + +export function checkGameResultKind( + gameStateKind: GameStateKind, + stateA: LatestGameState | null, + stateB: LatestGameState | null, +): GameResultKind | null { + if (gameStateKind !== "finished") { + return null; + } + + const scoreA = stateA?.score; + const scoreB = stateB?.score; + if (scoreA == null && scoreB == null) { + return "draw"; + } + if (scoreA == null) { + return "winB"; + } + if (scoreB == null) { + return "winA"; + } + if (scoreA === scoreB) { + // If score is non-null, state and best_score_submitted_at should also be non-null. + const submittedAtA = stateA!.best_score_submitted_at!; + const submittedAtB = stateB!.best_score_submitted_at!; + return submittedAtA < submittedAtB ? "winA" : "winB"; + } else { + return scoreA < scoreB ? "winA" : "winB"; + } +} -- cgit v1.2.3-70-g09d2