Cleanup: Replace literals by enums (#3252)

## Description:

Some literals were present that could/should have been enums. Replaced
them.

For Util.ts > createRandomName, also changed type of parameter
playerType from string to PlayerType. All callers already send it this
type.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

tryout33
This commit is contained in:
VariableVince
2026-02-19 23:58:07 +01:00
committed by GitHub
parent fcf45db672
commit c235debb57
4 changed files with 26 additions and 19 deletions
@@ -2,6 +2,7 @@ import { virtualize } from "@lit-labs/virtualizer/virtualize.js";
import { html, LitElement } from "lit";
import { customElement, query, state } from "lit/decorators.js";
import { PlayerLeaderboardEntry } from "../../../core/ApiSchemas";
import { RankedType } from "../../../core/game/Game";
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) {
+8 -2
View File
@@ -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
+3 -3
View File
@@ -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,
@@ -291,10 +291,10 @@ export function withinInt(num: bigint, min: bigint, max: bigint): bigint {
export function createRandomName(
name: string,
playerType: string,
playerType: PlayerType,
): 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 =
+1 -1
View File
@@ -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());
});