From ec2d3ffbc4c878dd5ee80172ccdc9b0b16eeab00 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:41:35 +0800 Subject: [PATCH] Fix vehicle icon lookup and default web account selection Match archive paths without regard to case and include Golden Eagle vehicles in icon extraction. Default read-only page state to the current in-game account. Keep web mutations gated on an explicit account ID. Type checking and local icon and account selection checks passed. In-game acceptance is pending. --- .../src/accounts/account-store.ts | 11 +++++++++ .../src/game-data/datasets/web-icons.ts | 22 ++++++++++------- .../local-service/src/inventory/web/app.js | 24 ++++++++++++------- packages/local-service/src/store/web/app.js | 9 ++++++- .../local-service/src/web-ui/web-helpers.ts | 5 ++-- .../local-service/src/web-ui/web/common.js | 16 +++++++++---- 6 files changed, 63 insertions(+), 24 deletions(-) diff --git a/packages/local-service/src/accounts/account-store.ts b/packages/local-service/src/accounts/account-store.ts index 313f2d3..39331d5 100644 --- a/packages/local-service/src/accounts/account-store.ts +++ b/packages/local-service/src/accounts/account-store.ts @@ -35,6 +35,7 @@ const NICK_MAX_LENGTH = 16; export class AccountStore { readonly #path: string; #file: AccountFile; + #lastSignedInUserId: string | undefined; constructor(dataFolder: string) { this.#path = join(dataFolder, 'accounts.json'); @@ -45,6 +46,7 @@ export class AccountStore { const existing = this.#find(login); if (existing) { if (!verifyPassword(password, existing.passwordHash)) return { kind: 'wrong-password' }; + this.#lastSignedInUserId = existing.userId; return { kind: 'signed-in', account: existing, registered: false }; } @@ -52,9 +54,18 @@ export class AccountStore { const account: Account = { login, userId, nick: nickFromLogin(login, userId), passwordHash: hashPassword(password), created: new Date().toISOString() }; this.#file = { ...this.#file, nextUserId: this.#file.nextUserId + 1, accounts: [...this.#file.accounts, account] }; writeFileAtomic(this.#path, JSON.stringify(this.#file, null, 2)); + this.#lastSignedInUserId = userId; return { kind: 'signed-in', account, registered: true }; } + /** + * The account that most recently signed in during this service run (for defaulting the initial + * read-only account dropdown in the built-in browser; never used as a fallback on mutations). + */ + lastSignedIn(): Account | undefined { + return this.#lastSignedInUserId ? this.byUserId(this.#lastSignedInUserId) : undefined; + } + all(): readonly Account[] { return this.#file.accounts; } diff --git a/packages/local-service/src/game-data/datasets/web-icons.ts b/packages/local-service/src/game-data/datasets/web-icons.ts index b36a0a2..92c5197 100644 --- a/packages/local-service/src/game-data/datasets/web-icons.ts +++ b/packages/local-service/src/game-data/datasets/web-icons.ts @@ -5,9 +5,10 @@ * gameuiskin/_ico.svg the tech-tree silhouette of a vehicle * gameuiskin/.svg a country flag (country_usa, ...) * - * All 3349 vehicle icons together are about 26 MB, so only the vehicles the stock game sells - * for real money are kept: gift vehicles (wpcost.blk gift:t, the store's packs) and - * marketplace vehicles (shop.blk marketplaceItemdefId). + * 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'; @@ -26,20 +27,23 @@ export interface WebIcons { export const webIcons: Dataset = { id: 'web-icons', - version: 1, + version: 3, extract: (source) => { - const available = new Set(source.listFiles(ATLASES)); + // 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 path = `${ICON_FOLDER}${name}.svg`; - return available.has(path) ? source.readText(ATLASES, path) : undefined; + const actualPath = byLowerPath.get(`${ICON_FOLDER}${name}.svg`.toLowerCase()); + return actualPath ? source.readText(ATLASES, actualPath) : undefined; }; const shopEntries = shopEntriesByName(source); const vehicles: Record = {}; for (const vehicle of source.readBlk('char.vromfs.bin', VEHICLE_ECONOMY).blocks) { - const soldForMoney = stringField(vehicle, 'gift') !== undefined + const needIcon = stringField(vehicle, 'gift') !== undefined + || (numberField(vehicle, 'costGold') ?? 0) > 0 || numberField(shopEntries.get(vehicle.name), 'marketplaceItemdefId') !== undefined; - const icon = soldForMoney ? readIcon(`${vehicle.name}_ico`) : undefined; + const icon = needIcon ? readIcon(`${vehicle.name}_ico`) : undefined; if (icon) vehicles[vehicle.name] = icon; } diff --git a/packages/local-service/src/inventory/web/app.js b/packages/local-service/src/inventory/web/app.js index fcc333c..a502ebc 100644 --- a/packages/local-service/src/inventory/web/app.js +++ b/packages/local-service/src/inventory/web/app.js @@ -43,8 +43,10 @@ function applyStaticTexts() { async function loadState(userId) { state = await WtoUi.getJson('/trade.gaijin.net/api/state' + (userId ? '?userId=' + encodeURIComponent(userId) : '')); - if (userId && !state.currentUserId) return loadState(''); - if (state.currentUserId) WtoUi.saveAccount(state.currentUserId); + if (userId && !state.currentUserId) { + WtoUi.clearSavedAccount(); + return loadState(''); + } WtoUi.fillAccountSelect($('accountSelect'), state.accounts, state.currentUserId); $('gjnVal').textContent = WtoUi.gjn(state.balance.gjnCents); $('goldVal').textContent = WtoUi.num(state.balance.goldenEagles); @@ -112,12 +114,15 @@ function listingCard(listing) { const foot = document.createElement('div'); foot.className = 'card-foot'; - foot.innerHTML = ''; + foot.innerHTML = ''; foot.querySelector('.price').textContent = WtoUi.gjn(listing.gjnCostCents) + ' GJN'; - const button = foot.querySelector('button'); - button.textContent = state.currentUserId ? t('buy') : t('pickAccount'); - button.disabled = !state.currentUserId; - button.onclick = () => buy(listing.itemdefId); + const btn = Object.assign(document.createElement('button'), { + className: 'buy', + textContent: state.currentUserId ? t('buy') : t('pickAccount'), + disabled: !state.currentUserId, + }); + if (!btn.disabled) btn.onclick = () => buy(listing.itemdefId); + foot.appendChild(btn); card.appendChild(foot); return card; } @@ -135,7 +140,10 @@ $('tabs').onclick = (event) => { activeCat = tab.dataset.cat; renderGrid(); }; -$('accountSelect').onchange = (event) => loadState(event.target.value); +$('accountSelect').onchange = (event) => { + WtoUi.saveAccount(event.target.value); + loadState(event.target.value); +}; $('countryFilter').onchange = renderGrid; $('classFilter').onchange = renderGrid; $('searchInput').oninput = renderGrid; diff --git a/packages/local-service/src/store/web/app.js b/packages/local-service/src/store/web/app.js index 6d4ee09..2ae8c99 100644 --- a/packages/local-service/src/store/web/app.js +++ b/packages/local-service/src/store/web/app.js @@ -35,6 +35,10 @@ function applyStaticTexts() { async function loadState(userId) { state = await WtoUi.getJson('/store/api/state' + (userId ? '?userId=' + encodeURIComponent(userId) : '')); + if (userId && !state.activeUserId) { + WtoUi.clearSavedAccount(); + return loadState(''); + } renderHeader(); renderFilters(); renderContent(); @@ -165,7 +169,10 @@ async function redeem() { await loadState(state.activeUserId); } -$('accountSelect').onchange = (event) => loadState(event.target.value); +$('accountSelect').onchange = (event) => { + WtoUi.saveAccount(event.target.value); + loadState(event.target.value); +}; $('searchInput').oninput = renderContent; $('countryFilter').onchange = renderContent; $('rankFilter').onchange = renderContent; diff --git a/packages/local-service/src/web-ui/web-helpers.ts b/packages/local-service/src/web-ui/web-helpers.ts index fc82e08..8576b37 100644 --- a/packages/local-service/src/web-ui/web-helpers.ts +++ b/packages/local-service/src/web-ui/web-helpers.ts @@ -70,11 +70,12 @@ export function jsonResponse(payload: unknown, summary: string): ServiceResponse /** * Select the account displayed in a read-only web state query: * - when `requestedUserId` is provided, look up that exact account (never falling back to another); - * - when `requestedUserId` is omitted on initial page load, default the UI selector to the first registered account. + * - when `requestedUserId` is omitted on initial page load, default the UI selector to the account + * currently signed into the game in this session, or the first registered account otherwise. */ export function selectWebViewAccount(accounts: AccountStore, requestedUserId: string | null): Account | undefined { const trimmed = requestedUserId?.trim() ?? ''; - return trimmed ? accounts.byUserId(trimmed) : accounts.all()[0]; + return trimmed ? accounts.byUserId(trimmed) : (accounts.lastSignedIn() ?? accounts.all()[0]); } /** diff --git a/packages/local-service/src/web-ui/web/common.js b/packages/local-service/src/web-ui/web/common.js index 899e62e..391803d 100644 --- a/packages/local-service/src/web-ui/web/common.js +++ b/packages/local-service/src/web-ui/web/common.js @@ -64,13 +64,21 @@ const WtoUi = (() => { return img; } - /** The account the player picked last time on either page (kept in the built-in browser). */ + /** + * Manual account override chosen in the page dropdown during this browser session. + * Kept in sessionStorage (not auto-written on initial load) so opening the store or + * marketplace defaults to the account currently signed into the game. + */ function savedAccount() { - try { return localStorage.getItem(ACCOUNT_KEY) || ''; } catch (error) { return ''; } + try { return sessionStorage.getItem(ACCOUNT_KEY) || ''; } catch (error) { return ''; } } function saveAccount(userId) { - try { localStorage.setItem(ACCOUNT_KEY, userId); } catch (error) { /* storage unavailable: the choice is not kept */ } + try { sessionStorage.setItem(ACCOUNT_KEY, userId); } catch (error) { /* storage unavailable */ } + } + + function clearSavedAccount() { + try { sessionStorage.removeItem(ACCOUNT_KEY); } catch (error) { /* storage unavailable */ } } function fillAccountSelect(select, accounts, currentId) { @@ -94,5 +102,5 @@ const WtoUi = (() => { element.className = 'notice ' + (ok ? 'ok' : 'err'); } - return { lang, query, text, tr, num, gjn, escapeHtml, label, getJson, postJson, loadLabels, iconImg, savedAccount, saveAccount, fillAccountSelect, pageLink, showNotice }; + return { lang, query, text, tr, num, gjn, escapeHtml, label, getJson, postJson, loadLabels, iconImg, savedAccount, saveAccount, clearSavedAccount, fillAccountSelect, pageLink, showNotice }; })();