Skip to content

Commit 60fca87

Browse files
committed
evan comments
1 parent a6acb12 commit 60fca87

8 files changed

Lines changed: 26 additions & 38 deletions

File tree

src/client/GameInfoModal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class GameInfoModal extends LitElement {
180180
try {
181181
const mapType = gameMap as GameMapType;
182182
const data = terrainMapFileLoader.getMapData(mapType);
183-
this.mapImage = await data.webpPath();
183+
this.mapImage = data.webpPath;
184184
} catch (error) {
185185
console.error("Failed to load map image:", error);
186186
}

src/client/GameModeSelector.ts

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ import {
1010
Trios,
1111
} from "../core/game/Game";
1212
import { PublicGameInfo, PublicGames } from "../core/Schemas";
13+
import { HostLobbyModal } from "./HostLobbyModal";
14+
import { JoinLobbyModal } from "./JoinLobbyModal";
1315
import { PublicLobbySocket } from "./LobbySocket";
1416
import { JoinLobbyEvent } from "./Main";
17+
import { SinglePlayerModal } from "./SinglePlayerModal";
1518
import { terrainMapFileLoader } from "./TerrainMapFileLoader";
16-
import { renderDuration, translateText } from "./Utils";
19+
import { getMapName, renderDuration, translateText } from "./Utils";
1720

1821
const CARD_BG = "bg-[color-mix(in_oklab,var(--frenchBlue)_70%,black)]";
1922

@@ -145,31 +148,24 @@ export class GameModeSelector extends LitElement {
145148

146149
private openRankedMenu = () => {
147150
if (!this.validateUsername()) return;
148-
149-
const modal = document.getElementById("page-ranked") as any;
150-
if (window.showPage) {
151-
window.showPage("page-ranked");
152-
} else if (modal) {
153-
document.getElementById("page-play")?.classList.add("hidden");
154-
modal.classList.remove("hidden");
155-
modal.classList.add("block");
156-
}
157-
modal?.open?.();
151+
window.showPage?.("page-ranked");
158152
};
159153

160154
private openSinglePlayerModal = () => {
161155
if (!this.validateUsername()) return;
162-
(document.querySelector("single-player-modal") as any)?.open();
156+
(
157+
document.querySelector("single-player-modal") as SinglePlayerModal
158+
)?.open();
163159
};
164160

165161
private openHostLobby = () => {
166162
if (!this.validateUsername()) return;
167-
(document.querySelector("host-lobby-modal") as any)?.open();
163+
(document.querySelector("host-lobby-modal") as HostLobbyModal)?.open();
168164
};
169165

170166
private openJoinLobby = () => {
171167
if (!this.validateUsername()) return;
172-
(document.querySelector("join-lobby-modal") as any)?.open();
168+
(document.querySelector("join-lobby-modal") as JoinLobbyModal)?.open();
173169
};
174170

175171
private renderSmallActionCard(title: string, onClick: () => void) {
@@ -188,15 +184,11 @@ export class GameModeSelector extends LitElement {
188184
titleContent: string | TemplateResult,
189185
) {
190186
const mapType = lobby.gameConfig!.gameMap as GameMapType;
191-
const mapImageSrc = terrainMapFileLoader.getMapData(mapType).webpPathSync();
192-
// TODO: plus or minus
187+
const mapImageSrc = terrainMapFileLoader.getMapData(mapType).webpPath;
193188
const start = lobby.startsAt - this.timeOffset;
194189
const timeRemaining = Math.max(0, Math.floor((start - Date.now()) / 1000));
195190
const timeDisplay = renderDuration(timeRemaining);
196-
const gameMap = lobby.gameConfig?.gameMap;
197-
const mapName = gameMap
198-
? translateText(`map.${gameMap.toLowerCase().replace(/[\s.]+/g, "")}`)
199-
: null;
191+
const mapName = getMapName(lobby.gameConfig?.gameMap);
200192

201193
const modifierLabels = this.getModifierLabels(
202194
lobby.gameConfig?.publicGameModifiers,
@@ -215,7 +207,7 @@ export class GameModeSelector extends LitElement {
215207
${mapImageSrc
216208
? html`<img
217209
src="${mapImageSrc}"
218-
alt="${mapName ?? gameMap ?? "map"}"
210+
alt="${mapName ?? lobby.gameConfig?.gameMap ?? "map"}"
219211
draggable="false"
220212
class="absolute inset-0 w-full h-full object-contain object-center scale-[1.05] pointer-events-none"
221213
/>`
@@ -288,10 +280,6 @@ export class GameModeSelector extends LitElement {
288280
);
289281
}
290282

291-
private getLobbyTitle(lobby: PublicGameInfo): string {
292-
return this.getBaseModeTitle(lobby);
293-
}
294-
295283
private getModifierLabels(mods: PublicGameModifiers | undefined): string[] {
296284
if (!mods) return [];
297285
return [
@@ -302,7 +290,7 @@ export class GameModeSelector extends LitElement {
302290
].filter((x): x is string => !!x);
303291
}
304292

305-
private getBaseModeTitle(lobby: PublicGameInfo): string {
293+
private getLobbyTitle(lobby: PublicGameInfo): string {
306294
const config = lobby.gameConfig!;
307295
if (config.gameMode === GameMode.FFA) {
308296
return translateText("game_mode.ffa");

src/client/JoinLobbyModal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { customElement, property, query, state } from "lit/decorators.js";
33
import {
44
getActiveModifiers,
55
getGameModeLabel,
6-
normaliseMapKey,
6+
getMapName,
77
renderDuration,
88
renderNumber,
99
translateText,
@@ -419,7 +419,7 @@ export class JoinLobbyModal extends BaseModal {
419419
if (!this.gameConfig) return html``;
420420

421421
const c = this.gameConfig;
422-
const mapName = translateText("map." + normaliseMapKey(c.gameMap));
422+
const mapName = getMapName(c.gameMap);
423423
const modeName = getGameModeLabel(c);
424424
const modifiers = getActiveModifiers(c.publicGameModifiers);
425425

src/client/Utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export function normaliseMapKey(mapName: string): string {
1717
return mapName.toLowerCase().replace(/[\s.]+/g, "");
1818
}
1919

20+
export function getMapName(mapName: string | undefined): string | null {
21+
if (!mapName) return null;
22+
return translateText(`map.${normaliseMapKey(mapName)}`);
23+
}
24+
2025
/**
2126
* Returns a display label for the game mode (e.g. "FFA", "4 Teams", "Duos").
2227
*/

src/client/components/map/MapDisplay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class MapDisplay extends LitElement {
5050
this.isLoading = true;
5151
const mapValue = GameMapType[this.mapKey as keyof typeof GameMapType];
5252
const data = terrainMapFileLoader.getMapData(mapValue);
53-
this.mapWebpPath = await data.webpPath();
53+
this.mapWebpPath = data.webpPath;
5454
const manifest = await data.manifest();
5555
this.mapName = manifest.name;
5656
this.hasNations =

src/core/game/BinaryLoaderGameMapLoader.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ export class BinaryLoaderGameMapLoader implements GameMapLoader {
5454
return res.json() as Promise<MapManifest>;
5555
}),
5656
),
57-
webpPathSync: () => `${mapBasePath}/thumbnail.webp`,
58-
webpPath: this.createLazyLoader(() =>
59-
Promise.resolve(`${mapBasePath}/thumbnail.webp`),
60-
),
57+
webpPath: `${mapBasePath}/thumbnail.webp`,
6158
} satisfies MapData;
6259

6360
this.maps.set(map, mapData);

src/core/game/FetchGameMapLoader.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ export class FetchGameMapLoader implements GameMapLoader {
3131
map4xBin: () => this.loadBinaryFromUrl(this.url(fileName, "map4x.bin")),
3232
map16xBin: () => this.loadBinaryFromUrl(this.url(fileName, "map16x.bin")),
3333
manifest: () => this.loadJsonFromUrl(this.url(fileName, "manifest.json")),
34-
webpPathSync: () => this.url(fileName, "thumbnail.webp"),
35-
webpPath: async () => this.url(fileName, "thumbnail.webp"),
34+
webpPath: this.url(fileName, "thumbnail.webp"),
3635
} satisfies MapData;
3736

3837
this.maps.set(map, mapData);

src/core/game/GameMapLoader.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ export interface MapData {
1010
map4xBin: () => Promise<Uint8Array>;
1111
map16xBin: () => Promise<Uint8Array>;
1212
manifest: () => Promise<MapManifest>;
13-
webpPathSync: () => string;
14-
webpPath: () => Promise<string>;
13+
webpPath: string;
1514
}

0 commit comments

Comments
 (0)