Files
OpenFrontIO/src/core/game/BinaryLoaderGameMapLoader.ts
T
Ryan 70f2abb181 Homepage update & add 3 public lobbies (#3191)
## Description:

Update UI 
check https://homepageupdate.openfront.dev/ 

Improved mobile UI (now fills whole screen for all modals) e.g.:
<img width="432" height="852" alt="image"
src="https://github.com/user-attachments/assets/56de40af-4137-4c57-96b7-3910c9a665b8"
/>

Converted PublicLobby to be "GameModeSelector" to get a nicer 4x4 grid
div, where <GameModeSelector> now handles all the username validation
now (removed redundant code from modals such as matchmaking) also fixed
a bug where someone could have "[XX] X" as thier username (when the
minimum should be 3 chars for their name)

Now visually displays the 3 lobbies ffa/team/special (which is a
continuation from the work done in: #3196 )
<img width="818" height="563" alt="image"
src="https://github.com/user-attachments/assets/a15cd31b-6061-4fb8-83ee-ffde6225cfa7"
/>

updated the background:
<img width="1919" height="807" alt="image"
src="https://github.com/user-attachments/assets/358a7434-51b8-4540-baf2-d1be05053c44"
/>



slightly updated the glassy-look to be less glassy:
<img width="825" height="729" alt="image"
src="https://github.com/user-attachments/assets/1801871b-bbf8-43db-ac53-489337ae80a5"
/>



## 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:

w.o.n
2026-02-18 23:11:01 -06:00

64 lines
1.8 KiB
TypeScript

import { GameMapType } from "./Game";
import { GameMapLoader, MapData } from "./GameMapLoader";
import { MapManifest } from "./TerrainMapLoader";
export class BinaryLoaderGameMapLoader implements GameMapLoader {
private maps: Map<GameMapType, MapData>;
constructor() {
this.maps = new Map<GameMapType, MapData>();
}
private createLazyLoader<T>(importFn: () => Promise<T>): () => Promise<T> {
let cache: Promise<T> | null = null;
return () => {
cache ??= importFn();
return cache;
};
}
getMapData(map: GameMapType): MapData {
const cachedMap = this.maps.get(map);
if (cachedMap) {
return cachedMap;
}
const key = Object.keys(GameMapType).find(
(k) => GameMapType[k as keyof typeof GameMapType] === map,
);
const fileName = key?.toLowerCase();
const loadBinary = (url: string) =>
fetch(url)
.then((res) => {
if (!res.ok) throw new Error(`Failed to load ${url}`);
return res.arrayBuffer();
})
.then((buf) => new Uint8Array(buf));
const mapBasePath = `/maps/${fileName}`;
const mapData = {
mapBin: this.createLazyLoader(() => loadBinary(`${mapBasePath}/map.bin`)),
map4xBin: this.createLazyLoader(() =>
loadBinary(`${mapBasePath}/map4x.bin`),
),
map16xBin: this.createLazyLoader(() =>
loadBinary(`${mapBasePath}/map16x.bin`),
),
manifest: this.createLazyLoader(() =>
fetch(`${mapBasePath}/manifest.json`).then((res) => {
if (!res.ok) {
throw new Error(`Failed to load ${mapBasePath}/manifest.json`);
}
return res.json() as Promise<MapManifest>;
}),
),
webpPath: `${mapBasePath}/thumbnail.webp`,
} satisfies MapData;
this.maps.set(map, mapData);
return mapData;
}
}