Files
ark-stronghold-protocol/public/js/render/app/host.js
T
sganggs 0def7babfd feedback5 WK: 自选编队 in the browser — the 干员调配 overlay's third tab 自选编队 (5阶 ×2, 6阶 ×2 slots; the slot picker lists the kitted picks of the tier with avatar, name, class, derived bonds and a 原型 / 已持有 tag; an owned pick chooses its skill and module — 集成战略 modules left out —, a prototype shows its locked skill; sp.pref.diy, export / import, 全部清空, synced as room.diy through the shared engine, welcome.diyKitted kept), the operator on shop / reward cards, own pieces (「自选」 tag, its model on bench and board), the detail card (pick's skill and module), placement and range previews, bond popups (own and a teammate's 自选 member), the result screen; new UI strings through t() with English; the e2e fast server's SP_START_LEVEL hook
Bonds of 自选 pieces checked everywhere membership is decided (the owner's reminder of 2026-10-05): the match's counts through the player's data view (煌 in 炎 and 维多利亚, one member per slot, 绝技 elites), the sim's bond effects through def.bonds (叙拉古 on deployment, 协防 ×1.2 / elite ×1.4), the client's strip, popups, cards and detail card. Golden unchanged.
Tests: test/ui/diy-ui.test.js (15), test/match/diy-bonds.test.js (4), test/i18n.test.js pins screens/diy.js; test/ui/diy.e2e.test.js (SP_E2E=1, run once: pass).
2026-10-06 00:13:31 +08:00

101 lines
4.5 KiB
JavaScript

// public/js/render/app/host.js — asset lookup, data lookup and GL teardown for one field view.
import { createAssets, assets as defaultAssets } from '../../assets.js';
import { standInRecord } from '../../../../shared/standIn.js';
import { diyRecordOf } from '../../../../shared/diy.js';
function withTimeout(p, ms) {
return Promise.race([p, new Promise((resolve) => setTimeout(resolve, ms))]);
}
/** Wrap whatever the caller passed as `assets` into the store API of public/js/assets.js. */
function resolveAssets(a) {
if (a && typeof a === 'object' && typeof a.ready === 'function' && typeof a.spineEntry === 'function') return a;
if (a && typeof a === 'object' && (a.chars || a.enemies || a.version)) return createAssets({ manifest: a });
return defaultAssets;
}
function makeData(src) {
const look = (file, id) => {
if (id == null || id === '') return null;
try {
if (src && typeof src.lookup === 'function') return src.lookup(file, id) || null;
const m = src && src[file];
if (m instanceof Map) return m.get(id) || null;
if (m && typeof m === 'object' && Object.hasOwn(m, id)) return m[id] || null;
} catch { /* ignore */ }
return null;
};
// 0.2.0 补位: the composed stand-in record of a chess (shared/standIn.js over data/backups.json), cached per chess
const standIns = new Map();
const backups = () => {
try { return (src && typeof src.get === 'function' ? src.get('backups') : src && src.backups) || null; } catch { return null; }
};
const standIn = (id) => {
const c = look('chess', id);
const b = backups();
if (!c || !b) return null;
if (standIns.has(c)) return standIns.get(c);
let rec;
try { rec = standInRecord(c, b); } catch { rec = null; }
standIns.set(c, rec);
return rec;
};
// 0.2.0 自选编队: the composed 自选 record of a DIY slot filled with a pick (shared/diy.js over chess.json + backups.json)
const diys = new Map();
const chessMap = () => {
try { return (src && typeof src.get === 'function' ? src.get('chess') : src && src.chess) || null; } catch { return null; }
};
const diy = (id, pick) => {
const c = look('chess', id);
const b = backups();
if (!c || !c.isDiy || !b || !pick || typeof pick.charId !== 'string') return null;
const key = `${id}|${pick.charId}|${pick.skillIndex ?? ''}|${pick.uniEquipId ?? ''}`;
if (diys.has(key)) return diys.get(key);
let rec;
try { rec = diyRecordOf(c, pick, { chess: chessMap(), backups: b }); } catch { rec = null; }
diys.set(key, rec);
return rec;
};
return {
chess: (id) => look('chess', id), token: (id) => look('tokens', id), item: (id) => look('items', id),
enemy: (id) => look('enemies', id), stage: (id) => look('stages', id), bond: (id) => look('bonds', id),
standIn, diy,
};
}
const QUALITY_RES = { high: 2, medium: 1.5, low: 1 };
/** Pixel-ratio cap of the 3D board canvas per quality (its fill cost is the PBR board, not the sprites). */
const BOARD_RES = { high: 2, medium: 1.25, low: 1 };
/**
* Before a renderer is destroyed: free its GL copies of every texture / buffer / geometry / framebuffer it
* uploaded. Module-level textures (FX atlas, tier chips, backdrop, diamonds, Spine pages, PIXI.Texture.WHITE…)
* outlive the view; PIXI 7 leaves their per-context GL entries and 'dispose' listeners pointing at the dead
* renderer, which kept every unmounted view's renderer, canvas and WebGL context reachable.
*/
export function releaseGl(renderer) {
const ts = renderer && renderer.texture;
if (ts && Array.isArray(ts.managedTextures) && typeof ts.destroyTexture === 'function') {
for (const bt of ts.managedTextures.slice()) { try { ts.destroyTexture(bt, true); } catch { /* ignore */ } }
ts.managedTextures.length = 0;
}
for (const sys of [renderer?.geometry, renderer?.buffer, renderer?.framebuffer]) {
try { if (sys && typeof sys.disposeAll === 'function') sys.disposeAll(false); } catch { /* ignore */ }
}
// shader programs are cached globally by source (PIXI.utils.ProgramCache) with one GLProgram per context
const uid = renderer?.CONTEXT_UID, gl = renderer?.gl;
const programs = globalThis.PIXI?.utils?.ProgramCache;
if (uid != null && programs && typeof programs === 'object') {
for (const prog of Object.values(programs)) {
const g = prog && prog.glPrograms && prog.glPrograms[uid];
if (!g) continue;
try { if (gl && g.program) gl.deleteProgram(g.program); } catch { /* ignore */ }
delete prog.glPrograms[uid];
}
}
}
export { withTimeout, resolveAssets, makeData, QUALITY_RES, BOARD_RES };