PIXI loading, pick records, tunables, view kind, unit info and the asset / GL host now live in public/js/render/app/*.js. createFieldView stays in app.js, unchanged, and every name the file used to export is re-exported. One pixiPromise. Two source pins follow the lines that moved.
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
// public/js/render/app/pixi.js — load PIXI and pixi-spine once (one module-level promise).
|
|
|
|
const VENDOR = { pixi: '/vendor/pixi.min.js', spine: '/vendor/pixi-spine.js' };
|
|
|
|
let pixiPromise = null;
|
|
|
|
function loadScript(src) {
|
|
return new Promise((resolve, reject) => {
|
|
const s = document.createElement('script');
|
|
s.src = src;
|
|
s.async = false;
|
|
s.onload = () => resolve();
|
|
s.onerror = () => reject(new Error(`failed to load ${src}`));
|
|
document.head.appendChild(s);
|
|
});
|
|
}
|
|
|
|
/** Make sure PIXI and PIXI.spine exist (classic scripts; loaded once). */
|
|
export function ensurePixi() {
|
|
if (globalThis.PIXI && globalThis.PIXI.spine) return Promise.resolve(globalThis.PIXI);
|
|
if (!pixiPromise) {
|
|
pixiPromise = (async () => {
|
|
if (!globalThis.PIXI) await loadScript(VENDOR.pixi);
|
|
if (!globalThis.PIXI?.spine) await loadScript(VENDOR.spine);
|
|
if (!globalThis.PIXI || !globalThis.PIXI.spine) throw new Error('PIXI / pixi-spine unavailable');
|
|
return globalThis.PIXI;
|
|
})();
|
|
pixiPromise.catch(() => { pixiPromise = null; });
|
|
}
|
|
return pixiPromise;
|
|
}
|