@liminalia/runtime 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.
Files changed (57) hide show
  1. package/LICENSE +106 -0
  2. package/dist/src/chat.js +60 -0
  3. package/dist/src/commands-play.js +300 -0
  4. package/dist/src/commands.js +534 -0
  5. package/dist/src/coverage.js +208 -0
  6. package/dist/src/headless.js +109 -0
  7. package/dist/src/host.js +1 -0
  8. package/dist/src/index.js +15 -0
  9. package/dist/src/prefetch.js +80 -0
  10. package/dist/src/program.js +131 -0
  11. package/dist/src/project-options.js +84 -0
  12. package/dist/src/retranslate.js +44 -0
  13. package/dist/src/route.js +242 -0
  14. package/dist/src/runtime.js +1929 -0
  15. package/dist/src/save.js +51 -0
  16. package/dist/src/scenario-test.js +200 -0
  17. package/dist/src/state.js +62 -0
  18. package/dist/src/value.js +464 -0
  19. package/dist/src/voice-observe.js +82 -0
  20. package/package.json +33 -4
  21. package/src/chat.ts +109 -0
  22. package/src/commands-play.ts +280 -0
  23. package/src/commands.ts +457 -0
  24. package/src/coverage.ts +257 -0
  25. package/src/headless.ts +139 -0
  26. package/src/host.ts +116 -0
  27. package/src/index.ts +16 -0
  28. package/src/prefetch.ts +78 -0
  29. package/src/program.ts +186 -0
  30. package/src/project-options.ts +128 -0
  31. package/src/retranslate.ts +67 -0
  32. package/src/route.ts +365 -0
  33. package/src/runtime.ts +2143 -0
  34. package/src/save.ts +60 -0
  35. package/src/scenario-test.ts +218 -0
  36. package/src/state.ts +353 -0
  37. package/src/value.ts +443 -0
  38. package/src/voice-observe.ts +85 -0
  39. package/types/src/chat.d.ts +63 -0
  40. package/types/src/commands-play.d.ts +2 -0
  41. package/types/src/commands.d.ts +2 -0
  42. package/types/src/coverage.d.ts +100 -0
  43. package/types/src/headless.d.ts +77 -0
  44. package/types/src/host.d.ts +140 -0
  45. package/types/src/index.d.ts +16 -0
  46. package/types/src/prefetch.d.ts +18 -0
  47. package/types/src/program.d.ts +107 -0
  48. package/types/src/project-options.d.ts +103 -0
  49. package/types/src/retranslate.d.ts +39 -0
  50. package/types/src/route.d.ts +181 -0
  51. package/types/src/runtime.d.ts +553 -0
  52. package/types/src/save.d.ts +21 -0
  53. package/types/src/scenario-test.d.ts +43 -0
  54. package/types/src/state.d.ts +357 -0
  55. package/types/src/value.d.ts +61 -0
  56. package/types/src/voice-observe.d.ts +26 -0
  57. package/README.md +0 -3
