Add catalogue filters, item detail views, and purchase and resale actions. Resolve images from the player's asset pack, public image URLs, or local game data. Add a utility for creating the optional local asset pack. Type checking and JavaScript syntax checks passed. Embedded browser appearance and in-game behavior still need acceptance.
58 lines
2.5 KiB
TypeScript
58 lines
2.5 KiB
TypeScript
/**
|
|
* Dataset: the game's own SVG icons that the local web pages (store and marketplace, shown in
|
|
* the in-game browser; implementation notes) display, taken from the player's
|
|
* ui/atlases.vromfs.bin at runtime. The dataset uses these entries.
|
|
* gameuiskin/<vehicle>_ico.svg the tech-tree silhouette of a vehicle
|
|
* gameuiskin/<country>.svg a country flag (country_usa, ...)
|
|
*
|
|
* All 3349 vehicle icons together are about 26 MB, so only premium and store/market vehicles
|
|
* are kept: gift vehicles (wpcost.blk gift:t), Golden Eagle premium vehicles (wpcost.blk
|
|
* costGold > 0, used by starter packs and custom multi-vehicle packs), and marketplace
|
|
* vehicles (shop.blk marketplaceItemdefId).
|
|
*/
|
|
import { numberField, stringField } from './blk-fields.ts';
|
|
import type { Dataset } from './dataset.ts';
|
|
import { shopCountryNames, shopEntriesByName } from './shop-tree.ts';
|
|
|
|
const ATLASES = 'ui/atlases.vromfs.bin';
|
|
const VEHICLE_ECONOMY = 'config/wpcost.blk';
|
|
const ICON_FOLDER = 'gameuiskin/';
|
|
|
|
export interface WebIcons {
|
|
/** Vehicle name -> SVG text. */
|
|
readonly vehicles: Readonly<Record<string, string>>;
|
|
/** Country (country_usa, ...) -> SVG text. */
|
|
readonly flags: Readonly<Record<string, string>>;
|
|
}
|
|
|
|
export const webIcons: Dataset<WebIcons> = {
|
|
id: 'web-icons',
|
|
version: 3,
|
|
extract: (source) => {
|
|
// Archive paths in ui/atlases.vromfs.bin are lowercase, whereas unit IDs in wpcost.blk
|
|
// mix uppercase and lowercase (e.g. germ_pzkpfw_VI_ausf_h1_tiger_east, ussr_t_26E).
|
|
const byLowerPath = new Map(source.listFiles(ATLASES).map((path) => [path.toLowerCase(), path]));
|
|
const readIcon = (name: string): string | undefined => {
|
|
const actualPath = byLowerPath.get(`${ICON_FOLDER}${name}.svg`.toLowerCase());
|
|
return actualPath ? source.readText(ATLASES, actualPath) : undefined;
|
|
};
|
|
|
|
const shopEntries = shopEntriesByName(source);
|
|
const vehicles: Record<string, string> = {};
|
|
for (const vehicle of source.readBlk('char.vromfs.bin', VEHICLE_ECONOMY).blocks) {
|
|
const needIcon = stringField(vehicle, 'gift') !== undefined
|
|
|| (numberField(vehicle, 'costGold') ?? 0) > 0
|
|
|| numberField(shopEntries.get(vehicle.name), 'marketplaceItemdefId') !== undefined;
|
|
const icon = needIcon ? readIcon(`${vehicle.name}_ico`) : undefined;
|
|
if (icon) vehicles[vehicle.name] = icon;
|
|
}
|
|
|
|
const flags: Record<string, string> = {};
|
|
for (const country of shopCountryNames(source)) {
|
|
const flag = readIcon(country);
|
|
if (flag) flags[country] = flag;
|
|
}
|
|
return { vehicles, flags };
|
|
},
|
|
};
|