@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,447 @@
|
|
|
1
|
+
import {
|
|
2
|
+
castModelProblems,
|
|
3
|
+
castProblems,
|
|
4
|
+
castWarnings,
|
|
5
|
+
checkAfterLoad,
|
|
6
|
+
castSideProblems,
|
|
7
|
+
checkAutoLayout,
|
|
8
|
+
checkChapters,
|
|
9
|
+
checkCommandDefaults,
|
|
10
|
+
checkDraftStarts,
|
|
11
|
+
checkEndings,
|
|
12
|
+
checkExtra,
|
|
13
|
+
checkFormat,
|
|
14
|
+
checkItems,
|
|
15
|
+
checkProject,
|
|
16
|
+
checkProjectRules,
|
|
17
|
+
checkScreenTemplates,
|
|
18
|
+
checkSeverityConfig,
|
|
19
|
+
checkSound,
|
|
20
|
+
checkTones,
|
|
21
|
+
checkNvlStyles,
|
|
22
|
+
checkTranslation,
|
|
23
|
+
dataTranslatables,
|
|
24
|
+
checkUnusedSpeakersConfig,
|
|
25
|
+
checkUi,
|
|
26
|
+
checkUiCss,
|
|
27
|
+
checkVerticalFont,
|
|
28
|
+
checkVoiceLock,
|
|
29
|
+
configTargets,
|
|
30
|
+
configValueProblems,
|
|
31
|
+
encodingDiagnostic,
|
|
32
|
+
missingAssets,
|
|
33
|
+
parse,
|
|
34
|
+
placeConfigLines,
|
|
35
|
+
projectMacros,
|
|
36
|
+
promisedTargets,
|
|
37
|
+
readConfigJson,
|
|
38
|
+
soundStarts,
|
|
39
|
+
suppressDiagnostics,
|
|
40
|
+
targetCandidates,
|
|
41
|
+
unusedSpeakersConfig,
|
|
42
|
+
VARIABLE_KEY,
|
|
43
|
+
type Cast,
|
|
44
|
+
type ChapterInfo,
|
|
45
|
+
type Diagnostic,
|
|
46
|
+
type ExtraConfig,
|
|
47
|
+
type JsonSchema,
|
|
48
|
+
type PluginScreens,
|
|
49
|
+
type ProjectTextSource,
|
|
50
|
+
type ProjectFiles,
|
|
51
|
+
type ScreenTemplateRules,
|
|
52
|
+
type PunctuationConfig,
|
|
53
|
+
type ProjectFileCheckCache,
|
|
54
|
+
type Registry,
|
|
55
|
+
type Script,
|
|
56
|
+
type TargetHook,
|
|
57
|
+
type UiConfig,
|
|
58
|
+
type VoiceLock,
|
|
59
|
+
} from "@liminalia/lang";
|
|
60
|
+
import { declaredData, pluginDataCg } from "./data.ts";
|
|
61
|
+
import { pluginWrittenVariables, runPluginChecks, type CommandPlugin } from "./plugin.ts";
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* パック(packs/<フォルダ>/)の台本と訳の中身(@liminalia/project の listPackSources が読むもの)。
|
|
65
|
+
* dir は作品のフォルダからのパス、speakers はパックの cast.json の話者、scripts は台本の名前 → 中身、translations は言語 → 訳のファイルの中身。
|
|
66
|
+
*/
|
|
67
|
+
export interface PackCheckSource {
|
|
68
|
+
dir: string;
|
|
69
|
+
/** 遊ぶ側の並び(pack.json の order、id)。渡す並びもこの順にする(listPackSources の順)。 */
|
|
70
|
+
id?: string;
|
|
71
|
+
order?: number;
|
|
72
|
+
speakers: readonly string[];
|
|
73
|
+
scripts: ReadonlyMap<string, string>;
|
|
74
|
+
translations: ReadonlyMap<string, string>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 読み解いたパック(台本は、本体の話者にパックの cast.json の話者を足して読む。遊ぶ側はパックの cast.json で本体のものを差し替える)。 */
|
|
78
|
+
export interface ParsedPack {
|
|
79
|
+
dir: string;
|
|
80
|
+
scripts: Map<string, Script>;
|
|
81
|
+
translations: ReadonlyMap<string, string>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* その言語の訳のファイル(owner が無ければ本体の lang、あればそのパックの lang)と一緒に遊ばれるパックの台本。遊ぶ側は、入っているパックのうち
|
|
86
|
+
* 並びの最後でその言語の訳を持つもの(無ければ本体)の訳を、すべての台本に使う。遊ぶ人はパックのどの組み合わせでも入れうるので、
|
|
87
|
+
* その訳が使われる組み合わせ(owner を入れ、owner より後ろで訳を持つパックを入れない組)のどれかで出る台本を shown にする
|
|
88
|
+
* (組み合わせを並べずに、台本の持ち主と owner だけを入れた組で決める。パックの数によらずすべての組み合わせと同じ結果)。
|
|
89
|
+
* - shown: この訳で出るパックの台本(訳し漏れにも数える)。本体の訳なら、その言語の訳を持たないパック。パックの訳なら、訳を持たないパックと、
|
|
90
|
+
* 並びがそのパックより前で訳を持つパック。どちらも、並びがそのパックより前のパックの台本は、そのパックが同じ名前の台本で差し替えるものを除く
|
|
91
|
+
* - used: この訳では出ないが、使われているに数えるパックの台本(どの組み合わせで入っても訳を消さないよう、広めに数える)
|
|
92
|
+
*/
|
|
93
|
+
export function packTranslationScope(packs: readonly ParsedPack[], language: string, owner?: ParsedPack): { alsoShown: Map<string, Script>[]; alsoUsedBy: Map<string, Script>[] } {
|
|
94
|
+
const at = owner ? packs.indexOf(owner) : -1;
|
|
95
|
+
const alsoShown: Map<string, Script>[] = [];
|
|
96
|
+
const alsoUsedBy: Map<string, Script>[] = [];
|
|
97
|
+
packs.forEach((p, i) => {
|
|
98
|
+
if (p === owner) return;
|
|
99
|
+
const own = p.translations.has(language);
|
|
100
|
+
if (owner && i < at) {
|
|
101
|
+
// owner より前のパックの台本は、owner を一緒に入れたときにだけこの訳で出る。owner が同じ名前の台本を持てば、いつも差し替えられて出ない
|
|
102
|
+
const hidden = new Map([...p.scripts].filter(([name]) => owner.scripts.has(name)));
|
|
103
|
+
const shown = new Map([...p.scripts].filter(([name]) => !owner.scripts.has(name)));
|
|
104
|
+
if (shown.size > 0) alsoShown.push(shown);
|
|
105
|
+
if (hidden.size > 0) alsoUsedBy.push(hidden);
|
|
106
|
+
} else if (!own) alsoShown.push(p.scripts);
|
|
107
|
+
else alsoUsedBy.push(p.scripts);
|
|
108
|
+
});
|
|
109
|
+
return { alsoShown, alsoUsedBy };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** パックの台本を読み解く(検査、lim voice-lock と制作画面の「番号を固定」、lim i18n が同じ読み方をする)。 */
|
|
113
|
+
export function parsePacks(packs: readonly PackCheckSource[], speakers: readonly string[]): ParsedPack[] {
|
|
114
|
+
return packs.map((p) => {
|
|
115
|
+
const said = [...new Set([...speakers, ...p.speakers])];
|
|
116
|
+
return { dir: p.dir, scripts: new Map([...p.scripts].map(([name, text]) => [name, parse(text, name, { speakers: said })])), translations: p.translations };
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 作品全体の検査(lim check、制作画面のチェック、VS Code の拡張、MCP の check_text が同じ入力から同じ一覧を作る)。
|
|
122
|
+
* ファイルは読まない。読んだもの(台本、設定の字面、訳のファイル、素材の有無など)と読む口を呼ぶ側が渡す。
|
|
123
|
+
* checkProject などに渡す入力(台本の外から指すジャンプ先、commandDefaults で使うマクロ、変数、プラグインが値を入れる変数)も、
|
|
124
|
+
* 訳の検査と書式の版の検査も、ここで一度だけ組み立てる。呼ぶ側で足したり省いたりすると、同じ作品に違う結果が出る。
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
/** 検査に使う liminalia.json の項目(読み解いたもの。@liminalia/project の ProjectConfig をそのまま渡せる)。 */
|
|
128
|
+
export interface ProjectCheckConfig {
|
|
129
|
+
entry?: unknown;
|
|
130
|
+
afterLoad?: unknown;
|
|
131
|
+
extra?: unknown;
|
|
132
|
+
variables?: unknown;
|
|
133
|
+
commandDefaults?: unknown;
|
|
134
|
+
chapters?: unknown;
|
|
135
|
+
ui?: unknown;
|
|
136
|
+
items?: unknown;
|
|
137
|
+
scenes?: unknown;
|
|
138
|
+
languages?: unknown;
|
|
139
|
+
allowScript?: unknown;
|
|
140
|
+
format?: unknown;
|
|
141
|
+
title?: unknown;
|
|
142
|
+
endingKinds?: unknown;
|
|
143
|
+
autoLayout?: unknown;
|
|
144
|
+
playtest?: unknown;
|
|
145
|
+
/** プロジェクトのプラグイン(cast.json の model を描くものがあるかの見分けに使う)。 */
|
|
146
|
+
plugins?: unknown;
|
|
147
|
+
check?: { punctuation?: unknown; severity?: unknown; variables?: unknown; rules?: unknown; sound?: unknown; unusedSpeakers?: unknown } | undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface ProjectCheckInput {
|
|
151
|
+
/** 作品のフォルダ(プラグインの check に渡す)。 */
|
|
152
|
+
root: string;
|
|
153
|
+
/** 台本(ファイル名 → 構文木と字面。名前の順)。 */
|
|
154
|
+
files: ReadonlyMap<string, { script: Script; text: string }>;
|
|
155
|
+
/** liminalia.json(読み解いたもの)と、その字面(無い・読めないなら null。JSON の誤りの位置、型に無い項目、項目の行に使う)。 */
|
|
156
|
+
config: ProjectCheckConfig;
|
|
157
|
+
configText: string | null;
|
|
158
|
+
/** cast.json の cast と speakers、その字面(無ければ null)。 */
|
|
159
|
+
cast: Readonly<Record<string, unknown>>;
|
|
160
|
+
speakers: readonly string[];
|
|
161
|
+
castText: string | null;
|
|
162
|
+
/** 診断に書く cast.json の名前(作品のフォルダからのパス。既定 cast.json)。 */
|
|
163
|
+
castFile?: string;
|
|
164
|
+
/**
|
|
165
|
+
* 設定の JSON Schema(読めない環境では null。型に無い項目を見ない)。null の項目は、JSON として読めない所だけを知らせる
|
|
166
|
+
* (VS Code は liminalia.json と cast.json の型をエディタの JSON の検証に任せる)。
|
|
167
|
+
*/
|
|
168
|
+
schemas?: { liminalia?: JsonSchema | null; cast?: JsonSchema | null; lang?: JsonSchema | null };
|
|
169
|
+
/** 命令の仕様(作品の既定値 commandDefaults を重ねたもの)と、重ねる前のもの(既定値そのものの検査に使う)。 */
|
|
170
|
+
registry: Registry;
|
|
171
|
+
baseRegistry?: Registry;
|
|
172
|
+
/** 読み込んだプラグイン(標準の命令も)。命令の教えるジャンプ先、値を入れる変数、データの CG、プラグインの check に使う。 */
|
|
173
|
+
plugins: readonly CommandPlugin[];
|
|
174
|
+
/** 作品のデータ(paths.data の .json)を名前で読む口と、その字面(診断の行)。 */
|
|
175
|
+
data: (name: string) => unknown;
|
|
176
|
+
dataText?: (name: string) => string | undefined;
|
|
177
|
+
/** 診断に書くデータのフォルダの名前(作品のフォルダからのパス。既定 data)。 */
|
|
178
|
+
dataFolder?: string;
|
|
179
|
+
/** 原文以外の言語の訳のファイルの字面(無ければ null)。liminalia.json の languages の 2 番目からの順。 */
|
|
180
|
+
translations: readonly { language: string; text: string | null }[];
|
|
181
|
+
/**
|
|
182
|
+
* 素材の有無(無ければ素材の実在を見ない)。actual は大文字と小文字の違いを見る(@liminalia/lang の assetNameResolver)。
|
|
183
|
+
* head は素材のファイルの頭(Git LFS のポインタのままの素材を見分ける。@liminalia/project の assetHeads)。
|
|
184
|
+
*/
|
|
185
|
+
assets?: {
|
|
186
|
+
exists: (folder: string, path: string) => boolean;
|
|
187
|
+
files?: (folder: string) => readonly string[] | undefined;
|
|
188
|
+
actual?: (folder: string, path: string) => string | null | undefined;
|
|
189
|
+
head?: (folder: string, path: string) => Uint8Array | null | undefined;
|
|
190
|
+
} | null;
|
|
191
|
+
/** voice-lock.json の字面(無ければ null)。 */
|
|
192
|
+
voiceLockText?: string | null;
|
|
193
|
+
/**
|
|
194
|
+
* パック(packs/<フォルダ>/。@liminalia/project の listPackSources)。パックの台本だけが使う訳の鍵とボイスの番号の固定を「使われていない」にせず、
|
|
195
|
+
* パックの訳(packs/<フォルダ>/lang/<言語>.json)を、本体にパックを重ねた台本で確かめる。無ければパックを見ない。
|
|
196
|
+
*/
|
|
197
|
+
packs?: readonly PackCheckSource[];
|
|
198
|
+
/**
|
|
199
|
+
* 作品のフォルダの中のファイルを読む口(作品の CSS ui.css と、その中の url() と @import の検査。パスは作品のフォルダからの / 区切り)。
|
|
200
|
+
* 無ければ作品の CSS を見ない。
|
|
201
|
+
*/
|
|
202
|
+
projectFiles?: ProjectFiles | null;
|
|
203
|
+
/** 素材の others のフォントを読む口(縦書きの字送り幅の検査。無ければ見ない)。 */
|
|
204
|
+
readFont?: (file: string) => Uint8Array | null;
|
|
205
|
+
/** UTF-8 で読めない台本(ファイル → 文字コードの名前)。そのファイルは bad-encoding だけにする。 */
|
|
206
|
+
encodings?: ReadonlyMap<string, string>;
|
|
207
|
+
/**
|
|
208
|
+
* 作品の画面のテンプレート(liminalia.json の ui.templates)の検査に使うもの(これか projectFiles が無ければ見ない)。rules は標準の画面の決まり
|
|
209
|
+
* (@liminalia/web/screen-rules の screenTemplateRules)、plugins はプラグインの "./web" が差し替える画面
|
|
210
|
+
* (@liminalia/project/screen-templates の pluginScreens)。テンプレートのファイルは projectFiles で読む(作品の CSS と同じ読み方)。
|
|
211
|
+
*/
|
|
212
|
+
screenTemplates?: { rules: ScreenTemplateRules; plugins?: readonly PluginScreens[] } | null;
|
|
213
|
+
/** 呼ぶ側だけが分かる診断(プラグインの package.json の合うエンジンの宣言など)。 */
|
|
214
|
+
more?: readonly Diagnostic[];
|
|
215
|
+
/**
|
|
216
|
+
* 黙らせる(// lim-ignore と check.severity)前に一覧を整える口。syntax は構文の診断(台本の解析が出したもの)。
|
|
217
|
+
* 制作画面が分類を付け、読み込めなかったプラグインの命令の指摘をまとめるのに使う。
|
|
218
|
+
*/
|
|
219
|
+
adjust?: (diagnostics: Diagnostic[], syntax: ReadonlySet<Diagnostic>) => Diagnostic[];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** プラグインの命令が教える行き先(制作画面のフローチャートと同じ)。 */
|
|
223
|
+
export function pluginTargetHooks(plugins: readonly CommandPlugin[]): Map<string, TargetHook> {
|
|
224
|
+
const hooks = new Map<string, TargetHook>();
|
|
225
|
+
for (const p of plugins) for (const c of p.commands ?? []) if (typeof c.targets === "function") hooks.set(c.name, c.targets.bind(c));
|
|
226
|
+
return hooks;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** liminalia.json の variables のうち、使える名前のもの(configValueProblems が知らせたものは使わない。loadProject と同じ)。 */
|
|
230
|
+
function usableVariables(raw: unknown): Record<string, unknown> | undefined {
|
|
231
|
+
if (raw === undefined || !raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
|
|
232
|
+
return Object.fromEntries(Object.entries(raw as Record<string, unknown>).filter(([key]) => VARIABLE_KEY.test(key)));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* cast.json の model の種類を描くプラグインがあるか。読み込んだプラグインの名前が種類と同じか、liminalia.json の plugins に
|
|
237
|
+
* その種類の公式のプラグイン(`plugins/live2d`、`liminalia-live2d` など。制作画面のキャラクターの画面と同じ見分け方)を書いたもの。
|
|
238
|
+
*/
|
|
239
|
+
function modelAvailable(plugins: readonly CommandPlugin[], configured: unknown): (type: string) => boolean {
|
|
240
|
+
const names = new Set(plugins.map((p) => p.name));
|
|
241
|
+
const specs = Array.isArray(configured) ? configured.filter((s): s is string => typeof s === "string").map((s) => s.replace(/\/+$/, "")) : [];
|
|
242
|
+
return (type) => names.has(type) || specs.some((s) => s === type || s.endsWith(`/${type}`) || s === `liminalia-${type}` || s.endsWith(`/liminalia-${type}`));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* 多言語の訳のファイル(原文以外の言語)。無いものは警告(その言語では原文を出す)。
|
|
247
|
+
* 本体の訳はパックに訳が無ければパックの台本にも使われるので、パックの台本だけが使う訳も使われているに数える(packTranslationScope)。
|
|
248
|
+
* パックの訳(packs/<フォルダ>/lang/<言語>.json。あるものだけ)は、パックを入れると本体の訳と丸ごと入れ替わり本体の台本にも使われるので、
|
|
249
|
+
* 本体にそのパックを重ねた台本(同じ名前の台本はパックのもの)で確かめる。訳を持たないパックの台本は、一緒に入れればこの訳で出るので訳し漏れにも数える。
|
|
250
|
+
*/
|
|
251
|
+
function checkLanguages(input: ProjectCheckInput, scripts: ReadonlyMap<string, Script>, packs: readonly ParsedPack[]): Diagnostic[] {
|
|
252
|
+
const out: Diagnostic[] = [];
|
|
253
|
+
const sources = { registry: input.registry, project: input.config as ProjectTextSource, data: dataTranslatables(declaredData(input.plugins, (n) => input.data(n))) };
|
|
254
|
+
const check = (text: string, name: string, own: ReadonlyMap<string, Script>, scope: ReturnType<typeof packTranslationScope>) => {
|
|
255
|
+
// 読めない所は行と桁で、知らない項目は近い名前の案つきで知らせる
|
|
256
|
+
const read = readConfigJson(text, name, input.schemas?.lang ?? null, "bad-translation");
|
|
257
|
+
out.push(...read.diagnostics);
|
|
258
|
+
if (read.value !== undefined) out.push(...checkTranslation(read.value, name, own, { ...sources, ...(scope.alsoShown.length > 0 ? { alsoShown: scope.alsoShown } : {}), ...(scope.alsoUsedBy.length > 0 ? { alsoUsedBy: scope.alsoUsedBy } : {}) }));
|
|
259
|
+
};
|
|
260
|
+
for (const { language, text } of input.translations) {
|
|
261
|
+
const name = `lang/${language}.json`;
|
|
262
|
+
if (text === null) {
|
|
263
|
+
out.push({ severity: "warning", code: "missing-translation", message: `${language} の翻訳ファイルがありません(その言語では原文を表示します)`, file: name, line: 1, hint: `lim i18n ${language} で作成できます` });
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
check(text, name, scripts, packTranslationScope(packs, language));
|
|
267
|
+
}
|
|
268
|
+
for (const pack of packs) {
|
|
269
|
+
for (const { language } of input.translations) {
|
|
270
|
+
const text = pack.translations.get(language);
|
|
271
|
+
if (text === undefined) continue;
|
|
272
|
+
check(text, `${pack.dir}/lang/${language}.json`, new Map([...scripts, ...pack.scripts]), packTranslationScope(packs, language, pack));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return out;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** 連番のボイスの番号の固定(voice-lock.json があるときだけ)。パックの台詞も本体の固定を使うので、パックの台本も数える。 */
|
|
279
|
+
function voiceLockDiagnostics(input: ProjectCheckInput, scripts: ReadonlyMap<string, Script>, packs: readonly ParsedPack[]): Diagnostic[] {
|
|
280
|
+
if (input.voiceLockText === null || input.voiceLockText === undefined) return [];
|
|
281
|
+
const read = readConfigJson(input.voiceLockText, "voice-lock.json", null, "bad-voice-lock");
|
|
282
|
+
if (read.diagnostics.length > 0) return read.diagnostics.slice(0, 1);
|
|
283
|
+
const assets = input.assets;
|
|
284
|
+
// 大文字と小文字の違う名前のボイスも、無いものとして数える(Linux のサーバーやスマホでは鳴らない)
|
|
285
|
+
const exists = (folder: string, path: string) => {
|
|
286
|
+
if (!assets) return true;
|
|
287
|
+
const real = assets.actual?.(folder, path);
|
|
288
|
+
return real === undefined ? assets.exists(folder, path) : real === path;
|
|
289
|
+
};
|
|
290
|
+
const entry = typeof input.config.entry === "string" ? input.config.entry : undefined;
|
|
291
|
+
return checkVoiceLock(read.value as VoiceLock, scripts, exists, { entry, packs: packs.map((p) => p.scripts) });
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 作品全体の診断(lim check が出すもの。並びは集めた順。呼ぶ側が並べる)。台本の // lim-ignore と liminalia.json の check.severity を当て、
|
|
296
|
+
* 設定のファイルの診断は誤りのある項目の行に出す。
|
|
297
|
+
*/
|
|
298
|
+
export function projectDiagnostics(input: ProjectCheckInput, cache?: ProjectFileCheckCache): Diagnostic[] {
|
|
299
|
+
const { config, registry, plugins } = input;
|
|
300
|
+
const scripts = new Map<string, Script>();
|
|
301
|
+
const syntax = new Set<Diagnostic>();
|
|
302
|
+
for (const [file, { script }] of input.files) {
|
|
303
|
+
scripts.set(file, script);
|
|
304
|
+
for (const d of script.diagnostics) syntax.add(d);
|
|
305
|
+
}
|
|
306
|
+
const castFile = input.castFile ?? "cast.json";
|
|
307
|
+
const castNames = new Set(Object.keys(input.cast));
|
|
308
|
+
// cast.json の形が崩れていれば、そのキャラクターは名前だけ確かめる(立ち絵セット、差分、立ち位置は見ない)
|
|
309
|
+
const problems = castProblems(input.cast);
|
|
310
|
+
const broken = new Set(problems.map((p) => p.who));
|
|
311
|
+
const castEntries = Object.fromEntries(Object.entries(input.cast as Cast).filter(([who]) => !broken.has(who)));
|
|
312
|
+
const variables = usableVariables(config.variables);
|
|
313
|
+
const check = config.check ?? {};
|
|
314
|
+
const ui = config.ui as UiConfig | undefined;
|
|
315
|
+
const extra = config.extra as ExtraConfig | undefined;
|
|
316
|
+
// プラグインの命令が教える行き先(使われないラベルと、音の抜けの検査が流れをたどるのに使う)
|
|
317
|
+
const promised = promisedTargets({ scripts: input.files, registry, hooks: pluginTargetHooks(plugins), data: input.data });
|
|
318
|
+
const out: Diagnostic[] = [];
|
|
319
|
+
// 設定の JSON: 読めない所の行と桁、型に無い項目(ui の知らない項目は checkUi が知らせる)、使わずに続けた項目の値
|
|
320
|
+
if (input.configText !== null) {
|
|
321
|
+
const read = readConfigJson(input.configText, "liminalia.json", input.schemas?.liminalia ?? null, "bad-config", ["ui"]);
|
|
322
|
+
out.push(...read.diagnostics);
|
|
323
|
+
if (read.value !== undefined) out.push(...configValueProblems(read.value, input.configText));
|
|
324
|
+
}
|
|
325
|
+
if (input.castText !== null) out.push(...readConfigJson(input.castText, castFile, input.schemas?.cast ?? null).diagnostics);
|
|
326
|
+
// 台本の書式の版(format)がこのエンジンより新しいか
|
|
327
|
+
out.push(...checkFormat(config.format));
|
|
328
|
+
out.push(
|
|
329
|
+
...problems.map((p): Diagnostic => ({ severity: "error", code: "bad-cast", message: p.message, file: castFile, line: 1, ...(p.hint ? { hint: p.hint } : {}), cast: { who: p.who } })),
|
|
330
|
+
// 自動配置の定位置(side)の誤り。立ち絵の検査は続ける(castProblems と違い、その人物を壊れたものとして外さない)
|
|
331
|
+
...castSideProblems(input.cast).map((p): Diagnostic => ({ severity: "error", code: "bad-cast", message: p.message, file: castFile, line: 1, hint: p.hint, cast: { who: p.who } })),
|
|
332
|
+
...castWarnings(castEntries).map(
|
|
333
|
+
(w): Diagnostic => ({ 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 } : {}) } }),
|
|
334
|
+
),
|
|
335
|
+
// model(Live2D、Spine など)を描くプラグイン。読み込んだプラグインの名前か、liminalia.json の plugins に書いたもの(読み込めないときは plugin-load が知らせる)
|
|
336
|
+
...castModelProblems(castEntries, modelAvailable(plugins, config.plugins)).map(
|
|
337
|
+
(p): Diagnostic => ({ severity: "warning", code: "model-plugin-missing", message: p.message, file: castFile, line: 1, hint: p.hint, cast: { who: p.who } }),
|
|
338
|
+
),
|
|
339
|
+
);
|
|
340
|
+
out.push(
|
|
341
|
+
...checkProject(scripts, {
|
|
342
|
+
registry,
|
|
343
|
+
cast: castNames,
|
|
344
|
+
castEntries,
|
|
345
|
+
speakers: input.speakers,
|
|
346
|
+
allowScript: config.allowScript === true,
|
|
347
|
+
punctuation: check.punctuation as PunctuationConfig | undefined,
|
|
348
|
+
sourceLanguage: Array.isArray(config.languages) && typeof config.languages[0] === "string" ? config.languages[0] : undefined,
|
|
349
|
+
...(variables ? { variables } : {}),
|
|
350
|
+
// プラグインが値を入れる変数とデータのフラグ(変数の綴り違いの検査で、値の入る変数に数える)
|
|
351
|
+
writtenVariables: pluginWrittenVariables(plugins, input.data),
|
|
352
|
+
// 台本の外から指すジャンプ先(entry、回想、プラグインのデータの行き先)と、commandDefaults で使うマクロ
|
|
353
|
+
references: [...configTargets(config), ...[...promised.values()].flat()],
|
|
354
|
+
usedMacros: config.commandDefaults && typeof config.commandDefaults === "object" ? Object.keys(config.commandDefaults) : [],
|
|
355
|
+
...(check.variables === "declared" ? { variableCheck: "declared" as const } : {}),
|
|
356
|
+
// 章の扉に出すものが無い所と、章に入っていないシナリオ
|
|
357
|
+
chapters: config.chapters,
|
|
358
|
+
// 使われなくても知らせない話者(先の話で使う人物など)
|
|
359
|
+
unusedSpeakers: unusedSpeakersConfig(check.unusedSpeakers),
|
|
360
|
+
}, cache),
|
|
361
|
+
);
|
|
362
|
+
// 設定から始める位置が下書きのファイルを指していないか(書き出しに入らない)
|
|
363
|
+
out.push(...checkDraftStarts(config, scripts));
|
|
364
|
+
out.push(...checkCommandDefaults(config.commandDefaults, input.baseRegistry ?? registry, castNames, projectMacros(scripts)));
|
|
365
|
+
out.push(...checkExtra(config.extra, scripts, registry, config.chapters as ChapterInfo[] | undefined, pluginDataCg(plugins, input.data)));
|
|
366
|
+
out.push(...checkChapters(config.chapters, scripts.keys()));
|
|
367
|
+
// 立ち絵の登場順の自動配置の並べ方(形と、立ち絵の枠に無い立ち位置の名前)
|
|
368
|
+
out.push(...checkAutoLayout(config.autoLayout, input.cast));
|
|
369
|
+
// エンディングの種類(ending= の種類、前の書き方の文言、endingKinds、避ける指定、実績の endings、式の endings())
|
|
370
|
+
out.push(...checkEndings({ scripts, registry, endingKinds: config.endingKinds, format: config.format, playtest: config.playtest, extra: config.extra }));
|
|
371
|
+
out.push(...checkAfterLoad(config.afterLoad, scripts));
|
|
372
|
+
// ゲームの設定(ui)の形と色調、持ち物
|
|
373
|
+
out.push(...checkUi(ui), ...checkTones(scripts, ui), ...checkNvlStyles(scripts, ui), ...checkItems(config.items, scripts));
|
|
374
|
+
// 作品の CSS(ui.css。無いファイル、読めない CSS、url() の無い素材と作品の外を指すもの)
|
|
375
|
+
if (input.projectFiles) out.push(...checkUiCss(ui, input.projectFiles));
|
|
376
|
+
// 作品の画面のテンプレート(無いファイル、知らない画面と部品と値、要る data-role、外されるもの、古い版、プラグインの screens.* に隠れたもの)
|
|
377
|
+
const files = input.projectFiles;
|
|
378
|
+
if (input.screenTemplates && files && ui && typeof ui === "object") {
|
|
379
|
+
const preset = (ui as { system?: { preset?: unknown } }).system?.preset;
|
|
380
|
+
out.push(
|
|
381
|
+
...checkScreenTemplates({
|
|
382
|
+
templates: (ui as { templates?: unknown }).templates,
|
|
383
|
+
rules: input.screenTemplates.rules,
|
|
384
|
+
read: (file) => files.text(file),
|
|
385
|
+
...(input.screenTemplates.plugins ? { plugins: input.screenTemplates.plugins } : {}),
|
|
386
|
+
...(typeof preset === "string" ? { preset } : {}),
|
|
387
|
+
}),
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
// 作品の演出の決まり(check.rules)と場面の情報(scenes)
|
|
391
|
+
out.push(...checkProjectRules({ rules: check.rules, scenes: config.scenes, scripts, registry, cast: castEntries, ...(extra ? { extra } : {}) }));
|
|
392
|
+
out.push(...checkSeverityConfig(check.severity), ...checkUnusedSpeakersConfig(check.unusedSpeakers, input.speakers));
|
|
393
|
+
// 音の抜け(無音の長い区間、空振りの停止、ファイルをまたぐループ。check.sound)
|
|
394
|
+
out.push(...checkSound({ scripts, registry, config: check.sound, ...soundStarts(config), promised, candidates: targetCandidates(scripts, { registry, ...(variables ? { variables } : {}) }) }));
|
|
395
|
+
// パック(訳とボイスの鍵が使われているかと、パックの訳)
|
|
396
|
+
const packs = parsePacks(input.packs ?? [], input.speakers);
|
|
397
|
+
out.push(...checkLanguages(input, scripts, packs));
|
|
398
|
+
out.push(...voiceLockDiagnostics(input, scripts, packs));
|
|
399
|
+
if (input.readFont) out.push(...checkVerticalFont(ui, [...input.files.values()].map((f) => f.text), input.readFont));
|
|
400
|
+
const assets = input.assets;
|
|
401
|
+
if (assets) {
|
|
402
|
+
out.push(
|
|
403
|
+
...missingAssets({
|
|
404
|
+
scripts,
|
|
405
|
+
registry,
|
|
406
|
+
cast: input.cast,
|
|
407
|
+
castFile,
|
|
408
|
+
extra,
|
|
409
|
+
items: config.items,
|
|
410
|
+
ui,
|
|
411
|
+
exists: assets.exists,
|
|
412
|
+
...(assets.files ? { files: assets.files } : {}),
|
|
413
|
+
...(assets.actual ? { actual: assets.actual } : {}),
|
|
414
|
+
...(assets.head ? { head: assets.head } : {}),
|
|
415
|
+
}),
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
// プラグインの check(投げても止まらず、そのプラグインの診断になる。設定は呼ぶ側が使い回すことがあるので写しを渡す)
|
|
419
|
+
out.push(
|
|
420
|
+
...runPluginChecks(plugins, {
|
|
421
|
+
root: input.root,
|
|
422
|
+
config: structuredClone(config) as Record<string, unknown>,
|
|
423
|
+
scripts,
|
|
424
|
+
text: (file) => input.files.get(file)?.text ?? "",
|
|
425
|
+
cast: input.cast as Cast,
|
|
426
|
+
speakers: input.speakers,
|
|
427
|
+
registry,
|
|
428
|
+
data: input.data,
|
|
429
|
+
...(input.dataText ? { dataText: input.dataText } : {}),
|
|
430
|
+
dataFolder: input.dataFolder ?? "data",
|
|
431
|
+
assetExists: assets ? assets.exists : () => true,
|
|
432
|
+
}),
|
|
433
|
+
);
|
|
434
|
+
out.push(...(input.more ?? []));
|
|
435
|
+
// UTF-8 で読めない台本(Shift_JIS など)は bad-encoding だけにし、化けた中身からの診断は出さない
|
|
436
|
+
let list: Diagnostic[] = out;
|
|
437
|
+
if (input.encodings && input.encodings.size > 0) {
|
|
438
|
+
list = [...out.filter((d) => !input.encodings!.has(d.file)), ...[...input.encodings].map(([file, encoding]) => encodingDiagnostic(file, encoding))];
|
|
439
|
+
}
|
|
440
|
+
if (input.adjust) list = input.adjust(list, syntax);
|
|
441
|
+
// 台本の // lim-ignore と check.severity(警告と情報だけ。何も黙らせない lim-ignore は情報で知らせる)
|
|
442
|
+
let kept: Diagnostic[] = suppressDiagnostics(list, { scripts, severity: check.severity, reportUnused: true, externalCodes: new Set(["text-overflow"]) });
|
|
443
|
+
// 設定の形の誤りは、1 行目でなく誤りのある項目の行に出す
|
|
444
|
+
if (input.configText !== null) kept = placeConfigLines(kept, input.configText, "liminalia.json");
|
|
445
|
+
if (input.castText !== null) kept = placeConfigLines(kept, input.castText, castFile);
|
|
446
|
+
return kept;
|
|
447
|
+
}
|
package/src/state.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Value } from "@liminalia/runtime";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 型の付いたプラグインの状態(セーブに入る stage.extra の一つの鍵)。命令の apply・run と、描画側の renderers・restorers の両方から同じ形で読み書きする。
|
|
5
|
+
* ```ts
|
|
6
|
+
* interface Stamps { list: { image: string; x: number }[] }
|
|
7
|
+
* export const stamps = defineState<Stamps>("stamp.list", () => ({ list: [] }));
|
|
8
|
+
* // 命令: apply(args, extra) { stamps.update(extra, (s) => { s.list.push({ image: String(args.image), x: Number(args.x) }); }); }
|
|
9
|
+
* // 描画: restorers: [(ctx, stage) => draw(stamps.read(stage.extra))]
|
|
10
|
+
* ```
|
|
11
|
+
* 値は JSON にできる素の値だけにする(関数・Map・Date・undefined は入れない)。鍵はプラグインの名前を頭に付けて、ほかと重ならないようにする。
|
|
12
|
+
* `as unknown as Value` と書かずに済むように、読み書きの型をここで合わせる(中身の形までは確かめない。古いセーブの形を直すなら read の後で直す)。
|
|
13
|
+
*/
|
|
14
|
+
export interface PluginState<T> {
|
|
15
|
+
/** stage.extra の鍵。 */
|
|
16
|
+
readonly key: string;
|
|
17
|
+
/** 今の値(無ければ undefined)。 */
|
|
18
|
+
get(extra: Readonly<Record<string, Value>>): T | undefined;
|
|
19
|
+
/** 今の値(無ければ初めの値。初めの値を渡していなければ undefined で、そのとき T は undefined を含む)。返したものを書き換えても状態は変わらない(update で書く)。 */
|
|
20
|
+
read(extra: Readonly<Record<string, Value>>): T;
|
|
21
|
+
/** 値を入れる(写しを入れる)。 */
|
|
22
|
+
set(extra: Record<string, Value>, value: T): void;
|
|
23
|
+
/** 今の値(無ければ初めの値)の写しを change で書き換えて入れ、入れた値を返す。change が値を返せばそれを入れる。 */
|
|
24
|
+
update(extra: Record<string, Value>, change: (value: T) => T | void): T;
|
|
25
|
+
/** 鍵ごと消す(空になったら消すとセーブが小さくなる)。 */
|
|
26
|
+
clear(extra: Record<string, Value>): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 型の付いたプラグインの状態を作る。initial は値が無いときの初めの値(呼ぶたびに新しく作る)。
|
|
31
|
+
* initial を渡さなければ、値が無いとき read と update は undefined を渡すので、型も T | undefined になる。
|
|
32
|
+
*/
|
|
33
|
+
export function defineState<T>(key: string, initial: () => T): PluginState<T>;
|
|
34
|
+
export function defineState<T>(key: string): PluginState<T | undefined>;
|
|
35
|
+
export function defineState<T>(key: string, initial?: () => T): PluginState<T> {
|
|
36
|
+
const copy = (v: T): T => (v === undefined || v === null || typeof v !== "object" ? v : (structuredClone(v) as T));
|
|
37
|
+
const fresh = (): T => (initial ? initial() : (undefined as T));
|
|
38
|
+
return {
|
|
39
|
+
key,
|
|
40
|
+
get: (extra) => (Object.hasOwn(extra, key) ? (extra[key] as unknown as T) : undefined),
|
|
41
|
+
read: (extra) => (Object.hasOwn(extra, key) ? copy(extra[key] as unknown as T) : fresh()),
|
|
42
|
+
set: (extra, value) => {
|
|
43
|
+
if (value === undefined) delete extra[key];
|
|
44
|
+
else extra[key] = copy(value) as unknown as Value;
|
|
45
|
+
},
|
|
46
|
+
update: (extra, change) => {
|
|
47
|
+
const current = Object.hasOwn(extra, key) ? copy(extra[key] as unknown as T) : fresh();
|
|
48
|
+
const result = change(current);
|
|
49
|
+
const next = (result === undefined ? current : result) as T;
|
|
50
|
+
if (next === undefined) delete extra[key];
|
|
51
|
+
else extra[key] = next as unknown as Value;
|
|
52
|
+
return next;
|
|
53
|
+
},
|
|
54
|
+
clear: (extra) => {
|
|
55
|
+
delete extra[key];
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|