@@ -0,0 +1,457 @@
1
+ import { assignAutoSlots, AUTO_POSITION, castPositionCheck, autoLayoutKeepsSlots, autoLayoutName, autoLayoutPosition, autoLayoutPositionNames, autoLayoutSlots, castSides, CORE_COMMANDS, FRAME_POSITIONS, layoutPercent, shownPositions, spriteProblem, type CommandSpec } from "@liminalia/lang";
2
+ import { clearChatMessages } from "./chat.ts";
3
+ import { PLAY_HANDLERS } from "./commands-play.ts";
4
+ import type { Args, CommandContext, CommandImpl } from "./runtime.ts";
5
+ import type { Value } from "./value.ts";
6
+ import { filterArg, type Balloon, type SoundOptions, type Sprite } from "./state.ts";
7
+
8
+ /**
9
+ * 組み込み命令の実装。どれも「状態を更新してから描画側に知らせる」だけで、
10
+ * 見た目の処理は描画側(Host.present)が状態と引数から行う。
11
+ */
12
+
13
+ const s = (v: unknown) => String(v ?? "");
14
+ const n = (v: unknown) => Number(v ?? 0);
15
+ const b = (v: unknown) => v === true;
16
+
17
+ /** 消す立ち絵の差分を、顔ウィンドウの表情に引き継ぐ。 */
18
+ function keepFace(ctx: CommandContext, who: string): void {
19
+ const sprite = ctx.state.stage.sprites[who];
20
+ if (sprite) (ctx.state.stage.faces ??= {})[who] = { appearance: sprite.appearance, variant: sprite.variant };
21
+ }
22
+
23
+ /** 今の背景の色調(@bg・@scene-change の tone=)。書かなければ外す(描画側が ui.backgroundTones から引く)。 */
24
+ /** 規則の人数ごとの位置(autoLayout の positions)で、自動配置の人物が今いる立ち位置の名前(割合と等分の位置は除く)。 */
25
+ function ruledPositions(ctx: CommandContext): Map<string, string> {
26
+ const rules = ctx.runtime.autoLayout;
27
+ const out = new Map<string, string>();
28
+ if (!rules?.positions) return out;
29
+ for (const [who, slot] of autoLayoutSlots(Object.entries(ctx.state.stage.sprites), { rules, side: castSides(ctx.runtime.cast) })) {
30
+ const position = autoLayoutPosition(slot, rules);
31
+ if (position !== AUTO_POSITION && layoutPercent(position) === null) out.set(who, position);
32
+ }
33
+ return out;
34
+ }
35
+
36
+ /**
37
+ * 出し入れで並びが変わり、規則の立ち位置へ動いた自動配置の人物(except は除く。本人は @chara が別に確かめる)について、
38
+ * その立ち位置の名前が本人の立ち絵の枠にあるかを確かめる(無ければ中央に重なる)。before は出し入れの前の ruledPositions。
39
+ */
40
+ function reportMovedPositions(ctx: CommandContext, before: ReadonlyMap<string, string>, except?: string): void {
41
+ const cast = ctx.runtime.cast;
42
+ if (!cast) return;
43
+ for (const [who, at] of ruledPositions(ctx)) {
44
+ if (who === except || before.get(who) === at) continue;
45
+ const sprite = ctx.state.stage.sprites[who]!;
46
+ if (sprite.x !== undefined || sprite.y !== undefined) continue;
47
+ const problem = spriteProblem(cast, who, sprite.appearance, sprite.variant, at);
48
+ if (problem?.code === "unknown-position") ctx.runtime.report("error", problem.code, problem.message);
49
+ }
50
+ }
51
+
52
+ function setBackgroundTone(ctx: CommandContext, tone: Value | undefined): void {
53
+ const stage = ctx.state.stage;
54
+ if (tone !== undefined && stage.background) stage.backgroundTone = { image: stage.background, tone: s(tone) };
55
+ else delete stage.backgroundTone;
56
+ }
57
+
58
+ /**
59
+ * 枠を隠して次の本文で出し直す命令(hide-window)。出し直すときに前の本文を見せないので、NVL で積んだ段落とクリック待ちなしの本文も捨てる
60
+ * (@window hide と同じ。次の本文は新しいページから積む)。
61
+ */
62
+ function dropPageText(ctx: CommandContext): void {
63
+ delete ctx.state.stage.nvlPages;
64
+ delete ctx.state.stage.noclickPage;
65
+ }
66
+
67
+ const handlers: Record<string, (args: Args, ctx: CommandContext) => unknown> = {
68
+ bg: (a, ctx) => {
69
+ // 単色の背景(color=)は色のままセーブに残す
70
+ if (typeof a.color === "string") {
71
+ ctx.state.stage.background = null;
72
+ ctx.state.stage.backgroundColor = a.color;
73
+ } else {
74
+ ctx.state.stage.background = s(a.image);
75
+ delete ctx.state.stage.backgroundColor;
76
+ }
77
+ setBackgroundTone(ctx, a.tone);
78
+ // 奥行きの絵は前の背景のもの
79
+ delete ctx.state.stage.planes;
80
+ if (a["hide-window"] === true) dropPageText(ctx);
81
+ return ctx.present(a, b(a.wait));
82
+ },
83
+ plane: (a, ctx) => {
84
+ const planes = { ...(ctx.state.stage.planes ?? {}) };
85
+ planes[s(a.name)] = { image: s(a.image), depth: n(a.depth), ...(b(a.front) ? { front: true } : {}) };
86
+ ctx.state.stage.planes = planes;
87
+ return ctx.present(a, b(a.wait));
88
+ },
89
+ "plane-hide": (a, ctx) => {
90
+ const planes = { ...(ctx.state.stage.planes ?? {}) };
91
+ if (a.name === undefined) for (const k of Object.keys(planes)) delete planes[k];
92
+ else delete planes[s(a.name)];
93
+ if (Object.keys(planes).length > 0) ctx.state.stage.planes = planes;
94
+ else delete ctx.state.stage.planes;
95
+ return ctx.present(a, b(a.wait));
96
+ },
97
+ chara: (a, ctx) => {
98
+ const sprites = ctx.state.stage.sprites;
99
+ const who = s(a.who);
100
+ const before = ruledPositions(ctx);
101
+ let replacing: string | undefined;
102
+ if (a.replace !== undefined) {
103
+ if (a.at !== undefined || a.x !== undefined || a.y !== undefined || a.clear !== undefined || b(a.solo)) {
104
+ ctx.runtime.report("error", "chara-replace-conflict", "replace と at・x・y・clear・solo は同時に指定できません");
105
+ return;
106
+ }
107
+ const target = s(a.replace);
108
+ const layout = { rules: ctx.runtime.autoLayout, side: castSides(ctx.runtime.cast) };
109
+ const slots = autoLayoutSlots(Object.entries(sprites), layout);
110
+ // left、center、right と規則の立ち位置の名前は、同じ名前の人物がいても立ち位置。ほかは表示中の人物の名前でなければ立ち位置の名前で、
111
+ // 書いた立ち位置(立ち絵の枠の positions の名前も)のほか、人数で読み替えたあとの名前(autoLayout の byCount。制作画面の
112
+ // シーンの情報が出す名前)でも選べる
113
+ const positions: readonly string[] = [...FRAME_POSITIONS, ...autoLayoutPositionNames(layout.rules)];
114
+ // 描画と同じく、差分の枠に読み替え先がある人物だけを読み替える(キャストを持たない流しでは、どの枠にもあるとする)
115
+ const shown = shownPositions(Object.entries(sprites), layout, castPositionCheck(sprites, ctx.runtime.cast));
116
+ const candidates = positions.includes(target) || !Object.hasOwn(sprites, target)
117
+ ? Object.entries(sprites).filter(([name, sprite]) => {
118
+ const slot = slots.get(name);
119
+ if (slot) return autoLayoutName(slot, layout.rules) === target;
120
+ return sprite.x === undefined && sprite.y === undefined && (sprite.at === target || shown.get(name) === target);
121
+ }).map(([name]) => name)
122
+ : [target];
123
+ if (candidates.length !== 1 || candidates[0] === who || Object.hasOwn(sprites, who)) {
124
+ ctx.runtime.report("error", "chara-replace-target", candidates.length === 0 ? `入れ替え先 ${target} は表示されていません` : candidates.length > 1 ? `入れ替え先 ${target} に複数の人物がいます` : `${who} はすでに表示されています`);
125
+ return;
126
+ }
127
+ replacing = candidates[0]!;
128
+ }
129
+ // 全消しの直後と同じく、本人の以前の設定も引き継がない。
130
+ if (a.clear !== undefined) {
131
+ for (const other of Object.keys(sprites)) {
132
+ keepFace(ctx, other);
133
+ delete sprites[other];
134
+ }
135
+ }
136
+ const current = sprites[who];
137
+ // 表示中なら何もしない(描画側にも知らせない)。
138
+ if (b(a["if-hidden"]) && current) return;
139
+ // 出ている人物は、書かなかったものを今のまま保つ(位置は at・x・y のどれも書かなかったとき)。出ていなければ既定
140
+ // (差分 "" は基準の差分、立ち絵セット "" はキャストの既定。描画側が選ぶ)
141
+ const placed = a.at !== undefined || a.x !== undefined || a.y !== undefined;
142
+ const sprite: Sprite = {
143
+ variant: a.variant !== undefined ? s(a.variant) : (current?.variant ?? ""),
144
+ appearance: a.appearance !== undefined ? s(a.appearance) : (current?.appearance ?? ""),
145
+ at: a.at !== undefined ? s(a.at) : placed ? "center" : (current?.at ?? "center"),
146
+ flip: a.flip !== undefined ? b(a.flip) : (current?.flip ?? false),
147
+ };
148
+ if (replacing) {
149
+ const previous = sprites[replacing]!;
150
+ sprite.at = previous.at;
151
+ if (previous.autoLayout) sprite.autoLayout = true;
152
+ if (previous.autoSlot) sprite.autoSlot = { ...previous.autoSlot };
153
+ if (previous.x !== undefined) sprite.x = previous.x;
154
+ if (previous.y !== undefined) sprite.y = previous.y;
155
+ }
156
+ if (!replacing && !placed && (current?.autoLayout === true || (!current && b(a["auto-layout"])))) sprite.autoLayout = true;
157
+ if (sprite.autoLayout && current?.autoSlot) sprite.autoSlot = { ...current.autoSlot };
158
+ const x = placed ? a.x : current?.x;
159
+ const y = placed ? a.y : current?.y;
160
+ if (x !== undefined) sprite.x = n(x);
161
+ if (y !== undefined) sprite.y = n(y);
162
+ const width = a.width ?? current?.width;
163
+ const height = a.height ?? current?.height;
164
+ if (width !== undefined) sprite.width = n(width);
165
+ if (height !== undefined) sprite.height = n(height);
166
+ // 重なり順(z)。0 は書かない
167
+ const z = a.z !== undefined ? n(a.z) : (current?.z ?? 0);
168
+ if (z !== 0) sprite.z = z;
169
+ // 立ち絵に付いたプラグインの状態(漫符など)は、差し替えても残す
170
+ if (current?.extra) sprite.extra = current.extra;
171
+ // solo: ほかの人物を消す(描画側は消えた人物を同じ時間で消す)
172
+ if (b(a.solo)) {
173
+ for (const other of Object.keys(sprites)) {
174
+ if (other === who) continue;
175
+ keepFace(ctx, other);
176
+ delete sprites[other];
177
+ }
178
+ }
179
+ // 表示中の立ち絵の差し替えは、出した順(同じ重なり順のときの前後)を変えない。
180
+ if (replacing) {
181
+ keepFace(ctx, replacing);
182
+ const ordered = Object.entries(sprites).map(([name, value]) => name === replacing ? [who, sprite] as const : [name, value] as const);
183
+ for (const name of Object.keys(sprites)) delete sprites[name];
184
+ for (const [name, value] of ordered) sprites[name] = value;
185
+ } else sprites[who] = sprite;
186
+ // 新しく自動配置に入った人物を並びに入れ、全員の枠を決めて残す(入れる場所、退場しても動かさない並べ方、人物ごとの定位置を使う作品だけ)
187
+ if (!current && !replacing && sprite.autoLayout && autoLayoutKeepsSlots({ rules: ctx.runtime.autoLayout }, ctx.runtime.cast)) {
188
+ const slots = assignAutoSlots(Object.entries(sprites), who, { rules: ctx.runtime.autoLayout, side: castSides(ctx.runtime.cast) });
189
+ for (const [name, slot] of slots) {
190
+ const value = sprites[name];
191
+ if (value) sprites[name] = { ...value, autoSlot: slot };
192
+ }
193
+ }
194
+ // 検査と同じ誤りを、実行時にも黙らずに知らせる(描画は既定・center に落として続ける)
195
+ const cast = ctx.runtime.cast;
196
+ // 自動配置の人物は、規則で決まった立ち位置の名前が本人の枠にあるかも確かめる(無ければ中央に重なる)
197
+ const slot = sprite.autoLayout && ctx.runtime.autoLayout?.positions ? autoLayoutSlots(Object.entries(sprites), { rules: ctx.runtime.autoLayout, side: castSides(cast) }).get(who) : undefined;
198
+ const ruled = slot ? autoLayoutPosition(slot, ctx.runtime.autoLayout) : "";
199
+ const at = ruled !== "" && ruled !== AUTO_POSITION && layoutPercent(ruled) === null ? ruled : sprite.at;
200
+ const problem = cast ? spriteProblem(cast, who, sprite.appearance, sprite.variant, sprite.x !== undefined || sprite.y !== undefined ? "" : at) : null;
201
+ if (problem) ctx.runtime.report("error", problem.code, problem.message);
202
+ // 並べ直しで動いたほかの人物も、規則の立ち位置が本人の枠にあるかを確かめる
203
+ reportMovedPositions(ctx, before, who);
204
+ return ctx.present(replacing ? { ...a, "replace-who": replacing } : a, b(a.wait));
205
+ },
206
+ "chara-config": (a, ctx) => {
207
+ const c = { ...(ctx.state.stage.spriteConfig ?? {}) };
208
+ if (a.focus !== undefined) c.focus = s(a.focus) as NonNullable<typeof c.focus>;
209
+ if (a.dim !== undefined) c.dim = n(a.dim);
210
+ if (a.lower !== undefined) c.lower = n(a.lower);
211
+ if (a.jump !== undefined) c.jump = b(a.jump);
212
+ if (a["move-time"] !== undefined) c.moveTime = n(a["move-time"]);
213
+ if (a.easing !== undefined) c.easing = s(a.easing);
214
+ ctx.state.stage.spriteConfig = c;
215
+ return ctx.present(a, false);
216
+ },
217
+ dof: (a, ctx) => {
218
+ const on = a.who !== undefined ? "chara" : s(a.on);
219
+ if (on === "none") delete ctx.state.stage.dof;
220
+ else ctx.state.stage.dof = { on: on as "background" | "sprites" | "chara", ...(a.who !== undefined ? { who: s(a.who) } : {}), blur: n(a.blur) };
221
+ return ctx.present(a, b(a.wait));
222
+ },
223
+ tone: (a, ctx) => {
224
+ const key = a.who === undefined ? "" : s(a.who);
225
+ const name = s(a.tone);
226
+ const tones = { ...(ctx.state.stage.tones ?? {}) };
227
+ // すべての立ち絵を替えるときは、人物ごとの色調も外す
228
+ if (key === "") for (const k of Object.keys(tones)) delete tones[k];
229
+ if (name === "none") delete tones[key];
230
+ else tones[key] = name;
231
+ if (Object.keys(tones).length > 0) ctx.state.stage.tones = tones;
232
+ else delete ctx.state.stage.tones;
233
+ return ctx.present(a, b(a.wait));
234
+ },
235
+ "text-sound": (a, ctx) => {
236
+ (ctx.state.stage.textSound ??= {})[a.who === undefined ? "" : s(a.who)] = { file: s(a.file), volume: n(a.volume), every: Math.max(1, n(a.every)) };
237
+ return ctx.present(a, false);
238
+ },
239
+ "text-sound-off": (a, ctx) => {
240
+ if (a.who === undefined) delete ctx.state.stage.textSound;
241
+ else delete ctx.state.stage.textSound?.[s(a.who)];
242
+ return ctx.present(a, false);
243
+ },
244
+ balloon: (a, ctx) => {
245
+ if (a.mode !== "on") ctx.state.stage.balloon = null;
246
+ else {
247
+ const b: Balloon = {};
248
+ if (a.width !== undefined) b.width = n(a.width);
249
+ if (a.x !== undefined) b.x = n(a.x);
250
+ if (a.y !== undefined) b.y = n(a.y);
251
+ if (a.tail !== undefined && a.tail !== "auto") b.tail = s(a.tail) as NonNullable<Balloon["tail"]>;
252
+ if (a["tail-x"] !== undefined) b.tailX = n(a["tail-x"]);
253
+ ctx.state.stage.balloon = b;
254
+ }
255
+ return ctx.present(a, false);
256
+ },
257
+ "chara-hide": (a, ctx) => {
258
+ const before = ruledPositions(ctx);
259
+ keepFace(ctx, s(a.who));
260
+ delete ctx.state.stage.sprites[s(a.who)];
261
+ reportMovedPositions(ctx, before);
262
+ return ctx.present(a, b(a.wait));
263
+ },
264
+ "chara-hide-all": (a, ctx) => {
265
+ for (const who of Object.keys(ctx.state.stage.sprites)) keepFace(ctx, who);
266
+ ctx.state.stage.sprites = {};
267
+ return ctx.present(a, b(a.wait));
268
+ },
269
+ face: (a, ctx) => {
270
+ (ctx.state.stage.faces ??= {})[s(a.who)] = { appearance: s(a.appearance), variant: s(a.variant) };
271
+ ctx.state.stage.faceShown = { who: s(a.who), appearance: s(a.appearance), variant: s(a.variant) };
272
+ return ctx.present(a, false);
273
+ },
274
+ "face-off": (a, ctx) => {
275
+ delete ctx.state.stage.faceShown;
276
+ return ctx.present(a, false);
277
+ },
278
+ "window-image": (a, ctx) => {
279
+ if (a.image === undefined) delete ctx.state.stage.windowImage;
280
+ else ctx.state.stage.windowImage = s(a.image);
281
+ return ctx.present(a, false);
282
+ },
283
+ bgm: (a, ctx) => {
284
+ ctx.state.stage.bgm = { file: s(a.file), volume: n(a.volume), loop: b(a.loop), ...soundOptions(a) };
285
+ // 一度鳴らした BGM(おまけの音楽で聞けるようにする)
286
+ ((ctx.runtime.system.bgm_heard ??= {}) as Record<string, true>)[s(a.file)] = true;
287
+ return ctx.present(a, false);
288
+ },
289
+ "stop-bgm": (a, ctx) => {
290
+ ctx.state.stage.bgm = null;
291
+ return ctx.present(a, false);
292
+ },
293
+ se: (a, ctx) => {
294
+ const channel = s(a.channel);
295
+ if (b(a.loop)) ctx.state.stage.loopingSe[channel] = { file: s(a.file), volume: n(a.volume), ...soundOptions(a) };
296
+ else delete ctx.state.stage.loopingSe[channel];
297
+ return ctx.present(a, false);
298
+ },
299
+ "stop-se": (a, ctx) => {
300
+ delete ctx.state.stage.loopingSe[s(a.channel)];
301
+ return ctx.present(a, false);
302
+ },
303
+ wait: (a, ctx) => ctx.present(a, true),
304
+ mask: (a, ctx) => {
305
+ ctx.state.stage.mask = s(a.color);
306
+ if (a["hide-window"] !== false) {
307
+ dropPageText(ctx);
308
+ ctx.state.stage.windowSuppressed = true;
309
+ }
310
+ return ctx.present(a, true);
311
+ },
312
+ "mask-off": (a, ctx) => {
313
+ ctx.state.stage.mask = null;
314
+ return ctx.present(a, true);
315
+ },
316
+ "scene-change": (a, ctx) => {
317
+ // 明転し終えたあとの様子にしてから、描画側に暗転→切り替え→明転をさせる。
318
+ const stage = ctx.state.stage;
319
+ if (a["hide-chara"] !== false) {
320
+ if (a["hide-who"] !== undefined) {
321
+ const who = s(a["hide-who"]);
322
+ const before = ruledPositions(ctx);
323
+ keepFace(ctx, who);
324
+ delete stage.sprites[who];
325
+ reportMovedPositions(ctx, before);
326
+ } else {
327
+ for (const who of Object.keys(stage.sprites)) keepFace(ctx, who);
328
+ stage.sprites = {};
329
+ }
330
+ }
331
+ if (a.image !== undefined) {
332
+ stage.background = s(a.image);
333
+ delete stage.backgroundColor;
334
+ delete stage.planes;
335
+ } else if (typeof a["bg-color"] === "string") {
336
+ stage.background = null;
337
+ stage.backgroundColor = a["bg-color"];
338
+ delete stage.planes;
339
+ }
340
+ if (a.image !== undefined || a.tone !== undefined) setBackgroundTone(ctx, a.tone);
341
+ stage.mask = null;
342
+ if (a["hide-window"] !== false) {
343
+ dropPageText(ctx);
344
+ stage.windowSuppressed = true;
345
+ }
346
+ // 暗転の後ろで BGM を止める・替える(bgm を書けば stop-bgm は要らない)
347
+ if (a.bgm !== undefined) {
348
+ stage.bgm = { file: s(a.bgm), volume: n(a["bgm-volume"] ?? 100), loop: true };
349
+ ((ctx.runtime.system.bgm_heard ??= {}) as Record<string, true>)[s(a.bgm)] = true;
350
+ } else if (a["stop-bgm"] === true) stage.bgm = null;
351
+ // 暗転と明転の時間は、省けば time(描画側には決まった値を渡す)
352
+ return ctx.present({ ...a, "fade-out": a["fade-out"] ?? a.time ?? 0, "fade-in": a["fade-in"] ?? a.time ?? 0, "hide-chara-at": a["hide-at"] ?? a["hide-chara-at"] ?? "covered" }, true);
353
+ },
354
+ quake: (a, ctx) => ctx.present(a, b(a.wait)),
355
+ camera: (a, ctx) => {
356
+ // 行って戻る(yoyo)は状態を変えない(描画側が書いた姿まで動かして戻す)
357
+ if (a.yoyo === true) return ctx.present(a, b(a.wait));
358
+ const c = ctx.state.stage.camera;
359
+ if (a.zoom !== undefined) c.zoom = n(a.zoom);
360
+ if (a.x !== undefined) c.x = n(a.x);
361
+ if (a.y !== undefined) c.y = n(a.y);
362
+ if (a.rotate !== undefined) c.rotate = n(a.rotate);
363
+ return ctx.present(a, b(a.wait));
364
+ },
365
+ "reset-camera": (a, ctx) => {
366
+ ctx.state.stage.camera = { zoom: 1, x: 0, y: 0, rotate: 0 };
367
+ return ctx.present(a, b(a.wait));
368
+ },
369
+ window: (a, ctx) => {
370
+ ctx.state.stage.window = a.mode === "show";
371
+ delete ctx.state.stage.windowSuppressed;
372
+ if (a.mode === "show") delete ctx.state.stage.windowHidden;
373
+ else {
374
+ ctx.state.stage.windowHidden = true;
375
+ delete ctx.state.stage.nvlPages; // 枠を消すと本文も消える
376
+ delete ctx.state.stage.noclickPage;
377
+ }
378
+ return ctx.present(a, true);
379
+ },
380
+ nvl: (a, ctx) => {
381
+ ctx.state.stage.nvl = a.mode === "on";
382
+ // 見た目の名前(ui.nvlStyles)。書かなければ ui.nvl の見た目に戻す
383
+ if (a.mode === "on" && typeof a.style === "string" && a.style !== "") ctx.state.stage.nvlStyle = a.style;
384
+ else delete ctx.state.stage.nvlStyle;
385
+ delete ctx.state.stage.nvlPages;
386
+ delete ctx.state.stage.noclickPage;
387
+ return ctx.present(a, false);
388
+ },
389
+ vertical: (a, ctx) => {
390
+ ctx.state.stage.vertical = a.mode === "on";
391
+ delete ctx.state.stage.nvlPages;
392
+ delete ctx.state.stage.noclickPage;
393
+ return ctx.present(a, false);
394
+ },
395
+ name: (a, ctx) => {
396
+ ctx.state.stage.names = { ...(ctx.state.stage.names ?? {}), [s(a.who)]: s(a.as) };
397
+ return ctx.present(a, false);
398
+ },
399
+ "name-off": (a, ctx) => {
400
+ const names = { ...(ctx.state.stage.names ?? {}) };
401
+ if (a.who === undefined) for (const k of Object.keys(names)) delete names[k];
402
+ else delete names[s(a.who)];
403
+ if (Object.keys(names).length > 0) ctx.state.stage.names = names;
404
+ else delete ctx.state.stage.names;
405
+ return ctx.present(a, false);
406
+ },
407
+ clear: (a, ctx) => {
408
+ delete ctx.state.stage.nvlPages;
409
+ delete ctx.state.stage.noclickPage;
410
+ // 吹き出しの列も NVL の段落と同じに消す(@chat-open だけを使う作品の吹き出しは @clear で消えない)
411
+ if (ctx.runtime.chatDialogue) clearChatMessages(ctx.state.stage.extra);
412
+ return ctx.present(a, false);
413
+ },
414
+ "text-speed": (a, ctx) => {
415
+ ctx.state.stage.textSpeed = n(a["per-char"]);
416
+ return ctx.present(a, false);
417
+ },
418
+ "text-speed-reset": (a, ctx) => {
419
+ ctx.state.stage.textSpeed = null;
420
+ return ctx.present(a, false);
421
+ },
422
+ "cg-unlock": (a, ctx) => {
423
+ const system = ctx.runtime.system;
424
+ const unlocked = (system.cg_unlocked ??= {}) as Record<string, true>;
425
+ unlocked[s(a.image)] = true;
426
+ },
427
+ "wait-click": async (a, ctx) => {
428
+ await ctx.present(a, false);
429
+ await ctx.runtime.waitClick();
430
+ },
431
+ stop: (_a, ctx) => ctx.runtime.stop(),
432
+ ...PLAY_HANDLERS,
433
+ };
434
+
435
+ /**
436
+ * 自動確認(Host.automated)で、描画側の画面を出さずに答えなしで進める組み込みの命令(CommandImpl.autoplay)。
437
+ * 答えが無いときの動きは画面なしと同じ: @text-input は initial、@dialog は OK、@item-select は選ばない、@open-screen は開かない。
438
+ */
439
+ const AUTOPLAY_WITHOUT_ANSWER: ReadonlySet<string> = new Set(["text-input", "dialog", "item-select", "open-screen"]);
440
+
441
+ export const CORE_IMPLEMENTATIONS: CommandImpl[] = CORE_COMMANDS.map((spec: CommandSpec) => {
442
+ const run = handlers[spec.name];
443
+ if (!run) throw new Error(`組み込みコマンド @${spec.name} の実装がありません`);
444
+ return { spec, run: async (args: Args, ctx: CommandContext) => void (await run(args, ctx)), ...(AUTOPLAY_WITHOUT_ANSWER.has(spec.name) ? { autoplay: () => undefined } : {}) };
445
+ });
446
+
447
+ /** @bgm・@se の鳴らし方のパラメータ(書いたものだけ)。 */
448
+ function soundOptions(a: Record<string, Value>): SoundOptions {
449
+ const out: SoundOptions = {};
450
+ if (typeof a["loop-start"] === "number") out.loopStart = a["loop-start"];
451
+ if (typeof a["loop-end"] === "number") out.loopEnd = a["loop-end"];
452
+ if (typeof a.pan === "number" && a.pan !== 0) out.pan = a.pan;
453
+ if (typeof a.rate === "number" && a.rate !== 1) out.rate = a.rate;
454
+ const filter = filterArg(a);
455
+ if (filter) out.filter = filter;
456
+ return out;
457
+ }