Files
WT-Offline/packages/local-service/src/web-ui/web-ui-service.ts
T
N0VAN0M4LY 9cf7df5299 feat(store): open store pages in-game and centralize economy tuning
Use the native embedded browser and pass the game language through
auto_local. Share web assets and extract vehicle icons, flags, and
localized names from the installed client.

Load and validate per-domain JSONC tuning and merge local overrides
by field. Use official store USD prices for GJN products, keep GJN
balances in integer cents, and split the native and web store
handlers by protocol. Multi-vehicle packs are still listed as single
vehicles at this point.

Type checking, patch checks, and configuration loading passed.
In-game acceptance is pending.
2026-11-25 11:01:05 +08:00

45 lines
2.1 KiB
TypeScript

/**
* Files shared by the local web pages, under /_wto/ui/:
* common.css, common.js layout and helpers both pages load
* labels.json the game's country and vehicle type names (ui-labels dataset)
* vehicle/<vehicle>.svg the game's silhouette icon of a vehicle (web-icons dataset)
* flag/<country>.svg the game's country flag (web-icons dataset)
* Icons and names come from the player's game files at start-up; nothing of Gaijin's is shipped.
*/
import type { WebIcons } from '../game-data/datasets/web-icons.ts';
import type { UiLabels } from '../game-data/datasets/ui-labels.ts';
import type { Service, ServiceRequest, ServiceResponse } from '../server/exchange.ts';
import { contentResponse, createStaticWebSite, notFound } from './web-helpers.ts';
const PREFIX = '/_wto/ui/';
const SHARED_FILES = createStaticWebSite(new URL('./web/', import.meta.url), ['common.css', 'common.js']);
const ICON_PATH = /^(vehicle|flag)\/([^/]+)\.svg$/;
export class WebUiService implements Service {
readonly name = 'web-ui';
readonly #icons: WebIcons;
readonly #labels: string;
constructor(icons: WebIcons, labels: UiLabels) {
this.#icons = icons;
this.#labels = JSON.stringify(labels);
}
accepts(request: ServiceRequest): boolean {
return request.originalHost === undefined && request.method === 'GET' && request.path.startsWith(PREFIX);
}
handle(request: ServiceRequest): ServiceResponse {
const subPath = request.path.slice(PREFIX.length);
if (subPath === 'labels.json') return contentResponse(subPath, this.#labels, 'web ui: labels');
const icon = ICON_PATH.exec(subPath);
if (icon) {
const [, kind, name] = icon;
const table = kind === 'vehicle' ? this.#icons.vehicles : this.#icons.flags;
const svg = Object.hasOwn(table, name!) ? table[name!] : undefined;
return svg ? contentResponse(subPath, svg, `web ui: ${kind} icon`) : notFound(`web ui: no ${kind} icon ${name}`);
}
return SHARED_FILES.serve(subPath, 'web ui') ?? notFound(`web ui 404: ${subPath}`);
}
}