@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.
- package/LICENSE +106 -0
- package/dist/src/chat.js +60 -0
- package/dist/src/commands-play.js +300 -0
- package/dist/src/commands.js +534 -0
- package/dist/src/coverage.js +208 -0
- package/dist/src/headless.js +109 -0
- package/dist/src/host.js +1 -0
- package/dist/src/index.js +15 -0
- package/dist/src/prefetch.js +80 -0
- package/dist/src/program.js +131 -0
- package/dist/src/project-options.js +84 -0
- package/dist/src/retranslate.js +44 -0
- package/dist/src/route.js +242 -0
- package/dist/src/runtime.js +1929 -0
- package/dist/src/save.js +51 -0
- package/dist/src/scenario-test.js +200 -0
- package/dist/src/state.js +62 -0
- package/dist/src/value.js +464 -0
- package/dist/src/voice-observe.js +82 -0
- package/package.json +33 -4
- package/src/chat.ts +109 -0
- package/src/commands-play.ts +280 -0
- package/src/commands.ts +457 -0
- package/src/coverage.ts +257 -0
- package/src/headless.ts +139 -0
- package/src/host.ts +116 -0
- package/src/index.ts +16 -0
- package/src/prefetch.ts +78 -0
- package/src/program.ts +186 -0
- package/src/project-options.ts +128 -0
- package/src/retranslate.ts +67 -0
- package/src/route.ts +365 -0
- package/src/runtime.ts +2143 -0
- package/src/save.ts +60 -0
- package/src/scenario-test.ts +218 -0
- package/src/state.ts +353 -0
- package/src/value.ts +443 -0
- package/src/voice-observe.ts +85 -0
- package/types/src/chat.d.ts +63 -0
- package/types/src/commands-play.d.ts +2 -0
- package/types/src/commands.d.ts +2 -0
- package/types/src/coverage.d.ts +100 -0
- package/types/src/headless.d.ts +77 -0
- package/types/src/host.d.ts +140 -0
- package/types/src/index.d.ts +16 -0
- package/types/src/prefetch.d.ts +18 -0
- package/types/src/program.d.ts +107 -0
- package/types/src/project-options.d.ts +103 -0
- package/types/src/retranslate.d.ts +39 -0
- package/types/src/route.d.ts +181 -0
- package/types/src/runtime.d.ts +553 -0
- package/types/src/save.d.ts +21 -0
- package/types/src/scenario-test.d.ts +43 -0
- package/types/src/state.d.ts +357 -0
- package/types/src/value.d.ts +61 -0
- package/types/src/voice-observe.d.ts +26 -0
- package/README.md +0 -3
package/src/chat.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { TextOrigin } from "./retranslate.ts";
|
|
2
|
+
import type { NvlPart, StageState } from "./state.ts";
|
|
3
|
+
import type { Value } from "./value.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* チャットの画面の状態(stage.extra の "std.chat")。描くのと @chat-open・@chat は @liminalia/std だが、ふだんの台詞を吹き出しにするとき
|
|
7
|
+
* (ui.chat.dialogue)は、読み終えたページと選んだ選択肢を実行器が積む(NVL の段落と同じく、セーブとロード、画面なしで流す道筋の探索でも同じになるように)。
|
|
8
|
+
*/
|
|
9
|
+
export interface ChatMessage {
|
|
10
|
+
speaker: string;
|
|
11
|
+
text: string;
|
|
12
|
+
/** 画像(image からのパス。スタンプ・写真)。 */
|
|
13
|
+
image: string;
|
|
14
|
+
/** 自分の吹き出し(右に出す)。 */
|
|
15
|
+
me: boolean;
|
|
16
|
+
/** 足した命令の位置(その命令からやり直したとき、二度足さないため)。 */
|
|
17
|
+
at?: string;
|
|
18
|
+
/** 地の文(中央の小さな一行)。 */
|
|
19
|
+
note?: boolean;
|
|
20
|
+
/** 話者名の訳(多言語)。出すのはこちら。 */
|
|
21
|
+
label?: string;
|
|
22
|
+
/** 本文の一片(ルビ・装飾つき。あれば text の代わりに描く)。 */
|
|
23
|
+
parts?: NvlPart[];
|
|
24
|
+
/** そのときの顔(キャスト名と姿)。 */
|
|
25
|
+
face?: { who: string; appearance: string; variant: string };
|
|
26
|
+
/** 言語を替えたときに出し直す元(text・label。retranslate.ts)。 */
|
|
27
|
+
i18n?: Record<string, TextOrigin>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface Chat {
|
|
31
|
+
title: string;
|
|
32
|
+
/** 自分の名前(この話者の吹き出しを右に出す)。 */
|
|
33
|
+
me: string;
|
|
34
|
+
messages: ChatMessage[];
|
|
35
|
+
/** @chat-open を使わず、ふだんの台詞から始めた画面(ui.chat.dialogue を外した作品では出さない)。 */
|
|
36
|
+
auto?: boolean;
|
|
37
|
+
/** 言語を替えたときに出し直す元(title。retranslate.ts)。 */
|
|
38
|
+
i18n?: Record<string, TextOrigin>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** ふだんの台詞を吹き出しにする設定(ui.chat.dialogue のとき。me と title は ui.chat の値)。 */
|
|
42
|
+
export interface ChatDialogue {
|
|
43
|
+
me?: string;
|
|
44
|
+
title?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const CHAT_KEY = "std.chat";
|
|
48
|
+
/** 残す吹き出しの数(古いものから捨てる。セーブを小さく保つ)。 */
|
|
49
|
+
export const CHAT_KEEP = 60;
|
|
50
|
+
|
|
51
|
+
export function readChat(extra: Record<string, Value>): Chat | null {
|
|
52
|
+
return (extra[CHAT_KEY] as unknown as Chat | undefined) ?? null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 本文をチャットに出す状態か(@nvl on・@vertical on・@balloon on の間は、いつものメッセージ枠に戻す)。 */
|
|
56
|
+
export function chatDialogueActive(stage: StageState): boolean {
|
|
57
|
+
return stage.nvl !== true && stage.vertical !== true && !stage.balloon;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 列の終わりに吹き出しを足す(無ければ画面ごと作る)。 */
|
|
61
|
+
export function pushChatMessage(extra: Record<string, Value>, o: ChatDialogue | null, message: (chat: Chat) => ChatMessage): void {
|
|
62
|
+
const chat = readChat(extra) ?? { title: o?.title ?? "", me: o?.me ?? "", messages: [], auto: true };
|
|
63
|
+
extra[CHAT_KEY] = { ...chat, messages: [...chat.messages, message(chat)].slice(-CHAT_KEEP) } as unknown as Value;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 列を空にする(@clear)。 */
|
|
67
|
+
export function clearChatMessages(extra: Record<string, Value>): void {
|
|
68
|
+
const chat = readChat(extra);
|
|
69
|
+
if (chat) extra[CHAT_KEY] = { ...chat, messages: [] } as unknown as Value;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 台詞を包む鉤括弧(「…」『…』)を、本文を出す順に外す関数を作る(吹き出しが括弧の代わりなので。入れ子の括弧は残し、(…)は心の声として残す)。
|
|
74
|
+
* 本文は装飾やルビの切れ目で分かれて届くので、ページ全体を通して一つ使う。
|
|
75
|
+
*/
|
|
76
|
+
export function chatQuoteStripper(): (text: string) => string {
|
|
77
|
+
let state: "start" | "inside" | "done" = "start";
|
|
78
|
+
let open = "";
|
|
79
|
+
let close = "";
|
|
80
|
+
let depth = 0;
|
|
81
|
+
return (text) => {
|
|
82
|
+
let out = "";
|
|
83
|
+
for (const ch of text) {
|
|
84
|
+
if (state === "start") {
|
|
85
|
+
state = "done";
|
|
86
|
+
if (ch === "「" || ch === "『") {
|
|
87
|
+
state = "inside";
|
|
88
|
+
open = ch;
|
|
89
|
+
close = ch === "「" ? "」" : "』";
|
|
90
|
+
depth = 1;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
} else if (state === "inside") {
|
|
94
|
+
if (ch === open) depth++;
|
|
95
|
+
else if (ch === close && --depth === 0) {
|
|
96
|
+
state = "done";
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
out += ch;
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 本文の一片の文字列(ルビは親文字だけ。絵は数えない)。 */
|
|
107
|
+
export function chatPartsText(parts: readonly NvlPart[]): string {
|
|
108
|
+
return parts.map((p) => ("br" in p ? "\n" : p.style.image ? "" : p.text)).join("");
|
|
109
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import type { Args, CommandContext } from "./runtime.ts";
|
|
2
|
+
import { filterArg, voiceFilterFor, type StageState, type VoiceCue } from "./state.ts";
|
|
3
|
+
import { EvalError, type Scope } from "./value.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 遊ぶ側の仕組みに関わる組み込み命令の実装(仕様は @liminalia/lang の registry-play.ts)。
|
|
7
|
+
* システム画面への要求は状態を更新して描画側に知らせるだけで、何をするかは描画側とシステム画面が決める。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const s = (v: unknown) => String(v ?? "");
|
|
11
|
+
const n = (v: unknown) => Number(v ?? 0);
|
|
12
|
+
const b = (v: unknown) => v === true;
|
|
13
|
+
|
|
14
|
+
const ui = (stage: StageState) => (stage.ui ??= { menuButton: true, shortcuts: true, backlog: true });
|
|
15
|
+
|
|
16
|
+
/** チャンネルの指定がなければ、ループ再生中のすべての効果音。 */
|
|
17
|
+
const channels = (stage: StageState, channel: unknown) => (channel === undefined ? Object.keys(stage.loopingSe) : [s(channel)]);
|
|
18
|
+
|
|
19
|
+
const clear = (scope: Scope) => {
|
|
20
|
+
for (const key of Object.keys(scope)) delete scope[key];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** 持ち物の数(ゲームの変数の、式からは書けない名前のところ。@liminalia/lang の ITEMS_KEY)。 */
|
|
24
|
+
const items = (game: Scope): Scope => {
|
|
25
|
+
const v = game["@items"];
|
|
26
|
+
if (v && typeof v === "object" && !Array.isArray(v)) return v as Scope;
|
|
27
|
+
return (game["@items"] = {});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const PLAY_HANDLERS: Record<string, (args: Args, ctx: CommandContext) => unknown> = {
|
|
31
|
+
// ---- 持ち物 ----
|
|
32
|
+
"item-add": (a, ctx) => {
|
|
33
|
+
const bag = items(ctx.state.game);
|
|
34
|
+
const key = s(a.item);
|
|
35
|
+
bag[key] = (typeof bag[key] === "number" ? (bag[key] as number) : 0) + Math.max(1, n(a.count ?? 1));
|
|
36
|
+
ctx.runtime.variablesChanged("game.@items");
|
|
37
|
+
return ctx.present(a, false);
|
|
38
|
+
},
|
|
39
|
+
"item-remove": (a, ctx) => {
|
|
40
|
+
const bag = items(ctx.state.game);
|
|
41
|
+
const key = s(a.item);
|
|
42
|
+
const left = a.count === undefined ? 0 : (typeof bag[key] === "number" ? (bag[key] as number) : 0) - n(a.count);
|
|
43
|
+
if (left > 0) bag[key] = left;
|
|
44
|
+
else delete bag[key];
|
|
45
|
+
ctx.runtime.variablesChanged("game.@items");
|
|
46
|
+
return ctx.present(a, false);
|
|
47
|
+
},
|
|
48
|
+
"item-select": async (a, ctx) => {
|
|
49
|
+
ctx.resumeHere();
|
|
50
|
+
// 描画側は選んだ持ち物の名前(やめたら null)を返す。画面なしでは選ばなかったことにする
|
|
51
|
+
const value = await ctx.present(a, true);
|
|
52
|
+
ctx.runtime.setVariable(s(a.variable), typeof value === "string" ? value : "");
|
|
53
|
+
},
|
|
54
|
+
// ---- システム画面への要求 ----
|
|
55
|
+
auto: (a, ctx) => ctx.present(a, false),
|
|
56
|
+
skip: (a, ctx) => ctx.present(a, false),
|
|
57
|
+
// セーブ画面で保存したら、この命令の次から再開する(開き直さない)。
|
|
58
|
+
"open-screen": (a, ctx) => ctx.present(a, true),
|
|
59
|
+
"menu-button": (a, ctx) => {
|
|
60
|
+
ui(ctx.state.stage).menuButton = a.mode === "show";
|
|
61
|
+
return ctx.present(a, false);
|
|
62
|
+
},
|
|
63
|
+
shortcuts: (a, ctx) => {
|
|
64
|
+
ui(ctx.state.stage).shortcuts = a.mode === "on";
|
|
65
|
+
return ctx.present(a, false);
|
|
66
|
+
},
|
|
67
|
+
config: (a, ctx) => ctx.present(a, false),
|
|
68
|
+
fullscreen: (a, ctx) => ctx.present(a, false),
|
|
69
|
+
quit: (a, ctx) => ctx.present(a, true),
|
|
70
|
+
// システム画面に知らせてから、このプレイを終える(システム画面がタイトルへ戻す)
|
|
71
|
+
"title-screen": async (a, ctx) => {
|
|
72
|
+
await ctx.present(a, false);
|
|
73
|
+
ctx.runtime.stop();
|
|
74
|
+
},
|
|
75
|
+
"window-title": (a, ctx) => ctx.present(a, false),
|
|
76
|
+
presence: (a, ctx) => ctx.present(a, false),
|
|
77
|
+
"open-url": (a, ctx) => ctx.present(a, false),
|
|
78
|
+
autosave: (a, ctx) => ctx.present(a, true),
|
|
79
|
+
autoload: (a, ctx) => ctx.present(a, true),
|
|
80
|
+
backlog: (a, ctx) => {
|
|
81
|
+
ui(ctx.state.stage).backlog = a.mode === "on";
|
|
82
|
+
return ctx.present(a, false);
|
|
83
|
+
},
|
|
84
|
+
"backlog-add": (a, ctx) => ctx.present(a, false),
|
|
85
|
+
// 読み上げのときだけの文(システム画面がスクリーンリーダーとテキスト読み上げに渡す)
|
|
86
|
+
describe: (a, ctx) => ctx.present(a, false),
|
|
87
|
+
|
|
88
|
+
// ---- 音 ----
|
|
89
|
+
"pause-bgm": (a, ctx) => {
|
|
90
|
+
if (ctx.state.stage.bgm) ctx.state.stage.bgm.paused = true;
|
|
91
|
+
return ctx.present(a, false);
|
|
92
|
+
},
|
|
93
|
+
"resume-bgm": (a, ctx) => {
|
|
94
|
+
if (ctx.state.stage.bgm) delete ctx.state.stage.bgm.paused;
|
|
95
|
+
return ctx.present(a, false);
|
|
96
|
+
},
|
|
97
|
+
"pause-se": (a, ctx) => {
|
|
98
|
+
for (const c of channels(ctx.state.stage, a.channel)) {
|
|
99
|
+
const se = ctx.state.stage.loopingSe[c];
|
|
100
|
+
if (se) se.paused = true;
|
|
101
|
+
}
|
|
102
|
+
return ctx.present(a, false);
|
|
103
|
+
},
|
|
104
|
+
"resume-se": (a, ctx) => {
|
|
105
|
+
for (const c of channels(ctx.state.stage, a.channel)) delete ctx.state.stage.loopingSe[c]?.paused;
|
|
106
|
+
return ctx.present(a, false);
|
|
107
|
+
},
|
|
108
|
+
"bgm-volume": (a, ctx) => {
|
|
109
|
+
if (ctx.state.stage.bgm) ctx.state.stage.bgm.volume = n(a.volume);
|
|
110
|
+
return ctx.present(a, false);
|
|
111
|
+
},
|
|
112
|
+
"se-volume": (a, ctx) => {
|
|
113
|
+
for (const c of channels(ctx.state.stage, a.channel)) {
|
|
114
|
+
const se = ctx.state.stage.loopingSe[c];
|
|
115
|
+
if (se) se.volume = n(a.volume);
|
|
116
|
+
}
|
|
117
|
+
return ctx.present(a, false);
|
|
118
|
+
},
|
|
119
|
+
"wait-bgm": (a, ctx) => ctx.present(a, true),
|
|
120
|
+
"wait-se": (a, ctx) => ctx.present(a, true),
|
|
121
|
+
|
|
122
|
+
// ---- ボイス ----
|
|
123
|
+
voice: (a, ctx) => {
|
|
124
|
+
const cue: VoiceCue = {
|
|
125
|
+
file: s(a.file),
|
|
126
|
+
volume: n(a.volume),
|
|
127
|
+
folder: s(a.folder),
|
|
128
|
+
...(typeof a.caption === "string" && a.caption !== "" ? { caption: a.caption } : {}),
|
|
129
|
+
...(typeof a.channel === "number" && a.channel !== 1 ? { channel: a.channel } : {}),
|
|
130
|
+
...(typeof a.who === "string" && a.who !== "" ? { who: a.who } : {}),
|
|
131
|
+
// filter=none は、@voice-filter で掛け続けているフィルターもこのボイスには掛けない
|
|
132
|
+
...(typeof a.filter === "string" ? { filter: filterArg(a) } : {}),
|
|
133
|
+
};
|
|
134
|
+
// 本文の中なら、そのページのボイスとして今鳴らす(フィルターは書いたもの、無ければ @voice-filter のもの)
|
|
135
|
+
if (ctx.runtime.speaking) {
|
|
136
|
+
const who = cue.who ?? ctx.runtime.speakerNow ?? null;
|
|
137
|
+
const filter = cue.filter !== undefined ? cue.filter : voiceFilterFor(ctx.state.stage, who);
|
|
138
|
+
return ctx.present({ ...a, ...(filter ? { filter: filter.type, "filter-strength": filter.strength } : { filter: "none" }) }, false);
|
|
139
|
+
}
|
|
140
|
+
// 本文の外なら、次の台詞で鳴らす。話者やチャンネルの違う @voice は同時に鳴らし(channel が重なれば鳴らすときに空きへ回す)、
|
|
141
|
+
// 同じ話者とチャンネルのものは書き直す
|
|
142
|
+
const voice = (ctx.state.stage.voice ??= {});
|
|
143
|
+
const slots = voice.next ? [voice.next, ...(voice.next.also ?? [])] : [];
|
|
144
|
+
// who を省いた @voice はその台詞の話者のもの(省いたものどうしは同じところに入れ、話者を書いたものとは別にする)
|
|
145
|
+
const slot = (c: VoiceCue) => `${c.channel ?? 1} ${c.who ?? ""}`;
|
|
146
|
+
const at = slots.findIndex((x) => slot(x) === slot(cue));
|
|
147
|
+
if (at >= 0) slots[at] = cue;
|
|
148
|
+
else slots.push(cue);
|
|
149
|
+
const [main, ...also] = slots;
|
|
150
|
+
voice.next = also.length > 0 ? { ...main!, also } : main!;
|
|
151
|
+
},
|
|
152
|
+
"voice-filter": (a, ctx) => {
|
|
153
|
+
const filters = (ctx.state.stage.voiceFilter ??= {});
|
|
154
|
+
const who = typeof a.who === "string" ? a.who : "";
|
|
155
|
+
const filter = filterArg(a);
|
|
156
|
+
if (filter) filters[who] = filter;
|
|
157
|
+
else delete filters[who];
|
|
158
|
+
if (Object.keys(filters).length === 0) delete ctx.state.stage.voiceFilter;
|
|
159
|
+
// 鳴っているボイスにも掛ける(描画側)
|
|
160
|
+
return ctx.present(a, false);
|
|
161
|
+
},
|
|
162
|
+
"voice-auto": (a, ctx) => {
|
|
163
|
+
const auto = ((ctx.state.stage.voice ??= {}).auto ??= {});
|
|
164
|
+
if (a.pattern !== undefined) {
|
|
165
|
+
// 設定する
|
|
166
|
+
if (a.who === undefined) throw new EvalError("@voice-auto で pattern を書くときは話者も書きます");
|
|
167
|
+
auto[s(a.who)] = { pattern: s(a.pattern), next: a.next === undefined ? 1 : n(a.next), volume: n(a.volume), folder: s(a.folder), ...(b(a.start) ? {} : { off: true }) };
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
// 再開する(番号は保つ。next を書けばその番号から)
|
|
171
|
+
if (a.who !== undefined && !auto[s(a.who)]) throw new EvalError(`@voice-auto ${s(a.who)} の設定がありません(pattern を書いて設定します)`);
|
|
172
|
+
for (const t of a.who === undefined ? Object.values(auto) : [auto[s(a.who)]!]) {
|
|
173
|
+
delete t.off;
|
|
174
|
+
if (a.next !== undefined) t.next = n(a.next);
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
"voice-auto-off": (a, ctx) => {
|
|
178
|
+
const auto = ctx.state.stage.voice?.auto ?? {};
|
|
179
|
+
for (const t of a.who === undefined ? Object.values(auto) : [auto[s(a.who)]]) if (t) t.off = true;
|
|
180
|
+
},
|
|
181
|
+
"stop-voice": (a, ctx) => ctx.present(a, false),
|
|
182
|
+
"wait-voice": (a, ctx) => ctx.present(a, true),
|
|
183
|
+
|
|
184
|
+
// ---- 入力と確認の枠 ----
|
|
185
|
+
"text-input": async (a, ctx) => {
|
|
186
|
+
ctx.resumeHere();
|
|
187
|
+
const value = await ctx.present(a, true);
|
|
188
|
+
ctx.runtime.setVariable(s(a.variable), typeof value === "string" ? value : s(a.initial));
|
|
189
|
+
},
|
|
190
|
+
dialog: async (a, ctx) => {
|
|
191
|
+
ctx.resumeHere();
|
|
192
|
+
// 描画側は confirm なら true / false、input なら入力した文字(取り消しは null)を返す。画面なしでは OK を押したことにする。
|
|
193
|
+
const value = await ctx.present(a, true);
|
|
194
|
+
let ok = value !== false && value !== null;
|
|
195
|
+
if (a.type === "input" && ok) {
|
|
196
|
+
if (a.variable !== undefined) ctx.runtime.setVariable(s(a.variable), typeof value === "string" ? value : "");
|
|
197
|
+
}
|
|
198
|
+
if (a.type === "alert") ok = true;
|
|
199
|
+
const target = ok ? a.target : a["cancel-target"];
|
|
200
|
+
if (target !== undefined) await ctx.runtime.jump(s(target));
|
|
201
|
+
},
|
|
202
|
+
peek: (a, ctx) => ctx.present(a, true),
|
|
203
|
+
|
|
204
|
+
// ---- 変数と実行の状態 ----
|
|
205
|
+
"clear-vars": (a, ctx) => {
|
|
206
|
+
const scope = s(a.scope);
|
|
207
|
+
if (scope === "game" || scope === "all") clear(ctx.state.game);
|
|
208
|
+
if (scope === "system" || scope === "all") clear(ctx.runtime.system);
|
|
209
|
+
if (scope === "temp" || scope === "all") clear(ctx.state.temp);
|
|
210
|
+
ctx.runtime.variablesChanged(...(scope === "all" ? ["game", "system", "temp"] : [scope]));
|
|
211
|
+
},
|
|
212
|
+
"clear-stack": (_a, ctx) => {
|
|
213
|
+
ctx.state.callStack.length = 0;
|
|
214
|
+
},
|
|
215
|
+
"sleep-game": async (a, ctx) => {
|
|
216
|
+
ctx.state.sleep = ctx.runtime.snapshot();
|
|
217
|
+
await ctx.present(a, false);
|
|
218
|
+
await ctx.runtime.jump(s(a.target));
|
|
219
|
+
},
|
|
220
|
+
"awake-game": async (a, ctx) => {
|
|
221
|
+
const sleep = ctx.state.sleep;
|
|
222
|
+
if (!sleep) return;
|
|
223
|
+
ctx.state.sleep = null;
|
|
224
|
+
await ctx.runtime.restoreSnapshot(sleep, { keepVariables: b(a["keep-variables"]), keepBgm: b(a["keep-bgm"]) });
|
|
225
|
+
},
|
|
226
|
+
"break-game": (_a, ctx) => {
|
|
227
|
+
ctx.state.sleep = null;
|
|
228
|
+
},
|
|
229
|
+
checkpoint: (a, ctx) => {
|
|
230
|
+
(ctx.state.checkpoints ??= {})[s(a.name)] = ctx.runtime.snapshot();
|
|
231
|
+
},
|
|
232
|
+
rollback: async (a, ctx) => {
|
|
233
|
+
const snapshot = ctx.state.checkpoints?.[s(a.name)];
|
|
234
|
+
if (!snapshot) throw new EvalError(`@checkpoint ${s(a.name)} はまだ記録されていません`);
|
|
235
|
+
await ctx.runtime.restoreSnapshot(snapshot, { keepVariables: b(a["keep-variables"]), keepBgm: b(a["keep-bgm"]) });
|
|
236
|
+
},
|
|
237
|
+
"clear-checkpoint": (a, ctx) => {
|
|
238
|
+
if (a.name === undefined) ctx.state.checkpoints = {};
|
|
239
|
+
else delete ctx.state.checkpoints?.[s(a.name)];
|
|
240
|
+
},
|
|
241
|
+
"glossary-unlock": (a, ctx) => {
|
|
242
|
+
const unlocked = (ctx.runtime.system.glossary_unlocked ??= {}) as Record<string, true>;
|
|
243
|
+
unlocked[s(a.id)] = true;
|
|
244
|
+
},
|
|
245
|
+
"replay-unlock": (a, ctx) => {
|
|
246
|
+
const unlocked = (ctx.runtime.system.replay_unlocked ??= {}) as Record<string, true>;
|
|
247
|
+
unlocked[s(a.id)] = true;
|
|
248
|
+
},
|
|
249
|
+
"replay-end": (a, ctx) => ctx.present(a, false),
|
|
250
|
+
achieve: (a, ctx) => {
|
|
251
|
+
const unlocked = (ctx.runtime.system.achievements ??= {}) as Record<string, string>;
|
|
252
|
+
// はじめて解放したときだけ描画側(システム画面)へ知らせる
|
|
253
|
+
if (unlocked[s(a.id)]) return;
|
|
254
|
+
unlocked[s(a.id)] = new Date().toISOString();
|
|
255
|
+
return ctx.present(a, false);
|
|
256
|
+
},
|
|
257
|
+
// 数を数える実績。数をシステム変数 achievement_progress に残し、目標(extra.achievements の goal)に届いたら解除する。
|
|
258
|
+
// 描画側へは id・数・目標と、このとき解除したか(unlocked)を渡す(店の実績の進み具合に送る)
|
|
259
|
+
"achieve-progress": (a, ctx) => {
|
|
260
|
+
const id = s(a.id);
|
|
261
|
+
const progress = (ctx.runtime.system.achievement_progress ??= {}) as Record<string, number>;
|
|
262
|
+
const now = typeof progress[id] === "number" ? progress[id] : 0;
|
|
263
|
+
const next = Math.max(0, typeof a.set === "number" ? Math.max(now, a.set) : now + (typeof a.add === "number" ? a.add : 1));
|
|
264
|
+
if (next === now) return;
|
|
265
|
+
progress[id] = next;
|
|
266
|
+
const goal = ctx.runtime.achievementGoals[id];
|
|
267
|
+
const unlocked = (ctx.runtime.system.achievements ??= {}) as Record<string, string>;
|
|
268
|
+
let reached = false;
|
|
269
|
+
if (goal !== undefined && next >= goal && !unlocked[id]) {
|
|
270
|
+
unlocked[id] = new Date().toISOString();
|
|
271
|
+
reached = true;
|
|
272
|
+
}
|
|
273
|
+
return ctx.present({ id, value: next, ...(goal !== undefined ? { goal } : {}), unlocked: reached }, false);
|
|
274
|
+
},
|
|
275
|
+
// アップデートを確かめ、尋ね終えるまで待つ(デスクトップ版で build.update があるときだけ描画側が行う)
|
|
276
|
+
"check-update": (a, ctx) => ctx.present(a, true),
|
|
277
|
+
// 店の画面が閉じるまで待つ(買ったものは描画側が system.purchases に書く)
|
|
278
|
+
purchase: (a, ctx) => ctx.present(a, true),
|
|
279
|
+
"restore-purchases": (a, ctx) => ctx.present(a, true),
|
|
280
|
+
};
|