cortico-world-extra-actions 0.3.30 → 0.3.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/starter/figure/figure.json +2 -1
- package/dist/webui.js +18 -1
- package/package.json +1 -1
- package/src/starter.js +13 -1
- package/tools/manifest-check.mjs +90 -0
- package/tools/test_manifest.mjs +94 -0
package/dist/webui.js
CHANGED
|
@@ -369,7 +369,7 @@ const panel = {
|
|
|
369
369
|
<div class="hint" data-role="libhint">当前库见右下方状态行</div>
|
|
370
370
|
</div>
|
|
371
371
|
</details>
|
|
372
|
-
<button class="ea-btn" data-act="restore-pack" title="建一个空的角色包(只有身体状态),位置自己选">建立空的角色包(选位置)</button>
|
|
372
|
+
<button class="ea-btn" data-act="restore-pack" data-role="restore-btn" title="建一个空的角色包(只有身体状态),位置自己选">建立空的角色包(选位置)</button>
|
|
373
373
|
<span class="ea-lib" data-role="lib"></span>
|
|
374
374
|
</div>
|
|
375
375
|
<div class="ea-pin">
|
|
@@ -949,6 +949,22 @@ const panel = {
|
|
|
949
949
|
}
|
|
950
950
|
}
|
|
951
951
|
|
|
952
|
+
/** 已经有深深包时,这个按钮变成「修复」—— 避免用户以为可以再建一个新的。 */
|
|
953
|
+
function syncRestoreBtn() {
|
|
954
|
+
const btn = wrap.querySelector('[data-role=restore-btn]');
|
|
955
|
+
if (!btn) return;
|
|
956
|
+
const have = (Array.isArray(state?.figures) ? state.figures : []).find((f) => f && f.id === 'shenshen-actions');
|
|
957
|
+
if (have) {
|
|
958
|
+
btn.textContent = '修复深深形象包';
|
|
959
|
+
btn.title = `已经有深深的形象包了:${have.dir ?? ''}。点它会补齐缺的文件,不会重复创建。`;
|
|
960
|
+
btn.classList.remove('pri');
|
|
961
|
+
} else {
|
|
962
|
+
btn.textContent = '建立空的角色包(选位置)';
|
|
963
|
+
btn.title = '建一个空的角色包(只有身体状态),位置自己选';
|
|
964
|
+
btn.classList.add('pri');
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
952
968
|
function renderNote() {
|
|
953
969
|
const p = pack();
|
|
954
970
|
noteEl.hidden = true;
|
|
@@ -1035,6 +1051,7 @@ const panel = {
|
|
|
1035
1051
|
: '当前还没设置动作库 —— 选「自动寻找动作库…」或「选择动作库位置…」';
|
|
1036
1052
|
}
|
|
1037
1053
|
maybeOnboard();
|
|
1054
|
+
syncRestoreBtn();
|
|
1038
1055
|
renderPack(); renderShowAll(); renderChips(); renderList(); renderInstalled(); renderSum(); renderNote(); fitFoot();
|
|
1039
1056
|
}
|
|
1040
1057
|
|
package/package.json
CHANGED
package/src/starter.js
CHANGED
|
@@ -293,7 +293,18 @@ export function ensureConsolePreset(packDir, log) {
|
|
|
293
293
|
const fig = readJson(figFile, null);
|
|
294
294
|
if (!fig || fig.id !== PACK_ID) return { changed: false, reason: 'not-our-pack' };
|
|
295
295
|
const presets = Array.isArray(fig.presets) ? fig.presets : [];
|
|
296
|
-
|
|
296
|
+
// 预设必须带 pick(宿主 packs.ts:330),缺了整包不加载 → 先补
|
|
297
|
+
let repaired = 0;
|
|
298
|
+
for (const p of presets) {
|
|
299
|
+
if (p && typeof p === 'object' && (!p.pick || typeof p.pick !== 'object')) { p.pick = {}; repaired++; }
|
|
300
|
+
}
|
|
301
|
+
if (repaired) {
|
|
302
|
+
const bak = join(packDir, 'figure.json.bak-配色2');
|
|
303
|
+
if (!existsSync(bak)) writeFileSync(bak, readFileSync(figFile, 'utf8'), 'utf8');
|
|
304
|
+
writeFileSync(figFile, JSON.stringify(fig, null, 2) + '\n', 'utf8');
|
|
305
|
+
log?.('补上了形象包里缺失的 preset.pick(缺它整包都不会加载)');
|
|
306
|
+
}
|
|
307
|
+
if (presets.some((p) => p && p.console)) return { changed: repaired > 0, reason: repaired ? 'repaired-pick' : 'already-has-console' };
|
|
297
308
|
if (presets.some((p) => p && p.id === CONSOLE_PRESET.id)) return { changed: false, reason: 'id-taken' };
|
|
298
309
|
|
|
299
310
|
const backup = join(packDir, 'figure.json.bak-配色');
|
|
@@ -307,6 +318,7 @@ export function ensureConsolePreset(packDir, log) {
|
|
|
307
318
|
/** 深深包的配色预设(对比度:浅色 on-accent 5.3:1、t/纸面 6.3:1;深色 8.1:1 / 11.4:1)。 */
|
|
308
319
|
export const CONSOLE_PRESET = {
|
|
309
320
|
"id": "teal",
|
|
321
|
+
"pick": {},
|
|
310
322
|
"name": {
|
|
311
323
|
"zh": "深深 · 青绿",
|
|
312
324
|
"zh-Hant": "深深 · 青綠",
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 形象包清单体检:把 figure.json 按宿主 readManifest() 的规则过一遍。
|
|
3
|
+
* node manifest-check.mjs <形象包目录> [更多目录…]
|
|
4
|
+
*
|
|
5
|
+
* 宿主(cortico-world-desktop-pet/packs.ts)对清单是「一条不合格 → 整个包不加载」,
|
|
6
|
+
* 界面上就表现为"形象列表里没有这个包",还会让人以为可以再建一个。
|
|
7
|
+
* 这里把最容易踩的几条静态查出来:
|
|
8
|
+
* - manifest / api 的范围
|
|
9
|
+
* - id / entry / export / thumb
|
|
10
|
+
* - axes:id、name、options[].id 与 name
|
|
11
|
+
* - presets:**必须有 pick 对象**,且 pick 要覆盖每个 axis、值必须是该 axis 的某个 option
|
|
12
|
+
* - vocab / sounds 交给 doctor.mjs 的词表检查
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
15
|
+
import { join, resolve } from 'node:path';
|
|
16
|
+
|
|
17
|
+
const ID = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
18
|
+
const OPTION_ID = /^[a-z0-9][a-z0-9_-]{0,31}$/i;
|
|
19
|
+
const NAME_BREAK = /[,,、\s【】<><>]/;
|
|
20
|
+
|
|
21
|
+
const namesOf = (v) => (v && typeof v === 'object' ? Object.values(v).some((x) => typeof x === 'string' && x.trim()) : false);
|
|
22
|
+
|
|
23
|
+
export function checkManifest(dir) {
|
|
24
|
+
const file = join(dir, 'figure.json');
|
|
25
|
+
if (!existsSync(file)) return [`没有 figure.json`];
|
|
26
|
+
let raw;
|
|
27
|
+
try { raw = JSON.parse(readFileSync(file, 'utf8').replace(/^\uFEFF/, '')); } catch (e) { return [`figure.json 不是合法 JSON:${e.message}`]; }
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const [key, oldest, now] of [['manifest', 1, 2], ['api', 1, 2]]) {
|
|
30
|
+
const v = raw[key];
|
|
31
|
+
if (typeof v !== 'number' || !Number.isInteger(v)) { out.push(`${key} 不是整数:${JSON.stringify(v)}`); continue; }
|
|
32
|
+
if (v > now) out.push(`${key} 比宿主新(${v} > ${now})`);
|
|
33
|
+
if (v < oldest) out.push(`${key} 太老(${v} < ${oldest})`);
|
|
34
|
+
}
|
|
35
|
+
if (typeof raw.id !== 'string' || !ID.test(raw.id)) out.push(`id 不合法:${JSON.stringify(raw.id)}`);
|
|
36
|
+
if (!namesOf(raw.name)) out.push('缺 name');
|
|
37
|
+
if (!namesOf(raw.about)) out.push('缺 about');
|
|
38
|
+
if (typeof raw.entry !== 'string' || !raw.entry) out.push('缺 entry');
|
|
39
|
+
if (typeof raw.export !== 'string' || !raw.export) out.push('缺 export');
|
|
40
|
+
|
|
41
|
+
const axes = [];
|
|
42
|
+
for (const a of Array.isArray(raw.axes) ? raw.axes : []) {
|
|
43
|
+
if (typeof a?.id !== 'string' || !ID.test(a.id)) { out.push(`axis id 不合法:${JSON.stringify(a?.id)}`); continue; }
|
|
44
|
+
if (!namesOf(a?.name)) { out.push(`axis "${a.id}" 缺 name`); continue; }
|
|
45
|
+
if (!Array.isArray(a?.options) || !a.options.length) { out.push(`axis "${a.id}" 没有 options`); continue; }
|
|
46
|
+
const ids = [];
|
|
47
|
+
for (const o of a.options) {
|
|
48
|
+
if (typeof o?.id !== 'string' || !OPTION_ID.test(o.id)) { out.push(`axis "${a.id}" 的 option id 不合法:${JSON.stringify(o?.id)}`); continue; }
|
|
49
|
+
if (!namesOf(o?.name)) out.push(`axis "${a.id}" 的 option "${o.id}" 缺 name`);
|
|
50
|
+
ids.push(o.id);
|
|
51
|
+
}
|
|
52
|
+
axes.push({ id: a.id, ids });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (const p of Array.isArray(raw.presets) ? raw.presets : []) {
|
|
56
|
+
if (typeof p?.id !== 'string' || !ID.test(p.id)) { out.push(`preset id 不合法:${JSON.stringify(p?.id)}`); continue; }
|
|
57
|
+
// ← 这一条最容易被忽略:少了 pick,整个包都不加载
|
|
58
|
+
if (!p.pick || typeof p.pick !== 'object') { out.push(`preset "${p.id}" 缺 pick(宿主会拒绝整个包)`); continue; }
|
|
59
|
+
for (const a of axes) {
|
|
60
|
+
const v = p.pick[a.id];
|
|
61
|
+
if (!a.ids.includes(v)) out.push(`preset "${p.id}" 没给 axis "${a.id}" 选一个合法 option(现在是 ${JSON.stringify(v)})`);
|
|
62
|
+
}
|
|
63
|
+
if (p.name !== undefined && !namesOf(p.name)) out.push(`preset "${p.id}" 的 name 不合法`);
|
|
64
|
+
if (p.console !== undefined) {
|
|
65
|
+
if (typeof p.console !== 'object' || !p.console) out.push(`preset "${p.id}" 的 console 不是对象`);
|
|
66
|
+
else for (const mode of ['light', 'dark']) {
|
|
67
|
+
const pal = p.console[mode];
|
|
68
|
+
if (!pal || typeof pal !== 'object') { out.push(`preset "${p.id}" 的 console.${mode} 缺失`); continue; }
|
|
69
|
+
for (const k of ['a', 'a2', 'on', 't', 'c3', 'c4']) {
|
|
70
|
+
if (typeof pal[k] !== 'string' || !/^#[0-9a-f]{6}$/i.test(pal[k])) out.push(`preset "${p.id}" 的 console.${mode}.${k} 不是 #rrggbb`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* CLI */
|
|
79
|
+
if (process.argv[1] && process.argv[1].endsWith('manifest-check.mjs')) {
|
|
80
|
+
const dirs = process.argv.slice(2).map((d) => resolve(d));
|
|
81
|
+
if (!dirs.length) { console.error('用法: node manifest-check.mjs <形象包目录> …'); process.exit(2); }
|
|
82
|
+
let bad = 0;
|
|
83
|
+
for (const d of dirs) {
|
|
84
|
+
const errs = checkManifest(d);
|
|
85
|
+
console.log(`\n${d}`);
|
|
86
|
+
if (!errs.length) console.log(' ✅ 清单合规');
|
|
87
|
+
else { bad++; for (const e of errs) console.log(' · ' + e); }
|
|
88
|
+
}
|
|
89
|
+
process.exit(bad ? 1 : 0);
|
|
90
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 清单(figure.json)合规测试:宿主对清单是「一条不合格 → 整个包不加载」。
|
|
3
|
+
*
|
|
4
|
+
* 真实踩过的坑:给深深包加控制台配色预设时漏了 `pick`,宿主 packs.ts:330 直接
|
|
5
|
+
* `presets 里有不合法的一项:"teal"` → 整个包不加载 → 形象列表里没有深深,
|
|
6
|
+
* 用户还以为可以再建一个(于是出现"重复创建"的错觉)。
|
|
7
|
+
*
|
|
8
|
+
* node test_manifest.mjs
|
|
9
|
+
*/
|
|
10
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { dirname, join } from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import { checkManifest } from './manifest-check.mjs';
|
|
14
|
+
|
|
15
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const fails = [];
|
|
17
|
+
const check = (fn, msg) => { try { fn(); console.log('ok ' + msg); } catch (e) { fails.push(`${msg} → ${e.message}`); console.log('FAIL ' + msg); } };
|
|
18
|
+
|
|
19
|
+
const root = join(here, '_tmp-manifest');
|
|
20
|
+
rmSync(root, { recursive: true, force: true });
|
|
21
|
+
|
|
22
|
+
const writePack = (name, fig) => {
|
|
23
|
+
const dir = join(root, name);
|
|
24
|
+
mkdirSync(dir, { recursive: true });
|
|
25
|
+
writeFileSync(join(dir, 'figure.json'), JSON.stringify(fig, null, 2), 'utf8');
|
|
26
|
+
writeFileSync(join(dir, 'figure.js'), 'export {};', 'utf8');
|
|
27
|
+
return dir;
|
|
28
|
+
};
|
|
29
|
+
const base = { manifest: 2, api: 2, id: 'shenshen-actions', name: { zh: '深深' }, about: { zh: 'x' }, entry: 'figure.js', export: 'createActionBody' };
|
|
30
|
+
|
|
31
|
+
/* ① 我们自带的 figure.json 必须合规 */
|
|
32
|
+
check(() => {
|
|
33
|
+
const errs = checkManifest(join(here, '..', 'assets', 'starter', 'figure'));
|
|
34
|
+
if (errs.length) throw new Error(errs.join(';'));
|
|
35
|
+
}, '插件自带 figure.json 符合宿主清单规则');
|
|
36
|
+
|
|
37
|
+
/* ② 没 pick 的预设会被抓出来(就是这次线上事故) */
|
|
38
|
+
check(() => {
|
|
39
|
+
const dir = writePack('no-pick', { ...base, presets: [{ id: 'teal', console: { light: {}, dark: {} } }] });
|
|
40
|
+
const errs = checkManifest(dir);
|
|
41
|
+
if (!errs.some((e) => /preset "teal" 缺 pick/.test(e))) throw new Error('没识别出缺 pick:' + errs.join(';'));
|
|
42
|
+
}, '缺 pick 的预设被判为不合法(线上事故的复现)');
|
|
43
|
+
|
|
44
|
+
/* ③ pick 要覆盖每个 axis,且值必须是该 axis 的 option */
|
|
45
|
+
check(() => {
|
|
46
|
+
const withAxis = {
|
|
47
|
+
...base,
|
|
48
|
+
axes: [{ id: 'look', name: { zh: '样子' }, options: [{ id: 'a', name: { zh: 'A' } }, { id: 'b', name: { zh: 'B' } }] }],
|
|
49
|
+
};
|
|
50
|
+
const dir = writePack('pick-missing-axis', { ...withAxis, presets: [{ id: 'p1', pick: {} }] });
|
|
51
|
+
const errs = checkManifest(dir);
|
|
52
|
+
if (!errs.some((e) => /没给 axis "look"/.test(e))) throw new Error('没识别出 pick 缺 axis:' + errs.join(';'));
|
|
53
|
+
|
|
54
|
+
const okDir = writePack('pick-ok', { ...withAxis, presets: [{ id: 'p1', pick: { look: 'a' } }] });
|
|
55
|
+
const errs2 = checkManifest(okDir);
|
|
56
|
+
if (errs2.length) throw new Error('合法预设被判错:' + errs2.join(';'));
|
|
57
|
+
}, 'pick 必须覆盖每个 axis 并取合法 option');
|
|
58
|
+
|
|
59
|
+
/* ④ console 调色板要齐全(light/dark × a,a2,on,t,c3,c4) */
|
|
60
|
+
check(() => {
|
|
61
|
+
const dir = writePack('console-bad', { ...base, presets: [{ id: 'p2', pick: {}, console: { light: { a: '#000000' }, dark: {} } }] });
|
|
62
|
+
const errs = checkManifest(dir);
|
|
63
|
+
if (!errs.some((e) => /console\.light\.a2/.test(e))) throw new Error('没识别出配色字段缺失:' + errs.join(';'));
|
|
64
|
+
}, 'console 调色板缺字段会被抓出来');
|
|
65
|
+
|
|
66
|
+
/* ⑤ 合法包(带 console 预设)应当通过 */
|
|
67
|
+
check(() => {
|
|
68
|
+
const preset = {
|
|
69
|
+
id: 'teal', pick: {},
|
|
70
|
+
name: { zh: '深深 · 青绿' }, accent: '#0b7a5a',
|
|
71
|
+
console: {
|
|
72
|
+
light: { a: '#0b7a5a', a2: '#0f9d76', on: '#ffffff', t: '#0b6b4f', c3: '#3f8f78', c4: '#8a8a90' },
|
|
73
|
+
dark: { a: '#2fd3a0', a2: '#7fe6c2', on: '#062a20', t: '#8ae8c6', c3: '#5fbfa0', c4: '#9a9aa0' },
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
const dir = writePack('good', { ...base, presets: [preset] });
|
|
77
|
+
const errs = checkManifest(dir);
|
|
78
|
+
if (errs.length) throw new Error(errs.join(';'));
|
|
79
|
+
}, '带 console 预设的合法包通过校验');
|
|
80
|
+
|
|
81
|
+
/* ⑥ 迁移会补 pick(老包里的坏预设) */
|
|
82
|
+
{
|
|
83
|
+
const { ensureConsolePreset } = await import('../src/starter.js');
|
|
84
|
+
const dir = writePack('migrate', { ...base, presets: [{ id: 'teal', console: { light: {}, dark: {} } }] });
|
|
85
|
+
const before = checkManifest(dir);
|
|
86
|
+
if (!before.some((e) => /缺 pick/.test(e))) throw new Error('夹具应该是坏的');
|
|
87
|
+
ensureConsolePreset(dir);
|
|
88
|
+
const after = checkManifest(dir);
|
|
89
|
+
check(() => { if (after.some((e) => /缺 pick/.test(e))) throw new Error('迁移没补上 pick'); }, '迁移会给老预设补上 pick');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
rmSync(root, { recursive: true, force: true });
|
|
93
|
+
console.log(fails.length ? `\nFAIL (${fails.length})\n- ${fails.join('\n- ')}` : '\nall checks passed');
|
|
94
|
+
process.exit(fails.length ? 1 : 0);
|