@liminalia/sdk 0.0.0-stage → 0.8.4
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/LICENSE +21 -0
- package/dist/src/command.js +85 -0
- package/dist/src/data.js +91 -0
- package/dist/src/index.js +10 -0
- package/dist/src/plugin.js +364 -0
- package/dist/src/project-check.js +266 -0
- package/dist/src/state.js +28 -0
- package/package.json +34 -4
- package/src/command.ts +195 -0
- package/src/data.ts +99 -0
- package/src/index.ts +10 -0
- package/src/plugin.ts +424 -0
- package/src/project-check.ts +447 -0
- package/src/state.ts +58 -0
- package/types/src/command.d.ts +166 -0
- package/types/src/data.d.ts +92 -0
- package/types/src/index.d.ts +7 -0
- package/types/src/plugin.d.ts +134 -0
- package/types/src/project-check.d.ts +162 -0
- package/types/src/state.d.ts +32 -0
- package/README.md +0 -3
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { castModelProblems, castProblems, castWarnings, checkAfterLoad, castSideProblems, checkAutoLayout, checkChapters, checkCommandDefaults, checkDraftStarts, checkEndings, checkExtra, checkFormat, checkItems, checkProject, checkProjectRules, checkScreenTemplates, checkSeverityConfig, checkSound, checkTones, checkNvlStyles, checkTranslation, dataTranslatables, checkUnusedSpeakersConfig, checkUi, checkUiCss, checkVerticalFont, checkVoiceLock, configTargets, configValueProblems, encodingDiagnostic, missingAssets, parse, placeConfigLines, projectMacros, promisedTargets, readConfigJson, soundStarts, suppressDiagnostics, targetCandidates, unusedSpeakersConfig, VARIABLE_KEY, } from "@liminalia/lang";
|
|
2
|
+
import { declaredData, pluginDataCg } from "./data.js";
|
|
3
|
+
import { pluginWrittenVariables, runPluginChecks } from "./plugin.js";
|
|
4
|
+
/**
|
|
5
|
+
* その言語の訳のファイル(owner が無ければ本体の lang、あればそのパックの lang)と一緒に遊ばれるパックの台本。遊ぶ側は、入っているパックのうち
|
|
6
|
+
* 並びの最後でその言語の訳を持つもの(無ければ本体)の訳を、すべての台本に使う。遊ぶ人はパックのどの組み合わせでも入れうるので、
|
|
7
|
+
* その訳が使われる組み合わせ(owner を入れ、owner より後ろで訳を持つパックを入れない組)のどれかで出る台本を shown にする
|
|
8
|
+
* (組み合わせを並べずに、台本の持ち主と owner だけを入れた組で決める。パックの数によらずすべての組み合わせと同じ結果)。
|
|
9
|
+
* - shown: この訳で出るパックの台本(訳し漏れにも数える)。本体の訳なら、その言語の訳を持たないパック。パックの訳なら、訳を持たないパックと、
|
|
10
|
+
* 並びがそのパックより前で訳を持つパック。どちらも、並びがそのパックより前のパックの台本は、そのパックが同じ名前の台本で差し替えるものを除く
|
|
11
|
+
* - used: この訳では出ないが、使われているに数えるパックの台本(どの組み合わせで入っても訳を消さないよう、広めに数える)
|
|
12
|
+
*/
|
|
13
|
+
export function packTranslationScope(packs, language, owner) {
|
|
14
|
+
const at = owner ? packs.indexOf(owner) : -1;
|
|
15
|
+
const alsoShown = [];
|
|
16
|
+
const alsoUsedBy = [];
|
|
17
|
+
packs.forEach((p, i) => {
|
|
18
|
+
if (p === owner)
|
|
19
|
+
return;
|
|
20
|
+
const own = p.translations.has(language);
|
|
21
|
+
if (owner && i < at) {
|
|
22
|
+
// owner より前のパックの台本は、owner を一緒に入れたときにだけこの訳で出る。owner が同じ名前の台本を持てば、いつも差し替えられて出ない
|
|
23
|
+
const hidden = new Map([...p.scripts].filter(([name]) => owner.scripts.has(name)));
|
|
24
|
+
const shown = new Map([...p.scripts].filter(([name]) => !owner.scripts.has(name)));
|
|
25
|
+
if (shown.size > 0)
|
|
26
|
+
alsoShown.push(shown);
|
|
27
|
+
if (hidden.size > 0)
|
|
28
|
+
alsoUsedBy.push(hidden);
|
|
29
|
+
}
|
|
30
|
+
else if (!own)
|
|
31
|
+
alsoShown.push(p.scripts);
|
|
32
|
+
else
|
|
33
|
+
alsoUsedBy.push(p.scripts);
|
|
34
|
+
});
|
|
35
|
+
return { alsoShown, alsoUsedBy };
|
|
36
|
+
}
|
|
37
|
+
/** パックの台本を読み解く(検査、lim voice-lock と制作画面の「番号を固定」、lim i18n が同じ読み方をする)。 */
|
|
38
|
+
export function parsePacks(packs, speakers) {
|
|
39
|
+
return packs.map((p) => {
|
|
40
|
+
const said = [...new Set([...speakers, ...p.speakers])];
|
|
41
|
+
return { dir: p.dir, scripts: new Map([...p.scripts].map(([name, text]) => [name, parse(text, name, { speakers: said })])), translations: p.translations };
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** プラグインの命令が教える行き先(制作画面のフローチャートと同じ)。 */
|
|
45
|
+
export function pluginTargetHooks(plugins) {
|
|
46
|
+
const hooks = new Map();
|
|
47
|
+
for (const p of plugins)
|
|
48
|
+
for (const c of p.commands ?? [])
|
|
49
|
+
if (typeof c.targets === "function")
|
|
50
|
+
hooks.set(c.name, c.targets.bind(c));
|
|
51
|
+
return hooks;
|
|
52
|
+
}
|
|
53
|
+
/** liminalia.json の variables のうち、使える名前のもの(configValueProblems が知らせたものは使わない。loadProject と同じ)。 */
|
|
54
|
+
function usableVariables(raw) {
|
|
55
|
+
if (raw === undefined || !raw || typeof raw !== "object" || Array.isArray(raw))
|
|
56
|
+
return undefined;
|
|
57
|
+
return Object.fromEntries(Object.entries(raw).filter(([key]) => VARIABLE_KEY.test(key)));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* cast.json の model の種類を描くプラグインがあるか。読み込んだプラグインの名前が種類と同じか、liminalia.json の plugins に
|
|
61
|
+
* その種類の公式のプラグイン(`plugins/live2d`、`liminalia-live2d` など。制作画面のキャラクターの画面と同じ見分け方)を書いたもの。
|
|
62
|
+
*/
|
|
63
|
+
function modelAvailable(plugins, configured) {
|
|
64
|
+
const names = new Set(plugins.map((p) => p.name));
|
|
65
|
+
const specs = Array.isArray(configured) ? configured.filter((s) => typeof s === "string").map((s) => s.replace(/\/+$/, "")) : [];
|
|
66
|
+
return (type) => names.has(type) || specs.some((s) => s === type || s.endsWith(`/${type}`) || s === `liminalia-${type}` || s.endsWith(`/liminalia-${type}`));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 多言語の訳のファイル(原文以外の言語)。無いものは警告(その言語では原文を出す)。
|
|
70
|
+
* 本体の訳はパックに訳が無ければパックの台本にも使われるので、パックの台本だけが使う訳も使われているに数える(packTranslationScope)。
|
|
71
|
+
* パックの訳(packs/<フォルダ>/lang/<言語>.json。あるものだけ)は、パックを入れると本体の訳と丸ごと入れ替わり本体の台本にも使われるので、
|
|
72
|
+
* 本体にそのパックを重ねた台本(同じ名前の台本はパックのもの)で確かめる。訳を持たないパックの台本は、一緒に入れればこの訳で出るので訳し漏れにも数える。
|
|
73
|
+
*/
|
|
74
|
+
function checkLanguages(input, scripts, packs) {
|
|
75
|
+
const out = [];
|
|
76
|
+
const sources = { registry: input.registry, project: input.config, data: dataTranslatables(declaredData(input.plugins, (n) => input.data(n))) };
|
|
77
|
+
const check = (text, name, own, scope) => {
|
|
78
|
+
// 読めない所は行と桁で、知らない項目は近い名前の案つきで知らせる
|
|
79
|
+
const read = readConfigJson(text, name, input.schemas?.lang ?? null, "bad-translation");
|
|
80
|
+
out.push(...read.diagnostics);
|
|
81
|
+
if (read.value !== undefined)
|
|
82
|
+
out.push(...checkTranslation(read.value, name, own, { ...sources, ...(scope.alsoShown.length > 0 ? { alsoShown: scope.alsoShown } : {}), ...(scope.alsoUsedBy.length > 0 ? { alsoUsedBy: scope.alsoUsedBy } : {}) }));
|
|
83
|
+
};
|
|
84
|
+
for (const { language, text } of input.translations) {
|
|
85
|
+
const name = `lang/${language}.json`;
|
|
86
|
+
if (text === null) {
|
|
87
|
+
out.push({ severity: "warning", code: "missing-translation", message: `${language} の翻訳ファイルがありません(その言語では原文を表示します)`, file: name, line: 1, hint: `lim i18n ${language} で作成できます` });
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
check(text, name, scripts, packTranslationScope(packs, language));
|
|
91
|
+
}
|
|
92
|
+
for (const pack of packs) {
|
|
93
|
+
for (const { language } of input.translations) {
|
|
94
|
+
const text = pack.translations.get(language);
|
|
95
|
+
if (text === undefined)
|
|
96
|
+
continue;
|
|
97
|
+
check(text, `${pack.dir}/lang/${language}.json`, new Map([...scripts, ...pack.scripts]), packTranslationScope(packs, language, pack));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
/** 連番のボイスの番号の固定(voice-lock.json があるときだけ)。パックの台詞も本体の固定を使うので、パックの台本も数える。 */
|
|
103
|
+
function voiceLockDiagnostics(input, scripts, packs) {
|
|
104
|
+
if (input.voiceLockText === null || input.voiceLockText === undefined)
|
|
105
|
+
return [];
|
|
106
|
+
const read = readConfigJson(input.voiceLockText, "voice-lock.json", null, "bad-voice-lock");
|
|
107
|
+
if (read.diagnostics.length > 0)
|
|
108
|
+
return read.diagnostics.slice(0, 1);
|
|
109
|
+
const assets = input.assets;
|
|
110
|
+
// 大文字と小文字の違う名前のボイスも、無いものとして数える(Linux のサーバーやスマホでは鳴らない)
|
|
111
|
+
const exists = (folder, path) => {
|
|
112
|
+
if (!assets)
|
|
113
|
+
return true;
|
|
114
|
+
const real = assets.actual?.(folder, path);
|
|
115
|
+
return real === undefined ? assets.exists(folder, path) : real === path;
|
|
116
|
+
};
|
|
117
|
+
const entry = typeof input.config.entry === "string" ? input.config.entry : undefined;
|
|
118
|
+
return checkVoiceLock(read.value, scripts, exists, { entry, packs: packs.map((p) => p.scripts) });
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 作品全体の診断(lim check が出すもの。並びは集めた順。呼ぶ側が並べる)。台本の // lim-ignore と liminalia.json の check.severity を当て、
|
|
122
|
+
* 設定のファイルの診断は誤りのある項目の行に出す。
|
|
123
|
+
*/
|
|
124
|
+
export function projectDiagnostics(input, cache) {
|
|
125
|
+
const { config, registry, plugins } = input;
|
|
126
|
+
const scripts = new Map();
|
|
127
|
+
const syntax = new Set();
|
|
128
|
+
for (const [file, { script }] of input.files) {
|
|
129
|
+
scripts.set(file, script);
|
|
130
|
+
for (const d of script.diagnostics)
|
|
131
|
+
syntax.add(d);
|
|
132
|
+
}
|
|
133
|
+
const castFile = input.castFile ?? "cast.json";
|
|
134
|
+
const castNames = new Set(Object.keys(input.cast));
|
|
135
|
+
// cast.json の形が崩れていれば、そのキャラクターは名前だけ確かめる(立ち絵セット、差分、立ち位置は見ない)
|
|
136
|
+
const problems = castProblems(input.cast);
|
|
137
|
+
const broken = new Set(problems.map((p) => p.who));
|
|
138
|
+
const castEntries = Object.fromEntries(Object.entries(input.cast).filter(([who]) => !broken.has(who)));
|
|
139
|
+
const variables = usableVariables(config.variables);
|
|
140
|
+
const check = config.check ?? {};
|
|
141
|
+
const ui = config.ui;
|
|
142
|
+
const extra = config.extra;
|
|
143
|
+
// プラグインの命令が教える行き先(使われないラベルと、音の抜けの検査が流れをたどるのに使う)
|
|
144
|
+
const promised = promisedTargets({ scripts: input.files, registry, hooks: pluginTargetHooks(plugins), data: input.data });
|
|
145
|
+
const out = [];
|
|
146
|
+
// 設定の JSON: 読めない所の行と桁、型に無い項目(ui の知らない項目は checkUi が知らせる)、使わずに続けた項目の値
|
|
147
|
+
if (input.configText !== null) {
|
|
148
|
+
const read = readConfigJson(input.configText, "liminalia.json", input.schemas?.liminalia ?? null, "bad-config", ["ui"]);
|
|
149
|
+
out.push(...read.diagnostics);
|
|
150
|
+
if (read.value !== undefined)
|
|
151
|
+
out.push(...configValueProblems(read.value, input.configText));
|
|
152
|
+
}
|
|
153
|
+
if (input.castText !== null)
|
|
154
|
+
out.push(...readConfigJson(input.castText, castFile, input.schemas?.cast ?? null).diagnostics);
|
|
155
|
+
// 台本の書式の版(format)がこのエンジンより新しいか
|
|
156
|
+
out.push(...checkFormat(config.format));
|
|
157
|
+
out.push(...problems.map((p) => ({ severity: "error", code: "bad-cast", message: p.message, file: castFile, line: 1, ...(p.hint ? { hint: p.hint } : {}), cast: { who: p.who } })),
|
|
158
|
+
// 自動配置の定位置(side)の誤り。立ち絵の検査は続ける(castProblems と違い、その人物を壊れたものとして外さない)
|
|
159
|
+
...castSideProblems(input.cast).map((p) => ({ severity: "error", code: "bad-cast", message: p.message, file: castFile, line: 1, hint: p.hint, cast: { who: p.who } })), ...castWarnings(castEntries).map((w) => ({ severity: "warning", code: "cast-ambiguous", message: w.message, file: castFile, line: 1, hint: w.hint, cast: { who: w.who, ...(w.appearance ? { appearance: w.appearance } : {}), ...(w.kind ? { kind: w.kind } : {}) } })),
|
|
160
|
+
// model(Live2D、Spine など)を描くプラグイン。読み込んだプラグインの名前か、liminalia.json の plugins に書いたもの(読み込めないときは plugin-load が知らせる)
|
|
161
|
+
...castModelProblems(castEntries, modelAvailable(plugins, config.plugins)).map((p) => ({ severity: "warning", code: "model-plugin-missing", message: p.message, file: castFile, line: 1, hint: p.hint, cast: { who: p.who } })));
|
|
162
|
+
out.push(...checkProject(scripts, {
|
|
163
|
+
registry,
|
|
164
|
+
cast: castNames,
|
|
165
|
+
castEntries,
|
|
166
|
+
speakers: input.speakers,
|
|
167
|
+
allowScript: config.allowScript === true,
|
|
168
|
+
punctuation: check.punctuation,
|
|
169
|
+
sourceLanguage: Array.isArray(config.languages) && typeof config.languages[0] === "string" ? config.languages[0] : undefined,
|
|
170
|
+
...(variables ? { variables } : {}),
|
|
171
|
+
// プラグインが値を入れる変数とデータのフラグ(変数の綴り違いの検査で、値の入る変数に数える)
|
|
172
|
+
writtenVariables: pluginWrittenVariables(plugins, input.data),
|
|
173
|
+
// 台本の外から指すジャンプ先(entry、回想、プラグインのデータの行き先)と、commandDefaults で使うマクロ
|
|
174
|
+
references: [...configTargets(config), ...[...promised.values()].flat()],
|
|
175
|
+
usedMacros: config.commandDefaults && typeof config.commandDefaults === "object" ? Object.keys(config.commandDefaults) : [],
|
|
176
|
+
...(check.variables === "declared" ? { variableCheck: "declared" } : {}),
|
|
177
|
+
// 章の扉に出すものが無い所と、章に入っていないシナリオ
|
|
178
|
+
chapters: config.chapters,
|
|
179
|
+
// 使われなくても知らせない話者(先の話で使う人物など)
|
|
180
|
+
unusedSpeakers: unusedSpeakersConfig(check.unusedSpeakers),
|
|
181
|
+
}, cache));
|
|
182
|
+
// 設定から始める位置が下書きのファイルを指していないか(書き出しに入らない)
|
|
183
|
+
out.push(...checkDraftStarts(config, scripts));
|
|
184
|
+
out.push(...checkCommandDefaults(config.commandDefaults, input.baseRegistry ?? registry, castNames, projectMacros(scripts)));
|
|
185
|
+
out.push(...checkExtra(config.extra, scripts, registry, config.chapters, pluginDataCg(plugins, input.data)));
|
|
186
|
+
out.push(...checkChapters(config.chapters, scripts.keys()));
|
|
187
|
+
// 立ち絵の登場順の自動配置の並べ方(形と、立ち絵の枠に無い立ち位置の名前)
|
|
188
|
+
out.push(...checkAutoLayout(config.autoLayout, input.cast));
|
|
189
|
+
// エンディングの種類(ending= の種類、前の書き方の文言、endingKinds、避ける指定、実績の endings、式の endings())
|
|
190
|
+
out.push(...checkEndings({ scripts, registry, endingKinds: config.endingKinds, format: config.format, playtest: config.playtest, extra: config.extra }));
|
|
191
|
+
out.push(...checkAfterLoad(config.afterLoad, scripts));
|
|
192
|
+
// ゲームの設定(ui)の形と色調、持ち物
|
|
193
|
+
out.push(...checkUi(ui), ...checkTones(scripts, ui), ...checkNvlStyles(scripts, ui), ...checkItems(config.items, scripts));
|
|
194
|
+
// 作品の CSS(ui.css。無いファイル、読めない CSS、url() の無い素材と作品の外を指すもの)
|
|
195
|
+
if (input.projectFiles)
|
|
196
|
+
out.push(...checkUiCss(ui, input.projectFiles));
|
|
197
|
+
// 作品の画面のテンプレート(無いファイル、知らない画面と部品と値、要る data-role、外されるもの、古い版、プラグインの screens.* に隠れたもの)
|
|
198
|
+
const files = input.projectFiles;
|
|
199
|
+
if (input.screenTemplates && files && ui && typeof ui === "object") {
|
|
200
|
+
const preset = ui.system?.preset;
|
|
201
|
+
out.push(...checkScreenTemplates({
|
|
202
|
+
templates: ui.templates,
|
|
203
|
+
rules: input.screenTemplates.rules,
|
|
204
|
+
read: (file) => files.text(file),
|
|
205
|
+
...(input.screenTemplates.plugins ? { plugins: input.screenTemplates.plugins } : {}),
|
|
206
|
+
...(typeof preset === "string" ? { preset } : {}),
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
// 作品の演出の決まり(check.rules)と場面の情報(scenes)
|
|
210
|
+
out.push(...checkProjectRules({ rules: check.rules, scenes: config.scenes, scripts, registry, cast: castEntries, ...(extra ? { extra } : {}) }));
|
|
211
|
+
out.push(...checkSeverityConfig(check.severity), ...checkUnusedSpeakersConfig(check.unusedSpeakers, input.speakers));
|
|
212
|
+
// 音の抜け(無音の長い区間、空振りの停止、ファイルをまたぐループ。check.sound)
|
|
213
|
+
out.push(...checkSound({ scripts, registry, config: check.sound, ...soundStarts(config), promised, candidates: targetCandidates(scripts, { registry, ...(variables ? { variables } : {}) }) }));
|
|
214
|
+
// パック(訳とボイスの鍵が使われているかと、パックの訳)
|
|
215
|
+
const packs = parsePacks(input.packs ?? [], input.speakers);
|
|
216
|
+
out.push(...checkLanguages(input, scripts, packs));
|
|
217
|
+
out.push(...voiceLockDiagnostics(input, scripts, packs));
|
|
218
|
+
if (input.readFont)
|
|
219
|
+
out.push(...checkVerticalFont(ui, [...input.files.values()].map((f) => f.text), input.readFont));
|
|
220
|
+
const assets = input.assets;
|
|
221
|
+
if (assets) {
|
|
222
|
+
out.push(...missingAssets({
|
|
223
|
+
scripts,
|
|
224
|
+
registry,
|
|
225
|
+
cast: input.cast,
|
|
226
|
+
castFile,
|
|
227
|
+
extra,
|
|
228
|
+
items: config.items,
|
|
229
|
+
ui,
|
|
230
|
+
exists: assets.exists,
|
|
231
|
+
...(assets.files ? { files: assets.files } : {}),
|
|
232
|
+
...(assets.actual ? { actual: assets.actual } : {}),
|
|
233
|
+
...(assets.head ? { head: assets.head } : {}),
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
// プラグインの check(投げても止まらず、そのプラグインの診断になる。設定は呼ぶ側が使い回すことがあるので写しを渡す)
|
|
237
|
+
out.push(...runPluginChecks(plugins, {
|
|
238
|
+
root: input.root,
|
|
239
|
+
config: structuredClone(config),
|
|
240
|
+
scripts,
|
|
241
|
+
text: (file) => input.files.get(file)?.text ?? "",
|
|
242
|
+
cast: input.cast,
|
|
243
|
+
speakers: input.speakers,
|
|
244
|
+
registry,
|
|
245
|
+
data: input.data,
|
|
246
|
+
...(input.dataText ? { dataText: input.dataText } : {}),
|
|
247
|
+
dataFolder: input.dataFolder ?? "data",
|
|
248
|
+
assetExists: assets ? assets.exists : () => true,
|
|
249
|
+
}));
|
|
250
|
+
out.push(...(input.more ?? []));
|
|
251
|
+
// UTF-8 で読めない台本(Shift_JIS など)は bad-encoding だけにし、化けた中身からの診断は出さない
|
|
252
|
+
let list = out;
|
|
253
|
+
if (input.encodings && input.encodings.size > 0) {
|
|
254
|
+
list = [...out.filter((d) => !input.encodings.has(d.file)), ...[...input.encodings].map(([file, encoding]) => encodingDiagnostic(file, encoding))];
|
|
255
|
+
}
|
|
256
|
+
if (input.adjust)
|
|
257
|
+
list = input.adjust(list, syntax);
|
|
258
|
+
// 台本の // lim-ignore と check.severity(警告と情報だけ。何も黙らせない lim-ignore は情報で知らせる)
|
|
259
|
+
let kept = suppressDiagnostics(list, { scripts, severity: check.severity, reportUnused: true, externalCodes: new Set(["text-overflow"]) });
|
|
260
|
+
// 設定の形の誤りは、1 行目でなく誤りのある項目の行に出す
|
|
261
|
+
if (input.configText !== null)
|
|
262
|
+
kept = placeConfigLines(kept, input.configText, "liminalia.json");
|
|
263
|
+
if (input.castText !== null)
|
|
264
|
+
kept = placeConfigLines(kept, input.castText, castFile);
|
|
265
|
+
return kept;
|
|
266
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function defineState(key, initial) {
|
|
2
|
+
const copy = (v) => (v === undefined || v === null || typeof v !== "object" ? v : structuredClone(v));
|
|
3
|
+
const fresh = () => (initial ? initial() : undefined);
|
|
4
|
+
return {
|
|
5
|
+
key,
|
|
6
|
+
get: (extra) => (Object.hasOwn(extra, key) ? extra[key] : undefined),
|
|
7
|
+
read: (extra) => (Object.hasOwn(extra, key) ? copy(extra[key]) : fresh()),
|
|
8
|
+
set: (extra, value) => {
|
|
9
|
+
if (value === undefined)
|
|
10
|
+
delete extra[key];
|
|
11
|
+
else
|
|
12
|
+
extra[key] = copy(value);
|
|
13
|
+
},
|
|
14
|
+
update: (extra, change) => {
|
|
15
|
+
const current = Object.hasOwn(extra, key) ? copy(extra[key]) : fresh();
|
|
16
|
+
const result = change(current);
|
|
17
|
+
const next = (result === undefined ? current : result);
|
|
18
|
+
if (next === undefined)
|
|
19
|
+
delete extra[key];
|
|
20
|
+
else
|
|
21
|
+
extra[key] = next;
|
|
22
|
+
return next;
|
|
23
|
+
},
|
|
24
|
+
clear: (extra) => {
|
|
25
|
+
delete extra[key];
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liminalia/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.8.4",
|
|
4
|
+
"description": "プラグインを書くための部品。命令を一つの表で定義し、仕様と実行時の処理を作る",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://liminalia.skyta.dev/",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/skyt-a/liminalia-sdk.git",
|
|
10
|
+
"directory": "packages/sdk"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./types/src/index.d.ts",
|
|
16
|
+
"node": "./dist/src/index.js",
|
|
17
|
+
"default": "./src/index.ts"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"src",
|
|
23
|
+
"types",
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": "^22.23.4 || ^24.22.1 || >=26.12.1"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@liminalia/lang": "0.8.4",
|
|
31
|
+
"@liminalia/runtime": "0.8.4"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/command.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { SKIP_PARAM, type CommandSpec, type Diagnostic, type ParamSpec, type ParamType } from "@liminalia/lang";
|
|
2
|
+
import type { Args, CommandContext, CommandImpl, Value } from "@liminalia/runtime";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* プラグインの命令の定義。この一つの表から
|
|
6
|
+
* - 命令の仕様(検査・補完・リファレンス)
|
|
7
|
+
* - 実行時の処理(状態の更新と描画側への通知)
|
|
8
|
+
* を作る。見た目はプラグインの描画側(WebPlugin の renderers)が担う。
|
|
9
|
+
* TyranoScript の .ks のタグからの変換は書き出すゲームに入れないので、ここには書かず、
|
|
10
|
+
* プラグインの "./import"(@liminalia/ks-import の TyranoImportProfile の mappings)に書く。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export interface ParamDefinition {
|
|
14
|
+
type: ParamType;
|
|
15
|
+
/**
|
|
16
|
+
* 既定値(.lim の書き方)。取り込み元の .ks のタグがあるなら、そのタグで省略したときの値と同じにしておく
|
|
17
|
+
* (取り込みは「.ks に書かれていた値のうち、既定値と違うもの」を書き出す)。
|
|
18
|
+
*/
|
|
19
|
+
default?: string;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
doc: string;
|
|
22
|
+
/** 英語の説明(任意。無ければ英語の表示でも doc を出す)。 */
|
|
23
|
+
docEn?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface CommandDefinition {
|
|
27
|
+
/** .lim の命令名。 */
|
|
28
|
+
name: string;
|
|
29
|
+
summary: string;
|
|
30
|
+
/** 英語の要約(任意。無ければ英語の表示でも summary を出す)。Studio と VS Code の英語表示、lim reference --lang en が読む。 */
|
|
31
|
+
summaryEn?: string;
|
|
32
|
+
positional?: string[];
|
|
33
|
+
/** 位置引数を埋めたあとの名前なしの値一つを受ける引数(名前を付けても書ける。対象を取らない命令の時間など)。 */
|
|
34
|
+
bare?: string;
|
|
35
|
+
params: Record<string, ParamDefinition>;
|
|
36
|
+
example: string;
|
|
37
|
+
/**
|
|
38
|
+
* 英語の例(任意。無ければ英語の表示でも example を出す)。例に人物の名前や見せる文字があるときに、それを英語にして書く。
|
|
39
|
+
* Studio と VS Code の英語表示、lim reference --lang en が読む。
|
|
40
|
+
*/
|
|
41
|
+
exampleEn?: string;
|
|
42
|
+
/**
|
|
43
|
+
* 引数に wait がないときに、演出の終わりを待つか。引数 wait を持つ命令は、省略するとその既定値になる。
|
|
44
|
+
* run で処理を差し替える命令も、ctx.present に渡す待ちと合わせて書く(制作画面の演出の流れとリファレンスが読む)。
|
|
45
|
+
*/
|
|
46
|
+
waits?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* この命令でプレイが終わる(タイトルへ戻る・ゲームを終えるなど。あとの行へは進まない)。制作画面の地図は、
|
|
49
|
+
* この命令で終わる場面を「終わり」にして、次の場面へ矢印を引かない(バッドエンドの場面などが別の枝として出る)。
|
|
50
|
+
*/
|
|
51
|
+
ends?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* 組み込みの命令か、先に読んだプラグイン(標準の命令 @liminalia/std など)の同じ名前の命令を、わざと置き換えるときに true。
|
|
54
|
+
* 書かずに同じ名前の命令を作ると、lim check と制作画面のチェックが警告する(plugin-replaces-command。標準の命令が増えて名前がぶつかったときに気づくため)。
|
|
55
|
+
*/
|
|
56
|
+
replaces?: boolean;
|
|
57
|
+
/** 制作画面のパーツの欄の区切り(screen・sprite・sound・motion・flow・system)。省くと「カスタムコマンド」に並ぶ。 */
|
|
58
|
+
category?: string;
|
|
59
|
+
/** やりたいことの言葉(「揺らす」「暗転」など)。パーツの欄で探すときと、AI が命令を選ぶときに使う。 */
|
|
60
|
+
keywords?: string[];
|
|
61
|
+
/** やりたいことの言葉の英語(任意。Studio の英語表示でパーツを探すとき)。 */
|
|
62
|
+
keywordsEn?: string[];
|
|
63
|
+
/**
|
|
64
|
+
* セーブに残す状態の更新(stage.extra を書き換える)。
|
|
65
|
+
* ロードしたとき描画側は stage.extra から画面を組み立て直す。
|
|
66
|
+
*/
|
|
67
|
+
apply?(args: Args, extra: Record<string, Value>): void;
|
|
68
|
+
/** 実行時の処理を丸ごと差し替える(結果を変数に入れる・飛ぶなど)。 */
|
|
69
|
+
run?(args: Args, ctx: CommandContext): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* 自動確認(lim playtest・lim shot・全ルートテスト)での進め方。人が操作せずに流すとき、ctx.present は描画側(renderers)に描かせずに
|
|
72
|
+
* これを呼び、返した値を描画側の答えの代わりにする(args は ctx.present に渡したもの)。遊ぶ人の操作を待つ画面(行き先を選ぶ地図、
|
|
73
|
+
* 調べる画面、ミニゲーム)や、飛ばしたい長い演出の命令に書く。
|
|
74
|
+
* 何も返さなければ答えなし。ctx.pick・ctx.choose で行き先を選ぶ命令は、ふつうの選択肢と同じく自動確認が選ぶ(lim playtest は
|
|
75
|
+
* 実行ごとに選び方を変え、--choose でも選べる)ので、`autoplay: () => undefined` だけでよい。ミニゲームの結果のように答えが要るなら、それを返す。
|
|
76
|
+
*/
|
|
77
|
+
autoplay?(args: Args, ctx: CommandContext): Value | void | Promise<Value | void>;
|
|
78
|
+
/**
|
|
79
|
+
* この命令が飛ぶかもしれない先(`#ラベル`・`ファイル`・`ファイル#ラベル`)。台本だけではわからない飛び先(作品のデータで
|
|
80
|
+
* 決まる選択など)を、制作画面の地図が矢印にするのに使う(実行には使わない)。args は台本に書いた値(書いたままの文字列。
|
|
81
|
+
* 位置引数も名前で引ける)、data は作品のデータ(paths.data の .json。無ければ undefined)を読む。
|
|
82
|
+
* leaves を true にすると、この命令のあとの行へは進まない(かならずどれかへ飛ぶ)とみなす。
|
|
83
|
+
*/
|
|
84
|
+
targets?(args: Readonly<Record<string, string>>, data: (name: string) => unknown): { targets: string[]; leaves?: boolean };
|
|
85
|
+
/**
|
|
86
|
+
* この命令の一行ごとの検査(lim check・lim build・制作画面のチェックが、台本のこの命令の行ごとに呼ぶ)。引数の型・必須・素材の実在など、
|
|
87
|
+
* 仕様(params)で決まることはエンジンが確かめるので、ここには引数どうしの組み合わせや作品のデータとの突き合わせを書く。
|
|
88
|
+
* args は台本に書いた値(書いたままの文字列。位置引数も名前で引ける。式で書いた引数は入らない)。返した診断の file・line を省くと、この行になる。
|
|
89
|
+
* 同期の関数で書く。投げてもチェックは止まらず、そのプラグインの診断になる。
|
|
90
|
+
*/
|
|
91
|
+
validate?(args: Readonly<Record<string, string>>, ctx: CommandValidateContext): readonly CommandDiagnostic[] | void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 命令の一行ごとの検査(CommandDefinition.validate)に渡すもの。 */
|
|
95
|
+
export interface CommandValidateContext {
|
|
96
|
+
/** 台本のファイル(拡張子なし)と行。 */
|
|
97
|
+
file: string;
|
|
98
|
+
line: number;
|
|
99
|
+
/** 作品のデータ(paths.data の .json。無ければ undefined)。 */
|
|
100
|
+
data(name: string): unknown;
|
|
101
|
+
/** 素材のフォルダ(image・bgimage など)の中にあるか。 */
|
|
102
|
+
assetExists(folder: string, path: string): boolean;
|
|
103
|
+
/** キャストにある名前か。 */
|
|
104
|
+
isCast(name: string): boolean;
|
|
105
|
+
/** 飛び先(`#ラベル`・`ファイル`・`ファイル#ラベル`)があるか(`#ラベル` はこの行のファイル)。 */
|
|
106
|
+
targetExists(target: string): boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 命令の一行ごとの検査が返す診断(file・line を省くとその行。code・message・severity は必ず書く)。 */
|
|
110
|
+
export type CommandDiagnostic = Pick<Diagnostic, "severity" | "code" | "message"> & Partial<Pick<Diagnostic, "messageEn" | "file" | "line" | "column" | "hint" | "hintEn" | "fix" | "fixes">>;
|
|
111
|
+
|
|
112
|
+
export function toSpec(c: CommandDefinition): CommandSpec {
|
|
113
|
+
const params: Record<string, ParamSpec> = {};
|
|
114
|
+
for (const [name, p] of Object.entries(c.params)) {
|
|
115
|
+
const spec: ParamSpec = { type: p.type, doc: p.doc };
|
|
116
|
+
if (p.docEn !== undefined) spec.docEn = p.docEn;
|
|
117
|
+
if (p.default !== undefined) spec.default = p.default;
|
|
118
|
+
if (p.required) spec.required = true;
|
|
119
|
+
params[name] = spec;
|
|
120
|
+
}
|
|
121
|
+
const waits = c.waits ?? c.params.wait?.default === "true";
|
|
122
|
+
return { name: c.name, summary: c.summary, ...(c.summaryEn ? { summaryEn: c.summaryEn } : {}), positional: c.positional ?? [], ...(c.bare ? { bare: c.bare } : {}), params, example: c.example, ...(c.exampleEn ? { exampleEn: c.exampleEn } : {}), ...(waits ? { waits } : {}), ...(c.ends ? { ends: true } : {}), ...(c.category ? { category: c.category } : {}), ...(c.keywords?.length ? { keywords: c.keywords } : {}), ...(c.keywordsEn?.length ? { keywordsEn: c.keywordsEn } : {}) };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function toImplementation(c: CommandDefinition): CommandImpl {
|
|
126
|
+
return {
|
|
127
|
+
spec: toSpec(c),
|
|
128
|
+
run: async (args, ctx) => {
|
|
129
|
+
if (c.run) return c.run(args, ctx);
|
|
130
|
+
c.apply?.(args, ctx.state.stage.extra);
|
|
131
|
+
await ctx.present(args, typeof args.wait === "boolean" ? args.wait : (c.waits ?? false));
|
|
132
|
+
},
|
|
133
|
+
...(c.autoplay ? { autoplay: c.autoplay } : {}),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const withDefault = (p: ParamDefinition, def: string | undefined): ParamDefinition => (def === undefined ? p : { ...p, default: def });
|
|
138
|
+
|
|
139
|
+
// 定義を短く書くための部品
|
|
140
|
+
export const t = {
|
|
141
|
+
/** suggest は入力の候補(制作画面で一覧から選べる。ほかの値も書ける)。 */
|
|
142
|
+
string: (doc: string, def?: string, suggest?: readonly string[]): ParamDefinition => {
|
|
143
|
+
const type = suggest ? { kind: "string" as const, suggest } : { kind: "string" as const };
|
|
144
|
+
return def === undefined ? { type, doc } : { type, default: def, doc };
|
|
145
|
+
},
|
|
146
|
+
/**
|
|
147
|
+
* プレイヤーに見せる文(章題・テロップ・ダイアログの文など)。多言語の作品では、台本に字面で書いた値が訳のファイル(lim i18n)に
|
|
148
|
+
* 「コマンドの文字」として並び、実行するときに遊んでいる言語の訳に替わる(訳が空なら原文のまま)。
|
|
149
|
+
*/
|
|
150
|
+
text: (doc: string, def?: string): ParamDefinition => {
|
|
151
|
+
const type = { kind: "string" as const, translate: "text" as const };
|
|
152
|
+
return def === undefined ? { type, doc } : { type, default: def, doc };
|
|
153
|
+
},
|
|
154
|
+
/** 人の名前(話者や相手の名前)。多言語の作品では、訳のファイルの speakers に並ぶ(訳して見せるのは命令の実装。ctx.runtime.translator?.speaker)。 */
|
|
155
|
+
name: (doc: string, def?: string): ParamDefinition => {
|
|
156
|
+
const type = { kind: "string" as const, translate: "name" as const };
|
|
157
|
+
return def === undefined ? { type, doc } : { type, default: def, doc };
|
|
158
|
+
},
|
|
159
|
+
/** 数。range の min・max を書くと、その外の値を lim check が知らせ、制作画面の欄もその幅にする。 */
|
|
160
|
+
number: (doc: string, def?: string, range: { min?: number; max?: number } = {}): ParamDefinition => withDefault({ type: { kind: "number", ...range }, doc }, def),
|
|
161
|
+
/** 整数。range は number と同じ。 */
|
|
162
|
+
int: (doc: string, def?: string, range: { min?: number; max?: number } = {}): ParamDefinition => withDefault({ type: { kind: "int", ...range }, doc }, def),
|
|
163
|
+
bool: (doc: string, def: boolean): ParamDefinition => ({ type: { kind: "bool" }, default: String(def), doc }),
|
|
164
|
+
duration: (doc: string, def?: string): ParamDefinition => (def === undefined ? { type: { kind: "duration" }, doc } : { type: { kind: "duration" }, default: def, doc }),
|
|
165
|
+
color: (doc: string, def?: string): ParamDefinition => (def === undefined ? { type: { kind: "color" }, doc } : { type: { kind: "color" }, default: def, doc }),
|
|
166
|
+
enum: (values: string[], doc: string, def?: string): ParamDefinition =>
|
|
167
|
+
def === undefined ? { type: { kind: "enum", values }, doc } : { type: { kind: "enum", values }, default: def, doc },
|
|
168
|
+
/**
|
|
169
|
+
* 素材のパス。cg を付けると、この素材を出したときに CG として解放する(liminalia.json の extra.cg か extra.cgAuto のフォルダにある画像なら。
|
|
170
|
+
* @bg と同じく、台本に @cg-unlock を書かなくてよい。章末の扉絵など、作品の命令で一枚絵を出すときに使う)。
|
|
171
|
+
*/
|
|
172
|
+
asset: (folder: string, doc: string, o: { cg?: boolean } = {}): ParamDefinition => ({ type: o.cg ? { kind: "asset", folder, cg: true } : { kind: "asset", folder }, doc }),
|
|
173
|
+
required: (p: ParamDefinition): ParamDefinition => ({ ...p, required: true }),
|
|
174
|
+
/** 値を入れる変数(`game.x`・`system.x`・`temp.x`)。命令の結果を受け取るときに。lim check が書き方を確かめ、値を入れる変数として数える。 */
|
|
175
|
+
variable: (doc: string, def?: string): ParamDefinition => withDefault({ type: { kind: "variable" }, doc }, def),
|
|
176
|
+
/** 飛び先(`#ラベル`・`ファイル`・`ファイル#ラベル`)。lim check がラベルとファイルの実在を確かめ、制作画面が候補を出し、地図が矢印を引く。 */
|
|
177
|
+
target: (doc: string, def?: string): ParamDefinition => withDefault({ type: { kind: "target" }, doc }, def),
|
|
178
|
+
/**
|
|
179
|
+
* キャストの名前。lim check がキャストにあるかを確かめ、制作画面が一覧から選ばせる。shown を付けると、表示中の立ち絵の人物に効く引数
|
|
180
|
+
* (消す、動かす、揺らす、漫符を付けるなど)として、制作画面の補完がその行で表示中の人物を上に並べる(ほかの人物も候補に残す。検査と実行は変わらない)。
|
|
181
|
+
*/
|
|
182
|
+
cast: (doc: string, def?: string, o: { shown?: boolean } = {}): ParamDefinition => withDefault({ type: o.shown ? { kind: "cast", shown: true } : { kind: "cast" }, doc }, def),
|
|
183
|
+
/** 条件。必ず式(`(…)`)で書き、実行するときに評価した真偽が渡る(@if と同じ)。 */
|
|
184
|
+
condition: (doc: string, def?: string): ParamDefinition => withDefault({ type: { kind: "condition" }, doc }, def),
|
|
185
|
+
/**
|
|
186
|
+
* 作品のデータの中の名前(file は paths.data の .json、path はその中の辞書か並びへの道。`places`・`maps/town/spots` のように / で区切る)。
|
|
187
|
+
* 辞書なら鍵、並びなら項目の id を名前とみなし、lim check が実在を確かめ、制作画面が候補を出す。
|
|
188
|
+
*/
|
|
189
|
+
dataKey: (file: string, path: string, doc: string, def?: string): ParamDefinition => withDefault({ type: { kind: "string", data: { file, path } }, doc }, def),
|
|
190
|
+
/**
|
|
191
|
+
* 演出をクリックで終わりまで飛ばせるか(skip。既定 true)。時間のかかる演出を出す命令に付ける。
|
|
192
|
+
* 描画側は何もしなくてよい(Element.animate の動きと ctx.delay の待ちは早送りで終わる。自分で動かす演出は ctx.onFastForward)。
|
|
193
|
+
*/
|
|
194
|
+
skip: (): ParamDefinition => ({ ...SKIP_PARAM }),
|
|
195
|
+
};
|
package/src/data.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { checkData, checkDataFlags, dataCgImages, dataTranslatables, scriptLabels, type DataDeclaration, type DataField, type DataText, type DeclaredData, type Diagnostic } from "@liminalia/lang";
|
|
2
|
+
import type { CommandPlugin, PluginCheckProject } from "./plugin.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* データの形の宣言を短く書く部品。プラグインの data に並べる。
|
|
6
|
+
* ```ts
|
|
7
|
+
* data: [{ file: "stamps.json", title: "スタンプ帳", root: d.map(d.record({ image: d.asset("image", "画像", { cg: true }), memo: d.text("メモ") })) }]
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
type Label = { label?: string; labelEn?: string; doc?: string; docEn?: string; required?: boolean };
|
|
11
|
+
const lab = (label?: string | Label): Label => (typeof label === "string" ? { label } : (label ?? {}));
|
|
12
|
+
|
|
13
|
+
export const d = {
|
|
14
|
+
/** 一行の文字。suggest は候補。translate なら遊ぶ人に見せる文で、lim i18n が訳のファイルに並べる(描画は dataText で訳を引く)。 */
|
|
15
|
+
string: (label?: string | Label, o: { suggest?: readonly string[]; translate?: boolean } = {}): DataField => ({ kind: "string", ...lab(label), ...o }),
|
|
16
|
+
/** 複数行の文字(本文・説明)。translate は string と同じ。 */
|
|
17
|
+
text: (label?: string | Label, o: { translate?: boolean } = {}): DataField => ({ kind: "string", multiline: true, ...lab(label), ...o }),
|
|
18
|
+
number: (label?: string | Label, o: { min?: number; max?: number } = {}): DataField => ({ kind: "number", ...lab(label), ...o }),
|
|
19
|
+
int: (label?: string | Label, o: { min?: number; max?: number } = {}): DataField => ({ kind: "int", ...lab(label), ...o }),
|
|
20
|
+
bool: (label?: string | Label): DataField => ({ kind: "bool", ...lab(label) }),
|
|
21
|
+
enum: (values: readonly string[], label?: string | Label): DataField => ({ kind: "enum", values, ...lab(label) }),
|
|
22
|
+
/**
|
|
23
|
+
* 素材。cg なら、プラグインがこの画像を CG として解放する(どこからも出ない CG の検査がこれを数える)。
|
|
24
|
+
* also は folder に無ければ探すほかのフォルダ(置き場所を替えた欄で、前の場所に置いた素材も読めるように。描画の側も同じ順に探す)。
|
|
25
|
+
*/
|
|
26
|
+
asset: (folder: string, label?: string | Label, o: { cg?: boolean; also?: readonly string[] } = {}): DataField => ({ kind: "asset", folder, ...lab(label), ...(o.cg ? { cg: true } : {}), ...(o.also?.length ? { also: o.also } : {}) }),
|
|
27
|
+
/** フラグ。use は、このデータでプラグインが立てる(set)か読む(read)か。 */
|
|
28
|
+
flag: (use: "set" | "read", label?: string | Label): DataField => ({ kind: "flag", use, ...lab(label) }),
|
|
29
|
+
/** 条件の式。 */
|
|
30
|
+
expr: (label?: string | Label): DataField => ({ kind: "expr", ...lab(label) }),
|
|
31
|
+
cast: (label?: string | Label): DataField => ({ kind: "cast", ...lab(label) }),
|
|
32
|
+
/** 飛び先。base は `#ラベル` のファイルを決める、外側の記録の欄の名前。 */
|
|
33
|
+
scene: (label?: string | Label, o: { base?: string; bare?: boolean } = {}): DataField => ({ kind: "scene", ...lab(label), ...o }),
|
|
34
|
+
file: (label?: string | Label): DataField => ({ kind: "file", ...lab(label) }),
|
|
35
|
+
/** 同じデータの中の名前(to は一覧の欄への道。`/entries`)。 */
|
|
36
|
+
ref: (to: string, label?: string | Label): DataField => ({ kind: "ref", to, ...lab(label) }),
|
|
37
|
+
/** 背景の上の矩形。image は背景の素材の欄の名前。 */
|
|
38
|
+
rect: (label?: string | Label, o: { image?: string } = {}): DataField => ({ kind: "rect", ...lab(label), ...o }),
|
|
39
|
+
/**
|
|
40
|
+
* 絵の上の点({ x, y }。既定は絵の左上からの割合 0〜100、unit が px なら舞台の px)。image は背景の素材の欄の名前(`ref の欄>素材の欄` なら ref が指す項目の欄)。
|
|
41
|
+
* keys を書くと、同じ記録の二つの欄(`["x", "y"]`)に置く(制作画面は絵を出して、押した所と引きずった所に点を置く)。
|
|
42
|
+
*/
|
|
43
|
+
point: (label?: string | Label, o: { image?: string; unit?: "percent" | "px"; keys?: readonly [string, string] } = {}): DataField => ({ kind: "point", ...lab(label), ...o }),
|
|
44
|
+
list: (of: DataField, label?: string | Label, o: { sortable?: boolean; key?: string } = {}): DataField => ({ kind: "list", of, ...lab(label), ...o }),
|
|
45
|
+
record: (fields: Record<string, DataField>, label?: string | Label, o: { title?: string } = {}): DataField => ({ kind: "record", fields, ...lab(label), ...o }),
|
|
46
|
+
map: (of: DataField, label?: string | Label): DataField => ({ kind: "map", of, ...lab(label) }),
|
|
47
|
+
json: (label?: string | Label): DataField => ({ kind: "json", ...lab(label) }),
|
|
48
|
+
/** 必須にする。 */
|
|
49
|
+
required: (f: DataField): DataField => ({ ...f, required: true }),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/** プラグインのデータの宣言(同じファイルは後のプラグインが勝つ)。 */
|
|
53
|
+
export function dataDeclarations(plugins: readonly CommandPlugin[]): DataDeclaration[] {
|
|
54
|
+
const byFile = new Map<string, DataDeclaration>();
|
|
55
|
+
for (const p of plugins) for (const decl of p.data ?? []) byFile.set(decl.file, decl);
|
|
56
|
+
return [...byFile.values()];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 宣言のあるデータのうち、作品にあるもの。 */
|
|
60
|
+
export function declaredData(plugins: readonly CommandPlugin[], read: (name: string) => unknown, text?: (name: string) => string | undefined): DeclaredData[] {
|
|
61
|
+
const out: DeclaredData[] = [];
|
|
62
|
+
for (const decl of dataDeclarations(plugins)) {
|
|
63
|
+
const value = read(decl.file);
|
|
64
|
+
if (value === undefined) continue;
|
|
65
|
+
const t = text?.(decl.file);
|
|
66
|
+
out.push({ decl, value, ...(t !== undefined ? { text: t } : {}) });
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 作品のデータの訳す文(宣言で translate の印の付いた欄。lim i18n と制作画面の訳の画面が updateTranslation の data に渡す)。 */
|
|
72
|
+
export function projectDataTexts(plugins: readonly CommandPlugin[], read: (name: string) => unknown): DataText[] {
|
|
73
|
+
return dataTranslatables(declaredData(plugins, read));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** プラグインが作品のデータから CG として解放する画像(`フォルダ/パス`)。checkExtra に渡す。 */
|
|
77
|
+
export function pluginDataCg(plugins: readonly CommandPlugin[], read: (name: string) => unknown): Set<string> {
|
|
78
|
+
return dataCgImages(declaredData(plugins, read));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** データの形の検査とフラグの突き合わせ(runPluginChecks が呼ぶ)。 */
|
|
82
|
+
export function checkDeclaredData(plugins: readonly CommandPlugin[], project: PluginCheckProject): Diagnostic[] {
|
|
83
|
+
const data = declaredData(plugins, (name) => project.data(name), project.dataText ? (name) => project.dataText!(name) : undefined);
|
|
84
|
+
if (data.length === 0) return [];
|
|
85
|
+
const folder = project.dataFolder ?? "data";
|
|
86
|
+
const fileName = (decl: DataDeclaration) => `${folder}/${decl.file}`;
|
|
87
|
+
const labels = scriptLabels(project.scripts);
|
|
88
|
+
const cast = new Set(Object.keys(project.cast));
|
|
89
|
+
const owner = new Map<string, string>();
|
|
90
|
+
for (const p of plugins) for (const decl of p.data ?? []) owner.set(decl.file, p.name);
|
|
91
|
+
const out: Diagnostic[] = [];
|
|
92
|
+
for (const x of data) {
|
|
93
|
+
const plugin = owner.get(x.decl.file);
|
|
94
|
+
for (const diag of checkData(x.decl, x.value, { fileName: fileName(x.decl), ...(x.text !== undefined ? { text: x.text } : {}), labels, assetExists: project.assetExists, cast })) out.push({ ...diag, ...(plugin ? { plugin } : {}) });
|
|
95
|
+
}
|
|
96
|
+
const variables = (project.config.variables ?? undefined) as Record<string, unknown> | undefined;
|
|
97
|
+
out.push(...checkDataFlags(data, project.scripts, project.registry, { fileName, ...(variables ? { variables } : {}) }));
|
|
98
|
+
return out;
|
|
99
|
+
}
|