feedback2 WE: setup downloads the 36 battle emotes and the 19 玩法说明 pages from the public mirror (ArknightsAssets2 cn); the client shows the local-client art first, then the mirror copy, then its fallback (#42)
This commit is contained in:
1 parent
380af1ba80
commit
db7b2b1404
11 files changed
+280
-44
No files matched your search
+62
-1
@@ -18,9 +18,10 @@ import { pngSize, isCompletePng, isMp3, validate } from '../tools/assets/formats
|
||||
import { encodeWoff2, decodeWoff2Tables, readSfnt, uintBase128 } from '../tools/assets/woff2.mjs';
|
||||
import { assetToPath, pickUnitSfx, indexAudio } from '../tools/assets/audio.mjs';
|
||||
import { mirrorUrl, safeName, encodePath } from '../tools/assets/sources.mjs';
|
||||
import { collectEnemyIds, skillIndicesByChar } from '../tools/assets/plan.mjs';
|
||||
import { collectEnemyIds, skillIndicesByChar, buildPlan, GUIDE_PAGES, UI_EXTRAS } from '../tools/assets/plan.mjs';
|
||||
import { resolveTemplate, collectLeaves } from '../tools/assets/manifest.mjs';
|
||||
import { spineEntry } from '../public/js/assets.js';
|
||||
import { EMOTE_CATALOG, emoteArtGroup } from '../shared/constants.js';
|
||||
|
||||
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const PUBLIC = join(ROOT, 'public');
|
||||
@@ -468,6 +469,66 @@ describe('downloader (fake network)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// GitHub issue #42: a source deploy on a server without the Arknights client had no public/assets/local, so the battle
|
||||
// emotes showed default icons and 玩法说明 showed text tips. The public mirror has both (checked 2026-10-03: all 55
|
||||
// URLs answer 200 on raw.githubusercontent.com and on jsDelivr, same pictures and sizes as the local extraction), so the
|
||||
// plan downloads them like any other UI sprite, keyed by the data/local-assets.json group and name.
|
||||
describe('emotes and 玩法说明 pages from the public mirror (GitHub issue #42)', () => {
|
||||
const AA2 = 'https://raw.githubusercontent.com/ArknightsAssets/ArknightsAssets2/cn/assets/dyn/';
|
||||
const plan = () => buildPlan({ assets07: {}, ops03: {}, enemies05: {}, maps05: {}, audio: indexAudio({}), modelsData: {} }).template;
|
||||
|
||||
test('the plan fetches the 36 battle emotes and the 19 guide pages from ArknightsAssets2 cn, keyed like the local art', () => {
|
||||
const ui = plan().ui;
|
||||
assert.equal(EMOTE_CATALOG.length, 36);
|
||||
for (const e of EMOTE_CATALOG) {
|
||||
const key = `${emoteArtGroup(e.id)}/${e.picId}`; // the local manifest's group + name (emoticon/<dir>/<picId>)
|
||||
assert.deepEqual(ui[key]?.alts, [{ rel: `ui/${key}.png`, urls: [`${AA2}ui/emoticon/theme/%5Buc%5D${e.themeId}/icon/${e.picId}.png`], kind: 'png' }], key);
|
||||
}
|
||||
assert.ok(ui['emoticon/fooldoctor/pic_fooldoctor_08_battle'], 'keyed by picId, not by the emote id (fooldoctor_06 → pic 08)');
|
||||
assert.notEqual(ui['emoticon/slug/pic_thanks_battle'].alts[0].rel, ui['emoticon/basic/pic_thanks_battle'].alts[0].rel, 'same picId, two themes');
|
||||
assert.deepEqual(GUIDE_PAGES.slice(0, 2), ['autochess_home_1', 'autochess_home_2']);
|
||||
assert.equal(GUIDE_PAGES.length, 19);
|
||||
for (const k of GUIDE_PAGES) {
|
||||
assert.deepEqual(ui[`guide/${k}`]?.alts, [{ rel: `ui/guide/${k}.png`, urls: [`${AA2}arts/guidebookpages/%5Bpack%5Dautochess/${k}.png`], kind: 'png' }], k);
|
||||
}
|
||||
const rels = Object.values(ui).map((l) => l.alts[0].rel);
|
||||
assert.equal(new Set(rels).size, rels.length, 'no two UI entries share a file');
|
||||
assert.ok(rels.every((r) => !r.startsWith('local/')), 'public/assets/local belongs to tools/local-extract');
|
||||
assert.equal(mirrorUrl(ui['emoticon/fooldoctor/pic_fooldoctor_08_battle'].alts[0].urls[0]),
|
||||
'https://cdn.jsdelivr.net/gh/ArknightsAssets/ArknightsAssets2@cn/assets/dyn/ui/emoticon/theme/%5Buc%5Demoticon_foolsday_doctor/icon/pic_fooldoctor_08_battle.png',
|
||||
'the jsDelivr fallback (downloader) serves the same path');
|
||||
assert.ok(Object.isFrozen(UI_EXTRAS) && UI_EXTRAS.every(Object.isFrozen));
|
||||
});
|
||||
|
||||
test('a rebuilt manifest lists the copies that are on disk under /assets/ui/…; a missing one is left out', async () => {
|
||||
const { mkdtemp, mkdir, writeFile } = await import('node:fs/promises');
|
||||
const { tmpdir } = await import('node:os');
|
||||
const root = await mkdtemp(join(tmpdir(), 'sp-mirror-art-'));
|
||||
const ui = plan().ui;
|
||||
const keys = ['emoticon/basic/pic_happy_battle', 'guide/autochess_home_1', 'emoticon/slug/pic_bye_battle'];
|
||||
for (const k of keys.slice(0, 2)) {
|
||||
await mkdir(join(root, dirname(ui[k].alts[0].rel)), { recursive: true });
|
||||
await writeFile(join(root, ui[k].alts[0].rel), 'x');
|
||||
}
|
||||
const r = resolveTemplate({ ui: Object.fromEntries(keys.map((k) => [k, ui[k]])) }, { root, spine: new Map() });
|
||||
assert.deepEqual(r.value.ui, {
|
||||
'emoticon/basic/pic_happy_battle': '/assets/ui/emoticon/basic/pic_happy_battle.png',
|
||||
'guide/autochess_home_1': '/assets/ui/guide/autochess_home_1.png',
|
||||
});
|
||||
assert.deepEqual(r.misses, ['ui.emoticon/slug/pic_bye_battle']);
|
||||
});
|
||||
|
||||
test('the committed data/assets.json lists all 55, so setup on an install made before them downloads them', () => {
|
||||
// tools/setup.mjs runs fetch-assets when data/assets.json lists a file that is not on disk (checkAssets)
|
||||
const m = readJson('data/assets.json');
|
||||
for (const e of EMOTE_CATALOG) assert.equal(m.ui[`emoticon/${e.dir}/${e.picId}`], `/assets/ui/emoticon/${e.dir}/${e.picId}.png`, e.id);
|
||||
for (const k of GUIDE_PAGES) assert.equal(m.ui[`guide/${k}`], `/assets/ui/guide/${k}.png`, k);
|
||||
assert.equal(m.stats.ui, Object.keys(m.ui).length);
|
||||
assert.ok(!JSON.stringify(m).includes('/assets/local/'), 'never a local-client path');
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('generated manifest data/assets.json', () => {
|
||||
const haveManifest = existsSync(MANIFEST);
|
||||
|
||||
@@ -71,6 +71,22 @@ test('fetch-assets shrink guard: the committed manifest minus some audio entries
|
||||
assert.equal(statSync(MANIFEST).mtimeMs, before, 'importing the tool runs nothing');
|
||||
});
|
||||
|
||||
test('a server where the mirror emotes / 玩法说明 pages failed to download keeps the committed manifest, so the next setup retries them (#42)', async () => {
|
||||
// setup re-runs fetch-assets only while data/assets.json lists a file that is not on disk: a manifest rewritten without
|
||||
// these entries would stop the retries, and the emotes would stay default icons on that server
|
||||
const { shrinkGuard, parseArgs } = await import('../tools/fetch-assets.mjs');
|
||||
const prev = JSON.parse(readFileSync(MANIFEST, 'utf8'));
|
||||
const next = JSON.parse(JSON.stringify(prev));
|
||||
for (const k of Object.keys(next.ui)) if (/^(emoticon|guide)\//.test(k)) delete next.ui[k];
|
||||
next.stats = { ...next.stats, ui: Object.keys(next.ui).length };
|
||||
const g = shrinkGuard(prev, next, parseArgs([]));
|
||||
assert.equal(g.write, false);
|
||||
assert.equal(g.dropped.length, 36 + 19);
|
||||
for (const k of ['ui.emoticon/basic/pic_happy_battle', 'ui.emoticon/fooldoctor/pic_fooldoctor_08_battle', 'ui.guide/autochess_home_1', 'ui.guide/autochess_handbook_4']) {
|
||||
assert.ok(g.dropped.includes(k), k);
|
||||
}
|
||||
});
|
||||
|
||||
test('fetch-assets still runs as a script: --help lists --allow-shrink', () => {
|
||||
const r = spawnSync(process.execPath, [join(ROOT, 'tools', 'fetch-assets.mjs'), '--help'], { encoding: 'utf8', timeout: 30000 });
|
||||
assert.equal(r.status, 0, r.stderr);
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
// Local-client art is optional (DESIGN §13): the emote art, the 玩法说明 pages and the official tier chips resolve
|
||||
// from data/local-assets.json when present and fall back (text / tips / CSS) when the manifest or an entry is missing.
|
||||
// The emotes and the 玩法说明 pages are also on the public mirror (GitHub issue #42): data/assets.json lists the copies
|
||||
// tools/fetch-assets.mjs downloads under the same group and name (ui['<group>/<name>']); the client takes the local
|
||||
// file first, then the mirror copy, then its fallback (data.js artUrls / nextArtUrl).
|
||||
|
||||
import { test, describe } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { EMOTES, emoteArtPath, emoteArtGroup, emoteInfo } from '../../shared/constants.js';
|
||||
import { EMOTES, EMOTE_CATALOG, emoteArtPath, emoteArtGroup, emoteInfo } from '../../shared/constants.js';
|
||||
import { GUIDE_PAGES } from '../../tools/assets/plan.mjs';
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
||||
|
||||
@@ -19,13 +23,28 @@ const manifest = {
|
||||
'ui/battle': { img_chess_level_3: { path: '/assets/local/ui/battle/img_chess_level_3.png', w: 45, h: 45 } },
|
||||
},
|
||||
};
|
||||
// what server/index.js serves when data/local-assets.json is absent
|
||||
const EMPTY_LOCAL = { version: 1, source: 'none', count: 0, groups: {} };
|
||||
|
||||
let mode = 'ok';
|
||||
let mode = 'ok'; // data/local-assets.json: 'ok' (the manifest above) | 'empty' (the server's stand-in) | 'missing' (404)
|
||||
let assetsDoc = null; // data/assets.json, or null (404)
|
||||
globalThis.fetch = async (url) => {
|
||||
if (String(url).endsWith('/local-assets.json') && mode === 'ok') return { ok: true, status: 200, json: async () => manifest };
|
||||
const u = String(url);
|
||||
if (u.endsWith('/local-assets.json')) {
|
||||
if (mode === 'ok') return { ok: true, status: 200, json: async () => manifest };
|
||||
if (mode === 'empty') return { ok: true, status: 200, json: async () => EMPTY_LOCAL };
|
||||
} else if (u.endsWith('/assets.json') && assetsDoc) return { ok: true, status: 200, json: async () => assetsDoc };
|
||||
return { ok: false, status: 404, json: async () => ({}) };
|
||||
};
|
||||
|
||||
/** Reload both manifests after changing `mode` / `assetsDoc`. */
|
||||
async function reload(data) {
|
||||
const orig = console.warn; console.warn = () => {};
|
||||
try {
|
||||
for (const n of ['local', 'assets']) { await data.invalidate(n); await data.load(n); }
|
||||
} finally { console.warn = orig; }
|
||||
}
|
||||
|
||||
describe('local-client art fallbacks', () => {
|
||||
test('manifest present: listed entries resolve, unlisted ones stay null', async () => {
|
||||
const { data, localAsset } = await import('../../public/js/data.js');
|
||||
@@ -48,9 +67,9 @@ describe('local-client art fallbacks', () => {
|
||||
|
||||
test('manifest missing: everything falls back', async () => {
|
||||
mode = 'missing';
|
||||
assetsDoc = null;
|
||||
const { data } = await import('../../public/js/data.js');
|
||||
const orig = console.warn; console.warn = () => {};
|
||||
try { await data.invalidate('local'); } finally { console.warn = orig; }
|
||||
await reload(data);
|
||||
assert.equal(data.status('local'), 'missing');
|
||||
const { emoteArtUrl } = await import('../../public/js/ui/emotes.js');
|
||||
const { guidePages } = await import('../../public/js/ui/guide.js');
|
||||
@@ -71,6 +90,65 @@ describe('local-client art fallbacks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('emotes and 玩法说明 pages: local art first, then the mirror copy (GitHub issue #42)', () => {
|
||||
test('lookup order: the local file, then data/assets.json ui[\'<group>/<name>\'], then nothing', async () => {
|
||||
mode = 'ok';
|
||||
assetsDoc = { ui: {
|
||||
'emoticon/basic/pic_happy_battle': '/assets/ui/emoticon/basic/pic_happy_battle.png', // both: the local one wins
|
||||
'emoticon/basic_2/pic_sad_battle': '/assets/ui/emoticon/basic_2/pic_sad_battle.png', // the mirror copy only
|
||||
'guide/autochess_home_1': '/assets/ui/guide/autochess_home_1.png',
|
||||
'guide/autochess_home_9': '/assets/ui/guide/autochess_home_9.png',
|
||||
'ui/battle/img_chess_level_4': '/assets/ui/x.png', // not one of the mirrored groups' names
|
||||
} };
|
||||
const { data, artUrls, nextArtUrl, localAsset } = await import('../../public/js/data.js');
|
||||
await reload(data);
|
||||
const { emoteArtUrl, emoteArtUrls } = await import('../../public/js/ui/emotes.js');
|
||||
const { guidePages } = await import('../../public/js/ui/guide.js');
|
||||
assert.deepEqual(emoteArtUrls('autochess_battle_happy'), ['/assets/local/emoticon/basic/pic_happy_battle.png', '/assets/ui/emoticon/basic/pic_happy_battle.png']);
|
||||
assert.equal(emoteArtUrl('autochess_battle_happy'), '/assets/local/emoticon/basic/pic_happy_battle.png', 'local first');
|
||||
assert.equal(emoteArtUrl('autochess_battle_sad'), '/assets/ui/emoticon/basic_2/pic_sad_battle.png', 'no local file: the mirror copy');
|
||||
assert.deepEqual(emoteArtUrls('autochess_battle_dying'), [], 'neither: the glyph');
|
||||
assert.equal(emoteArtUrl('autochess_battle_dying'), null);
|
||||
assert.deepEqual(emoteArtUrls('__proto__'), []);
|
||||
const pages = guidePages();
|
||||
assert.deepEqual(pages.map((p) => p.key), ['autochess_home_1', 'autochess_home_2', 'autochess_home_9', 'autochess_shop_1', 'autochess_handbook_4'], 'reading order, either source');
|
||||
assert.deepEqual(pages[0].urls, ['/assets/local/guide/autochess_home_1.png', '/assets/ui/guide/autochess_home_1.png']);
|
||||
assert.equal(pages[0].url, '/assets/local/guide/autochess_home_1.png');
|
||||
assert.deepEqual(pages[2].urls, ['/assets/ui/guide/autochess_home_9.png']);
|
||||
assert.deepEqual(artUrls('guide', 'autochess_home_2'), ['/assets/local/guide/autochess_home_2.png']);
|
||||
assert.deepEqual(artUrls('ui/battle', 'img_chess_level_3'), ['/assets/local/ui/battle/img_chess_level_3.png']);
|
||||
assert.deepEqual(artUrls('guide', '__proto__'), []);
|
||||
assert.deepEqual(artUrls('constructor', 'x'), []);
|
||||
assert.equal(localAsset('guide', 'autochess_home_9'), null, 'localAsset stays local-only');
|
||||
// an image that fails to load (a copied local-assets.json without its files) falls through to the next URL
|
||||
const urls = emoteArtUrls('autochess_battle_happy');
|
||||
assert.equal(nextArtUrl(urls, new Set()), urls[0]);
|
||||
assert.equal(nextArtUrl(urls, new Set([urls[0]])), urls[1]);
|
||||
assert.equal(nextArtUrl(urls, new Set(urls)), null, 'both failed: the fallback');
|
||||
assert.equal(nextArtUrl(urls), urls[0]);
|
||||
assert.equal(nextArtUrl(null), null);
|
||||
});
|
||||
|
||||
test('no local client (a source deploy on a server, issue #42): every emote and all 19 pages come from the committed data/assets.json', async () => {
|
||||
mode = 'empty';
|
||||
assetsDoc = JSON.parse(readFileSync(path.join(ROOT, 'data/assets.json'), 'utf8'));
|
||||
const { data } = await import('../../public/js/data.js');
|
||||
await reload(data);
|
||||
const { emoteArtUrl } = await import('../../public/js/ui/emotes.js');
|
||||
const { guidePages } = await import('../../public/js/ui/guide.js');
|
||||
for (const e of EMOTE_CATALOG) assert.equal(emoteArtUrl(e.id), `/assets/ui/emoticon/${e.dir}/${e.picId}.png`, e.id);
|
||||
const pages = guidePages();
|
||||
assert.deepEqual(pages.map((p) => p.key), GUIDE_PAGES);
|
||||
assert.deepEqual(pages.map((p) => p.url), GUIDE_PAGES.map((k) => `/assets/ui/guide/${k}.png`));
|
||||
assert.ok(pages.every((p) => p.urls.length === 1));
|
||||
});
|
||||
|
||||
test('tools/assets/plan.mjs GUIDE_PAGES is the viewer\'s page list (GUIDE_CHAPTERS), in reading order', async () => {
|
||||
const { GUIDE_CHAPTERS } = await import('../../public/js/ui/guide.js');
|
||||
assert.deepEqual([...GUIDE_PAGES], GUIDE_CHAPTERS.flatMap((c) => c.pages.map(([key]) => key)));
|
||||
});
|
||||
});
|
||||
|
||||
function safeRead() {
|
||||
try { return readFileSync(path.join(ROOT, 'data/local-assets.json'), 'utf8'); } catch { return null; }
|
||||
}
|
||||
Reference in new issue
Block a user