From 0f1ac5efb669db63087e50b6c96b52e10e241e78 Mon Sep 17 00:00:00 2001 From: VariableVince <24507472+VariableVince@users.noreply.github.com> Date: Thu, 19 Feb 2026 19:41:07 +0100 Subject: [PATCH] Replace literals by enums in 4 files --- .../leaderboard/LeaderboardPlayerList.ts | 27 ++++++++++--------- src/core/ApiSchemas.ts | 10 +++++-- src/core/Util.ts | 4 +-- src/server/Worker.ts | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/client/components/leaderboard/LeaderboardPlayerList.ts b/src/client/components/leaderboard/LeaderboardPlayerList.ts index 1ed4822cb..cf96e9af2 100644 --- a/src/client/components/leaderboard/LeaderboardPlayerList.ts +++ b/src/client/components/leaderboard/LeaderboardPlayerList.ts @@ -1,6 +1,7 @@ import { virtualize } from "@lit-labs/virtualizer/virtualize.js"; import { html, LitElement } from "lit"; import { customElement, query, state } from "lit/decorators.js"; +import { RankedType } from "src/core/game/Game"; import { PlayerLeaderboardEntry } from "../../../core/ApiSchemas"; import { fetchPlayerLeaderboard, getUserMe } from "../../Api"; import { translateText } from "../../Utils"; @@ -68,19 +69,19 @@ export class LeaderboardPlayerList extends LitElement { return; } - const nextPlayers: PlayerLeaderboardEntry[] = result["1v1"].map( - (entry) => ({ - rank: entry.rank, - playerId: entry.public_id, - username: entry.username, - clanTag: entry.clanTag ?? undefined, - elo: entry.elo, - games: entry.total, - wins: entry.wins, - losses: entry.losses, - winRate: entry.total > 0 ? entry.wins / entry.total : 0, - }), - ); + const nextPlayers: PlayerLeaderboardEntry[] = result[ + RankedType.OneVOne + ].map((entry) => ({ + rank: entry.rank, + playerId: entry.public_id, + username: entry.username, + clanTag: entry.clanTag ?? undefined, + elo: entry.elo, + games: entry.total, + wins: entry.wins, + losses: entry.losses, + winRate: entry.total > 0 ? entry.wins / entry.total : 0, + })); const receivedCount = nextPlayers.length; if (reset) { diff --git a/src/core/ApiSchemas.ts b/src/core/ApiSchemas.ts index 0e7bd5639..c3ab186e7 100644 --- a/src/core/ApiSchemas.ts +++ b/src/core/ApiSchemas.ts @@ -1,7 +1,13 @@ import { z } from "zod"; import { base64urlToUuid } from "./Base64"; import { BigIntStringSchema, PlayerStatsSchema } from "./StatsSchemas"; -import { Difficulty, GameMapType, GameMode, GameType } from "./game/Game"; +import { + Difficulty, + GameMapType, + GameMode, + GameType, + RankedType, +} from "./game/Game"; export const RefreshResponseSchema = z.object({ token: z.string(), @@ -176,7 +182,7 @@ export type RankedLeaderboardEntry = z.infer< >; export const RankedLeaderboardResponseSchema = z.object({ - "1v1": RankedLeaderboardEntrySchema.array(), + [RankedType.OneVOne]: RankedLeaderboardEntrySchema.array(), }); export type RankedLeaderboardResponse = z.infer< typeof RankedLeaderboardResponseSchema diff --git a/src/core/Util.ts b/src/core/Util.ts index a79dda1a8..b4f889d90 100644 --- a/src/core/Util.ts +++ b/src/core/Util.ts @@ -1,6 +1,6 @@ import DOMPurify from "dompurify"; import { customAlphabet } from "nanoid"; -import { Cell, Unit } from "./game/Game"; +import { Cell, PlayerType, Unit } from "./game/Game"; import { GameMap, TileRef } from "./game/GameMap"; import { GameConfig, @@ -294,7 +294,7 @@ export function createRandomName( playerType: string, ): string | null { let randomName: string | null = null; - if (playerType === "HUMAN") { + if (playerType === PlayerType.Human) { const hash = simpleHash(name); const prefixIndex = hash % BOT_NAME_PREFIXES.length; const suffixIndex = diff --git a/src/server/Worker.ts b/src/server/Worker.ts index f20b8986b..f3a5455e8 100644 --- a/src/server/Worker.ts +++ b/src/server/Worker.ts @@ -185,7 +185,7 @@ export async function startWorker() { const game = gm.createGame(id, gc, creatorPersistentID); log.info( - `Worker ${workerId}: IP ${ipAnonymize(clientIP)} creating ${game.isPublic() ? "Public" : "Private"}${gc?.gameMode ? ` ${gc.gameMode}` : ""} game with id ${id}${creatorPersistentID ? `, creator: ${creatorPersistentID.substring(0, 8)}...` : ""}`, + `Worker ${workerId}: IP ${ipAnonymize(clientIP)} creating ${game.isPublic() ? GameType.Public : GameType.Private}${gc?.gameMode ? ` ${gc.gameMode}` : ""} game with id ${id}${creatorPersistentID ? `, creator: ${creatorPersistentID.substring(0, 8)}...` : ""}`, ); res.json(game.gameInfo()); });