@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
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type Diagnostic } from "@liminalia/lang";
|
|
2
|
+
import type { RuntimeOptions } from "./runtime.js";
|
|
3
|
+
/** ファイルごとに流す回数の上限の既定(lim coverage --runs、制作画面の全ルートテスト)。選び方を試し終えれば、上限より前に止める。 */
|
|
4
|
+
export declare const DEFAULT_COVERAGE_RUNS = 8;
|
|
5
|
+
export interface CoverageOptions {
|
|
6
|
+
/** 流すファイル(拡張子なし)。 */
|
|
7
|
+
files: readonly string[];
|
|
8
|
+
loadSource(file: string): Promise<string>;
|
|
9
|
+
/** 実行器の設定。onAssign は使わない(流し方が使う)。onStep は通った命令ごとに呼ぶ。 */
|
|
10
|
+
runtime?: RuntimeOptions;
|
|
11
|
+
/** ファイルごとに流す回数の上限。既定 DEFAULT_COVERAGE_RUNS。選び方をすべて試し終えたら、上限より前に止める。 */
|
|
12
|
+
runs?: number;
|
|
13
|
+
/** 乱数の種(random の結果)。種ごとに runs 回まで流す。既定 [1]。 */
|
|
14
|
+
seeds?: readonly number[];
|
|
15
|
+
/**
|
|
16
|
+
* プラグインの命令が教えた行き先("ファイル:行" → 飛び先。@liminalia/lang の promisedTargets)。
|
|
17
|
+
* 通った命令の行き先のうち、画面なしで一度も選択肢(ctx.choose・ctx.pick)に出なかったものを警告にする。
|
|
18
|
+
*/
|
|
19
|
+
promised?: ReadonlyMap<string, readonly string[]>;
|
|
20
|
+
/** 一回流し終えるたびに呼ぶ(done は流し終えた回数、total は全部の回数、file はいま流したファイル)。制作画面の経過の表示。 */
|
|
21
|
+
onProgress?(p: {
|
|
22
|
+
done: number;
|
|
23
|
+
total: number;
|
|
24
|
+
file: string;
|
|
25
|
+
}): void;
|
|
26
|
+
/** 止める合図(止めたら、そこまでの分を返す)。 */
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}
|
|
29
|
+
export interface CoverageReport {
|
|
30
|
+
/** complete は、そのファイルの選び方をすべて試したか(false なら runs の上限か止める合図で打ち切った)。 */
|
|
31
|
+
files: {
|
|
32
|
+
file: string; /** 本文の行。 */
|
|
33
|
+
lines: number[]; /** 通った本文の行。 */
|
|
34
|
+
reached: Set<number>;
|
|
35
|
+
complete: boolean;
|
|
36
|
+
}[];
|
|
37
|
+
/** 実行時の診断(同じものはまとめて、出た回数を数える)。 */
|
|
38
|
+
diagnostics: {
|
|
39
|
+
diagnostic: Diagnostic;
|
|
40
|
+
count: number;
|
|
41
|
+
}[];
|
|
42
|
+
/** 実行の終わり方("end"・"error"・"別ファイルへ" など)→ 回数。前に通った状態に合流して止めた回は数えない。 */
|
|
43
|
+
endings: Map<string, number>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 全ファイルを画面なしで、選択肢の選び方を変えながら何通りか流し、本文の網羅と実行時の診断を集める(lim coverage・制作画面の全ルートテスト)。
|
|
47
|
+
* ファイルごとに先頭から、まだ試していない選び方へ広げながら(route.ts の explore)runs 回まで流す。選び方をすべて試し終えたら、そこで止める。
|
|
48
|
+
* 別のファイルへ移ったら、そのファイルの網羅はそのファイル自身の実行に任せて打ち切る。
|
|
49
|
+
* random は種で決まるので、種を変えないと同じ分かれ方しか通らない。seeds を複数渡すと種ごとに流し直す。
|
|
50
|
+
* promised があれば、通った命令が教えた行き先のうち選択肢に一度も出なかったものを "target-never-offered" の警告にする
|
|
51
|
+
* (画面なしの選び方に入れ忘れた行き先は、網羅でも道筋の探索でも通れないため)。
|
|
52
|
+
*/
|
|
53
|
+
export declare function coverage(o: CoverageOptions): Promise<CoverageReport>;
|
|
54
|
+
export interface RouteCoverageOptions {
|
|
55
|
+
/** 「はじめから」の位置(`ファイル` か `ファイル#ラベル`。liminalia.json の entry)。 */
|
|
56
|
+
entry: string;
|
|
57
|
+
loadSource(file: string): Promise<string>;
|
|
58
|
+
/** 実行器の設定。onAssign は使わない(流し方が使う)。onStep は通った命令ごとに呼ぶ。 */
|
|
59
|
+
runtime?: RuntimeOptions;
|
|
60
|
+
/** 流す回数の上限。既定 8。選び方をすべて試し終えたら、上限より前に止める。 */
|
|
61
|
+
runs?: number;
|
|
62
|
+
seeds?: readonly number[];
|
|
63
|
+
/**
|
|
64
|
+
* プレイを終える命令の行("ファイル:行" → エンディングの名前。@title-screen ending= など)。そこに来たら、その実行はそのエンディングに届いたとして止める。
|
|
65
|
+
*/
|
|
66
|
+
endings?: ReadonlyMap<string, string>;
|
|
67
|
+
}
|
|
68
|
+
export interface RouteCoverageReport {
|
|
69
|
+
/** ファイル → 通った本文の行(ファイルをまたいで流したもの)。 */
|
|
70
|
+
reached: Map<string, Set<number>>;
|
|
71
|
+
/** 届いた終わり方(名前 → 回数)。プレイを終える命令で止まらなかったものは "ファイルの終わり(file:行)" などの名前。 */
|
|
72
|
+
endings: Map<string, number>;
|
|
73
|
+
/**
|
|
74
|
+
* 実行ごとの終わり方と、選んだ選択肢の数。merged は、前に通ったのと同じ状態の選択肢に来たので、その先を流さずに止めた回
|
|
75
|
+
* (ending は止めた場所の名前で、endings には数えない)。
|
|
76
|
+
*/
|
|
77
|
+
runs: {
|
|
78
|
+
seed: number;
|
|
79
|
+
run: number;
|
|
80
|
+
ending: string;
|
|
81
|
+
choices: number;
|
|
82
|
+
at: {
|
|
83
|
+
file: string;
|
|
84
|
+
line: number;
|
|
85
|
+
} | null;
|
|
86
|
+
merged?: true;
|
|
87
|
+
}[];
|
|
88
|
+
/** 選び方をすべて試したか(false なら runs の上限で打ち切った。種のどれかで打ち切れば false)。 */
|
|
89
|
+
complete: boolean;
|
|
90
|
+
diagnostics: {
|
|
91
|
+
diagnostic: Diagnostic;
|
|
92
|
+
count: number;
|
|
93
|
+
}[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 「はじめから」の位置から、ファイルをまたいで最後まで流す(lim coverage のルートの網羅)。ほかのファイルで決めた変数を引き継いだまま進むので、
|
|
97
|
+
* 前の章の選択で分かれる先も通る。選び方は、まだ試していないものへ広げていく(coverage と同じ。route.ts の explore)。
|
|
98
|
+
* プレイを終える命令(endings)に来たら、そのエンディングに届いたとして止める。
|
|
99
|
+
*/
|
|
100
|
+
export declare function routeCoverage(o: RouteCoverageOptions): Promise<RouteCoverageReport>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Diagnostic } from "@liminalia/lang";
|
|
2
|
+
import type { ChoiceLook, Host, PresentEvent } from "./host.js";
|
|
3
|
+
import type { Value } from "./value.js";
|
|
4
|
+
export type TraceEntry =
|
|
5
|
+
/** label は名前欄に出す名前(訳か表示名の上書き。話者と同じなら無い)。 */
|
|
6
|
+
{
|
|
7
|
+
type: "page";
|
|
8
|
+
file: string;
|
|
9
|
+
line: number;
|
|
10
|
+
speaker: string | null;
|
|
11
|
+
label?: string;
|
|
12
|
+
text: string;
|
|
13
|
+
voice?: string;
|
|
14
|
+
} | {
|
|
15
|
+
type: "command";
|
|
16
|
+
name: string;
|
|
17
|
+
args: Record<string, Value>;
|
|
18
|
+
} | {
|
|
19
|
+
type: "choice";
|
|
20
|
+
options: string[];
|
|
21
|
+
selected: number | null;
|
|
22
|
+
} | {
|
|
23
|
+
type: "diagnostic";
|
|
24
|
+
diagnostic: Diagnostic;
|
|
25
|
+
};
|
|
26
|
+
export interface HeadlessOptions {
|
|
27
|
+
loadSource(file: string): Promise<string>;
|
|
28
|
+
/** 作品のデータ(paths.data の .json)を読む(命令の ctx.data)。無ければ命令はデータを読めない。 */
|
|
29
|
+
loadData?(name: string): Promise<unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* 選択肢で選ぶものを順に。数は番号(0 始まり)、文字は選択肢の文(同じ文か、その文を含む選択肢)。使い切ったら policy に従う。
|
|
32
|
+
* 文に当たる選択肢が無ければ診断(unknown-option)を残して policy に従う。
|
|
33
|
+
*/
|
|
34
|
+
choices?: (number | string)[];
|
|
35
|
+
/** 選ぶ番号を使い切ったとき。既定は "first"(最初の選択肢)。 */
|
|
36
|
+
/**
|
|
37
|
+
* 選ぶ番号を使い切ったとき。既定は "rotate"(同じ選択肢に戻ってくるたびに次の選択肢を選ぶ。
|
|
38
|
+
* 外れを選ぶと選択肢に戻る作りでも、いずれ全部を試して先へ進める)。
|
|
39
|
+
*/
|
|
40
|
+
whenChoicesRunOut?: "rotate" | "first" | "stop";
|
|
41
|
+
/** このページ数に達したら止める。 */
|
|
42
|
+
maxPages?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 画面なしで実行する Host。待ちはすべて即座に終わり、出来事を trace に記録する。
|
|
46
|
+
* テスト・CLI の trace・AI による動作確認に使う。
|
|
47
|
+
*/
|
|
48
|
+
export declare class HeadlessHost implements Host {
|
|
49
|
+
private readonly options;
|
|
50
|
+
/**
|
|
51
|
+
* 人が操作せずに流すので、命令の autoplay の答えで進める(Host.automated)。描画側の代わりに答えを返すテスト
|
|
52
|
+
* (present を差し替えて、遊ぶ人の操作を真似る)は false にする。
|
|
53
|
+
*/
|
|
54
|
+
automated: boolean;
|
|
55
|
+
readonly trace: TraceEntry[];
|
|
56
|
+
private page;
|
|
57
|
+
private pages;
|
|
58
|
+
private readonly choices;
|
|
59
|
+
private readonly seenChoices;
|
|
60
|
+
/** 選択肢(場所と文)ごとの、前に出たときのページの数と、ページを挟まずに続けて出た回数(選択肢だけの輪を見つける)。 */
|
|
61
|
+
private readonly choiceLoops;
|
|
62
|
+
onLimit: (() => void) | null;
|
|
63
|
+
/** 今の場所(実行器の at)。選択肢の輪と、選ぶ選択肢が無いときの診断に、選択肢のある行を入れる(無ければ場所なし)。 */
|
|
64
|
+
where: (() => {
|
|
65
|
+
file: string;
|
|
66
|
+
line: number;
|
|
67
|
+
} | null) | null;
|
|
68
|
+
constructor(options: HeadlessOptions);
|
|
69
|
+
loadSource(file: string): Promise<string>;
|
|
70
|
+
loadData(name: string): Promise<unknown>;
|
|
71
|
+
present(event: PresentEvent): Promise<Value | void>;
|
|
72
|
+
waitClick(): Promise<void>;
|
|
73
|
+
/** 診断の場所(where が無ければ場所なし)。 */
|
|
74
|
+
private place;
|
|
75
|
+
choose(texts: string[], _signal?: AbortSignal, looks?: (ChoiceLook | null)[]): Promise<number | null>;
|
|
76
|
+
onDiagnostic(diagnostic: Diagnostic): void;
|
|
77
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { Diagnostic } from "@liminalia/lang";
|
|
2
|
+
import type { Position, StageState, VoiceCue } from "./state.js";
|
|
3
|
+
import type { PrefetchItem } from "./prefetch.js";
|
|
4
|
+
import type { Value } from "./value.js";
|
|
5
|
+
export interface TextStyle {
|
|
6
|
+
bold: boolean;
|
|
7
|
+
italic: boolean;
|
|
8
|
+
color: string | null;
|
|
9
|
+
/** 一文字あたりのミリ秒。null はそのときの既定の速さ。 */
|
|
10
|
+
perChar: number | null;
|
|
11
|
+
/** 文字の大きさ(px)。null は既定の大きさ。 */
|
|
12
|
+
size: number | null;
|
|
13
|
+
/** 背景に引く色(蛍光ペン)。 */
|
|
14
|
+
mark: string | null;
|
|
15
|
+
/** 文字の動き({fx …}。shake・wave・pop・fade・glow)。 */
|
|
16
|
+
fx?: string | null;
|
|
17
|
+
/** 文字の動きの大きさと速さの倍率({fx … strength= speed=}。書かなければ無い)。 */
|
|
18
|
+
fxStrength?: number;
|
|
19
|
+
fxSpeed?: number;
|
|
20
|
+
/** 傍点({dot …})。 */
|
|
21
|
+
emphasis?: boolean;
|
|
22
|
+
/** 本文の中の画像({img …}。image フォルダからのパス)。このときの text は "\uFFFC"。imageHeight は高さ(px)。 */
|
|
23
|
+
image?: string;
|
|
24
|
+
imageHeight?: number;
|
|
25
|
+
}
|
|
26
|
+
/** 選択肢の見た目(@choice の選択肢の行の image= x= など)。書かなかったものは入らない。 */
|
|
27
|
+
export interface ChoiceLook {
|
|
28
|
+
/** 押せない状態で見せる(locked= が真)。 */
|
|
29
|
+
locked?: boolean;
|
|
30
|
+
image?: string;
|
|
31
|
+
hover?: string;
|
|
32
|
+
x?: number;
|
|
33
|
+
y?: number;
|
|
34
|
+
width?: number;
|
|
35
|
+
height?: number;
|
|
36
|
+
/** 上に乗せたときのカーソルの画像と、出す短い説明(調べる場所)。 */
|
|
37
|
+
cursor?: string;
|
|
38
|
+
tip?: string;
|
|
39
|
+
}
|
|
40
|
+
/** 同じページで同時に話すほかの話者(PresentEvent の page の with)。 */
|
|
41
|
+
export interface CoSpeaker {
|
|
42
|
+
speaker: string;
|
|
43
|
+
/** 名前欄に出す名前(@name、訳)。話者名と同じなら省く。 */
|
|
44
|
+
label?: string;
|
|
45
|
+
}
|
|
46
|
+
/** 描画側へ渡す出来事。描画側は表示し終えたら(または待たない指定なら即座に)Promise を解決する。 */
|
|
47
|
+
export type PresentEvent =
|
|
48
|
+
/**
|
|
49
|
+
* 新しいページ。メッセージ枠を空にして話者名を出す(null は地の文)。voice はこのページで鳴らすボイス(@voice・@voice-auto)。
|
|
50
|
+
* label は話者名の訳(多言語)。出すのは label、話者ごとの処理(ボイスの音量・口パク)は speaker で見る。
|
|
51
|
+
* key はページの鍵(@liminalia/lang の pageKeys。行を足しても変わらない。既読を覚えるのに使う)。
|
|
52
|
+
* with は同じページで同時に話すほかの話者(二つ目のボイスの who。話者と同じ人は入れない)。label はその人の名前欄の名前(話者名と違うときだけ)。
|
|
53
|
+
*/
|
|
54
|
+
{
|
|
55
|
+
type: "page";
|
|
56
|
+
speaker: string | null;
|
|
57
|
+
label?: string;
|
|
58
|
+
at: {
|
|
59
|
+
file: string;
|
|
60
|
+
line: number;
|
|
61
|
+
};
|
|
62
|
+
key?: string;
|
|
63
|
+
voice?: VoiceCue;
|
|
64
|
+
with?: CoSpeaker[];
|
|
65
|
+
} | {
|
|
66
|
+
type: "text";
|
|
67
|
+
text: string;
|
|
68
|
+
ruby: string | null;
|
|
69
|
+
style: TextStyle;
|
|
70
|
+
} | {
|
|
71
|
+
type: "br";
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 命令を実行した。stage は実行後の状態。wait が true なら演出が終わるまで解決しない。
|
|
75
|
+
* skip は演出の命令に付く。true ならクリックで演出を終わりまで早送りでき、false なら早送りしない(命令の skip=false)。
|
|
76
|
+
* 演出でない命令(音、入力を待つ画面など)には付かない。
|
|
77
|
+
* autoplay は自動確認(Host.automated)で命令の autoplay が答えを出すときに付く。描画側は描かずにすぐ返す(画面なしの記録には残す)。
|
|
78
|
+
* interactive は autoplay を持つ命令(遊ぶ人の操作を待つ画面や動画)を、自動確認でないので描かせるときに付く。描画側は描いている間、
|
|
79
|
+
* 操作待ちの画面を出していると撮影(lim shot)に知らせる。
|
|
80
|
+
* afterPage は、メッセージ枠のページをクリックで送ってから最初に渡す命令に付く(TyranoScript の [p] の改ページと同じく、
|
|
81
|
+
* 描画側はここで前のページの名前と本文を消し、枠は残す。ui.message.keepText か、@bg の keep-text=true なら消さない)。
|
|
82
|
+
*/
|
|
83
|
+
| {
|
|
84
|
+
type: "command";
|
|
85
|
+
name: string;
|
|
86
|
+
args: Record<string, Value>;
|
|
87
|
+
wait: boolean;
|
|
88
|
+
stage: StageState;
|
|
89
|
+
skip?: boolean;
|
|
90
|
+
autoplay?: boolean;
|
|
91
|
+
interactive?: boolean;
|
|
92
|
+
afterPage?: boolean;
|
|
93
|
+
};
|
|
94
|
+
export interface Host {
|
|
95
|
+
/** ファイル名(拡張子なし)から .lim の中身を返す。 */
|
|
96
|
+
loadSource(file: string): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* 作品のデータ(paths.data の .json。name はそこからのパスで `.json` を省ける)を JSON として読む。無ければ undefined。
|
|
99
|
+
* 命令は ctx.data で読む(図鑑・調べる場所など、作品のデータで動く標準の命令が使う)。省略可。
|
|
100
|
+
*/
|
|
101
|
+
loadData?(name: string): Promise<unknown>;
|
|
102
|
+
/** 命令によっては結果(選ばれた行き先など)を返す。 */
|
|
103
|
+
present(event: PresentEvent, signal: AbortSignal): Promise<Value | void>;
|
|
104
|
+
/** クリック(本文の送り)を待つ。 */
|
|
105
|
+
waitClick(signal: AbortSignal): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* 選択肢から一つ選ぶ。null なら実行を終える。
|
|
108
|
+
* looks は選択肢ごとの見た目(文字のボタンなら null)。画像のボタンや押せる範囲のときだけ渡る。
|
|
109
|
+
* targets は選択肢ごとの飛び先("ファイル" か "ファイル#ラベル"。式の飛び先などで分からなければ null)。
|
|
110
|
+
* 描画側は使わない。画面なしで流す道筋の探索が、目標に近い選択肢から試すのに使う。
|
|
111
|
+
*/
|
|
112
|
+
choose(options: string[], signal: AbortSignal, looks?: (ChoiceLook | null)[], targets?: (string | null)[]): Promise<number | null>;
|
|
113
|
+
/**
|
|
114
|
+
* @choice の選択肢を選んだ(時間切れで default を選んだときも。call=true の選択肢は除く)。text は選んだ選択肢の文(訳したもの。
|
|
115
|
+
* 画像のボタンなどで文が無ければ空)、index は出した選択肢の中の番号。履歴に残すのに使う。省略可。
|
|
116
|
+
*/
|
|
117
|
+
chosen?(option: {
|
|
118
|
+
text: string;
|
|
119
|
+
index: number;
|
|
120
|
+
}): void;
|
|
121
|
+
/**
|
|
122
|
+
* 選択肢の制限時間(@choice timeout=)を計り、ms だけ経ったら解決する。描画側は、システム画面を開いている間などは
|
|
123
|
+
* 時間を止めておける。signal で打ち切ったら解決しなくてよい。省略すると実時間で計る(画面なしで流すときなど)。
|
|
124
|
+
*/
|
|
125
|
+
countdown?(ms: number, signal: AbortSignal): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* この先で使う素材を先に読んでおく(ページを出すたびに呼ぶ)。待たずに返す。省略可。
|
|
128
|
+
* 同じものが何度も来るので、描画側で重複を除く。
|
|
129
|
+
*/
|
|
130
|
+
prefetch?(items: PrefetchItem[]): void;
|
|
131
|
+
/** @script を実行する。省略時は実行せず診断を出す。 */
|
|
132
|
+
runScript?(code: string, at: Position): Promise<void>;
|
|
133
|
+
onDiagnostic?(diagnostic: Diagnostic): void;
|
|
134
|
+
/**
|
|
135
|
+
* 自動確認(lim playtest・lim shot・全ルートテストなど、人が操作せずに流す)で動いているか。true なら、autoplay を持つ命令
|
|
136
|
+
* (遊ぶ人の操作を待つ画面や動画)は描かずに、命令の autoplay の答えで進める。画面なしの Host(HeadlessHost)は常に true。
|
|
137
|
+
* 実行器は命令ごとに読み直すので、途中で変えてよい(lim shot は撮る所に着いたら false にして、その画面を描かせる)。
|
|
138
|
+
*/
|
|
139
|
+
readonly automated?: boolean;
|
|
140
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { Runtime, type Args, type CommandContext, type CommandImpl, type PickOutcome, type Platform, type ProgramCache, type RunResult, type RuntimeOptions, type StartOptions, type Translator } from "./runtime.js";
|
|
2
|
+
export type { ChoiceLook, CoSpeaker, Host, PresentEvent, TextStyle } from "./host.js";
|
|
3
|
+
export { buildProgram, type Instruction, type Program, type Unit } from "./program.js";
|
|
4
|
+
export { createState, initialStage, toSaveData, voiceFile, type NvlPage, type NvlPart, type VoiceAuto, type VoiceCue, type GameState, type Position, type SaveData, type Snapshot, type Sprite, type StageState, type Balloon, type SceneWait, type SoundOptions, type SoundFilterState } from "./state.js";
|
|
5
|
+
export { CHAT_KEEP, CHAT_KEY, chatDialogueActive, chatPartsText, chatQuoteStripper, clearChatMessages, pushChatMessage, readChat, type Chat, type ChatDialogue, type ChatMessage } from "./chat.js";
|
|
6
|
+
export { argOrigin, textOrigins, I18N_FIELD, type TextOrigin } from "./retranslate.js";
|
|
7
|
+
export { display, equals, evaluate, EvalError, setPluginFunctionImpls, truthy, type Scope, type Value } from "./value.js";
|
|
8
|
+
export { CORE_IMPLEMENTATIONS } from "./commands.js";
|
|
9
|
+
export { HeadlessHost, type HeadlessOptions, type TraceEntry } from "./headless.js";
|
|
10
|
+
export { collectPrefetch, type PrefetchItem } from "./prefetch.js";
|
|
11
|
+
export { capture, explore, findRoute, walk, type Assignments, type ChoiceMade, type Exploration, type ExploreOptions, type FindRouteOptions, type Reached, type Walk, type WalkOptions } from "./route.js";
|
|
12
|
+
export { coverage, DEFAULT_COVERAGE_RUNS, routeCoverage, type CoverageOptions, type CoverageReport, type RouteCoverageOptions, type RouteCoverageReport } from "./coverage.js";
|
|
13
|
+
export { observeVoiceNumbers } from "./voice-observe.js";
|
|
14
|
+
export { projectRuntimeOptions, RUNTIME_OPTION_OWNERS, type ProjectRuntimeConfig, type ProjectRuntimeOptions, type ProjectRuntimeSource } from "./project-options.js";
|
|
15
|
+
export { DEFAULT_TEST_LIMIT, runScenarioTest, type ScenarioTestOptions, type ScenarioTestResult, type TestFailure } from "./scenario-test.js";
|
|
16
|
+
export { migrateSave, migrateWith, saveProblem, SAVE_VERSION, SaveVersionError, type SaveProblem } from "./save.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Registry } from "@liminalia/lang";
|
|
2
|
+
import type { Unit } from "./program.js";
|
|
3
|
+
/** 先読みしてほしい素材。立ち絵はキャストの定義から画像を求めるので、名前の組で渡す。 */
|
|
4
|
+
export type PrefetchItem = {
|
|
5
|
+
kind: "asset";
|
|
6
|
+
folder: string;
|
|
7
|
+
path: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: "sprite";
|
|
10
|
+
who: string;
|
|
11
|
+
appearance: string;
|
|
12
|
+
variant: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* index から先の limit 個の命令(本文中の命令と、選択肢の画像も含む)が使う素材を集める。
|
|
16
|
+
* 分岐は両方とも見る(どちらへ進んでも間に合うように)。式で書いた引数は評価せずに飛ばす(副作用を起こさないため)。
|
|
17
|
+
*/
|
|
18
|
+
export declare function collectPrefetch(unit: Unit, index: number, registry: Registry, limit?: number): PrefetchItem[];
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type Argument, type ChoiceOption, type Expr, type Inline, type Param, type Script, type Target } from "@liminalia/lang";
|
|
2
|
+
/**
|
|
3
|
+
* 実行単位。ファイル本体と、各 @define の本体がそれぞれ一つの Unit になる。
|
|
4
|
+
* 制御構文は条件ジャンプに展開してあり、実行位置は (unit, index) の二つの値で表せる。
|
|
5
|
+
* そのためセーブデータに実行位置をそのまま書ける。
|
|
6
|
+
*/
|
|
7
|
+
export interface Unit {
|
|
8
|
+
/** "chapter1" または "chapter1::title-card"。 */
|
|
9
|
+
id: string;
|
|
10
|
+
file: string;
|
|
11
|
+
instructions: Instruction[];
|
|
12
|
+
/** ラベル名 → 位置(ファイル本体の Unit だけが持つ)。 */
|
|
13
|
+
labels: Record<string, number>;
|
|
14
|
+
/** @if の中にあるラベル(飛び込めない。検査ではエラー)。 */
|
|
15
|
+
nestedLabels?: Set<string>;
|
|
16
|
+
/** @define の Unit だけが持つ。 */
|
|
17
|
+
params?: Param[];
|
|
18
|
+
}
|
|
19
|
+
export type Instruction =
|
|
20
|
+
/** name はこの行だけ名前欄に出す名前(話者{name …})。id は行末の固定の行 ID(#line:ID。訳の鍵)。 */
|
|
21
|
+
{
|
|
22
|
+
op: "say";
|
|
23
|
+
speaker: string | null;
|
|
24
|
+
name?: Inline[];
|
|
25
|
+
content: Inline[];
|
|
26
|
+
line: number;
|
|
27
|
+
id?: string;
|
|
28
|
+
}
|
|
29
|
+
/** body は @end までの行をそのまま持つ命令(@html)の中身。content は @with で渡す中身の実行単位の id。 */
|
|
30
|
+
| {
|
|
31
|
+
op: "command";
|
|
32
|
+
name: string;
|
|
33
|
+
args: Argument[];
|
|
34
|
+
body?: string;
|
|
35
|
+
content?: string;
|
|
36
|
+
line: number;
|
|
37
|
+
} | {
|
|
38
|
+
op: "branch";
|
|
39
|
+
condition: Expr; /** 偽のときの飛び先 */
|
|
40
|
+
otherwise: number;
|
|
41
|
+
line: number;
|
|
42
|
+
} | {
|
|
43
|
+
op: "goto";
|
|
44
|
+
to: number;
|
|
45
|
+
line: number;
|
|
46
|
+
} | {
|
|
47
|
+
op: "choice";
|
|
48
|
+
options: ChoiceOption[];
|
|
49
|
+
args?: Argument[];
|
|
50
|
+
line: number;
|
|
51
|
+
} | {
|
|
52
|
+
op: "set";
|
|
53
|
+
target: Expr;
|
|
54
|
+
operator: "=" | "+=" | "-=" | "*=" | "/=";
|
|
55
|
+
value: Expr;
|
|
56
|
+
line: number;
|
|
57
|
+
} | {
|
|
58
|
+
op: "let";
|
|
59
|
+
name: string;
|
|
60
|
+
value: Expr;
|
|
61
|
+
line: number;
|
|
62
|
+
} | {
|
|
63
|
+
op: "jump" | "call";
|
|
64
|
+
target: Target;
|
|
65
|
+
line: number;
|
|
66
|
+
}
|
|
67
|
+
/** value はマクロの戻り値(@return (式))。 */
|
|
68
|
+
| {
|
|
69
|
+
op: "return";
|
|
70
|
+
value?: Expr;
|
|
71
|
+
line: number;
|
|
72
|
+
}
|
|
73
|
+
/** @with で渡された中身を実行する(@define の中の @content)。 */
|
|
74
|
+
| {
|
|
75
|
+
op: "content";
|
|
76
|
+
line: number;
|
|
77
|
+
} | {
|
|
78
|
+
op: "script";
|
|
79
|
+
code: string;
|
|
80
|
+
line: number;
|
|
81
|
+
} | {
|
|
82
|
+
op: "label";
|
|
83
|
+
name: string;
|
|
84
|
+
line: number;
|
|
85
|
+
};
|
|
86
|
+
export interface Program {
|
|
87
|
+
file: string;
|
|
88
|
+
main: Unit;
|
|
89
|
+
defines: Map<string, Unit>;
|
|
90
|
+
/** @use したファイル(ここにある @define を呼べる)。 */
|
|
91
|
+
uses: string[];
|
|
92
|
+
/** 台詞の行 → ボイスの番号の固定の鍵(voice-lock.json)。 */
|
|
93
|
+
voiceKeys: Map<number, string>;
|
|
94
|
+
/** 本文の行 → ページの鍵(既読を覚えるのに使う。@liminalia/lang の pageKeys)。 */
|
|
95
|
+
pageKeys: Map<number, string>;
|
|
96
|
+
/** @function で作った式の関数(名前 → 引数と中身)。 */
|
|
97
|
+
functions: Map<string, UserFunction>;
|
|
98
|
+
}
|
|
99
|
+
/** @function で作った式の関数。file は書いたファイル(中から呼ぶ関数はそのファイルから探す)。 */
|
|
100
|
+
export interface UserFunction {
|
|
101
|
+
file: string;
|
|
102
|
+
params: string[];
|
|
103
|
+
body: Expr;
|
|
104
|
+
}
|
|
105
|
+
export declare function buildProgram(script: Script): Program;
|
|
106
|
+
/** @for が回すものを配列にする式の関数(実行器だけが呼ぶ。名前は式からは書けない。value.ts)。 */
|
|
107
|
+
export declare const EACH_FUNCTION = "@each";
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type CastEntry, type VoiceLock } from "@liminalia/lang";
|
|
2
|
+
import type { CommandImpl, RuntimeOptions, Translator } from "./runtime.js";
|
|
3
|
+
/**
|
|
4
|
+
* 作品の設定から実行器の設定(RuntimeOptions)を作る。遊ぶ側(packages/web)と、画面なしで流すもの(lim trace、lim test、lim coverage、
|
|
5
|
+
* lim reach、lim build --seed、lim voice-lock、制作画面の現在地と全ルートテスト、VS Code の「ここからテストプレイ」)は、どれもこれで作り、
|
|
6
|
+
* 流し方で変えるもの(RUNTIME_OPTION_OWNERS で caller にしたもの)だけを呼ぶ側が足す。片方にだけ作品の設定を渡して、
|
|
7
|
+
* 同じ台本を流した結果が食い違う(自動配置が外れる、言語や章や版で分かれる先が違う、台詞の括弧やボイスの番号が違う)ことを防ぐ。
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* 実行器の設定の一つ一つを、だれが決めるか。
|
|
11
|
+
* - "project": projectRuntimeOptions が作品の設定から埋める
|
|
12
|
+
* - { caller }: 呼ぶ側が決める(その理由)
|
|
13
|
+
* 実行器の設定を足したら、ここで分けるまで型の確かめが通らない(project-options.test.ts は、関数が埋める項目がここの "project" と
|
|
14
|
+
* ちょうど同じことを見る)。
|
|
15
|
+
*/
|
|
16
|
+
export declare const RUNTIME_OPTION_OWNERS: {
|
|
17
|
+
readonly speakers: "project";
|
|
18
|
+
readonly commands: "project";
|
|
19
|
+
readonly commandDefaults: "project";
|
|
20
|
+
readonly variables: "project";
|
|
21
|
+
readonly afterLoad: "project";
|
|
22
|
+
readonly gameVersion: "project";
|
|
23
|
+
readonly chapters: "project";
|
|
24
|
+
readonly achievementGoals: "project";
|
|
25
|
+
readonly endingAchievements: "project";
|
|
26
|
+
readonly endingKinds: "project";
|
|
27
|
+
readonly cast: "project";
|
|
28
|
+
readonly autoLayout: "project";
|
|
29
|
+
readonly voiceLock: "project";
|
|
30
|
+
readonly cg: "project";
|
|
31
|
+
readonly chatDialogue: "project";
|
|
32
|
+
readonly inlineChoices: "project";
|
|
33
|
+
readonly stripQuotes: "project";
|
|
34
|
+
readonly language: "project";
|
|
35
|
+
readonly translator: "project";
|
|
36
|
+
readonly loadData: "project";
|
|
37
|
+
readonly seed: {
|
|
38
|
+
readonly caller: "乱数の種。遊ぶ側は決めず、台本のテストと網羅は回ごとに決める";
|
|
39
|
+
};
|
|
40
|
+
readonly maxSteps: {
|
|
41
|
+
readonly caller: "命令の数の上限。流し方ごとに、終わらない繰り返しで止める所が違う";
|
|
42
|
+
};
|
|
43
|
+
readonly onError: {
|
|
44
|
+
readonly caller: "実行時のエラーで止めるか。遊ぶ側と画面なしの流しは続けて知らせる(continue)が、実行器の既定は止める";
|
|
45
|
+
};
|
|
46
|
+
readonly returnWithoutCall: {
|
|
47
|
+
readonly caller: "呼ばれていない @return の扱い。網羅のファイルごとの流しだけが、@call で呼ぶだけのファイルを先頭から流すので続ける";
|
|
48
|
+
};
|
|
49
|
+
readonly onAssign: {
|
|
50
|
+
readonly caller: "変数を入れたときの知らせ。制作画面が値を決めた行を控えるためのもので、流し方が使う";
|
|
51
|
+
};
|
|
52
|
+
readonly onStep: {
|
|
53
|
+
readonly caller: "命令の前の知らせ。網羅と台本のテストが通った行を数えるためのもので、流し方が使う";
|
|
54
|
+
};
|
|
55
|
+
readonly beforeStep: {
|
|
56
|
+
readonly caller: "命令の前で待つ。遊ぶ側の作品の画面とブレークポイントだけが使う";
|
|
57
|
+
};
|
|
58
|
+
readonly programCache: {
|
|
59
|
+
readonly caller: "読んだ台本の控え。遊ぶ側が一回のプレイを作り直しても読み解き直さないためのもので、流し方が持つ";
|
|
60
|
+
};
|
|
61
|
+
readonly platform: {
|
|
62
|
+
readonly caller: "遊んでいる機種。遊ぶ側は調べて入れ、画面なしの流しは省いてパソコンのブラウザとする";
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
type ProjectKey = {
|
|
66
|
+
[K in keyof typeof RUNTIME_OPTION_OWNERS]: (typeof RUNTIME_OPTION_OWNERS)[K] extends "project" ? K : never;
|
|
67
|
+
}[keyof typeof RUNTIME_OPTION_OWNERS];
|
|
68
|
+
/** projectRuntimeOptions が埋める実行器の設定。 */
|
|
69
|
+
export type ProjectRuntimeOptions = Pick<RuntimeOptions, ProjectKey>;
|
|
70
|
+
/** 作品の設定(liminalia.json)の、実行器に効く項目。読んだ JSON のままでよい(形の違う値は使わない。lim check が知らせる)。 */
|
|
71
|
+
export interface ProjectRuntimeConfig {
|
|
72
|
+
version?: unknown;
|
|
73
|
+
variables?: unknown;
|
|
74
|
+
afterLoad?: unknown;
|
|
75
|
+
commandDefaults?: unknown;
|
|
76
|
+
chapters?: unknown;
|
|
77
|
+
extra?: unknown;
|
|
78
|
+
endingKinds?: unknown;
|
|
79
|
+
autoLayout?: unknown;
|
|
80
|
+
ui?: unknown;
|
|
81
|
+
languages?: unknown;
|
|
82
|
+
}
|
|
83
|
+
/** 実行器の設定を作る元。ファイルを読むのは呼ぶ側(ブラウザでも Node でも使うため)。 */
|
|
84
|
+
export interface ProjectRuntimeSource {
|
|
85
|
+
config: ProjectRuntimeConfig;
|
|
86
|
+
/** 話者(cast.json の speakers)。 */
|
|
87
|
+
speakers: Iterable<string>;
|
|
88
|
+
/** 組み込みの外の命令(標準の命令と、作品のプラグインの命令)。 */
|
|
89
|
+
commands: readonly CommandImpl[];
|
|
90
|
+
/** キャストの定義(cast.json の cast)。 */
|
|
91
|
+
cast: Readonly<Record<string, CastEntry>> | Readonly<Record<string, unknown>>;
|
|
92
|
+
/** 連番のボイスの番号の固定(voice-lock.json。無い・読めなければ null)。 */
|
|
93
|
+
voiceLock?: VoiceLock | null;
|
|
94
|
+
/** 作品のデータを読む(画面なしで流すとき。遊ぶ側は描画側が読むので渡さない)。 */
|
|
95
|
+
loadData?(name: string): unknown;
|
|
96
|
+
/** 遊ぶ言語。省けば原文の言語(languages の先頭。無ければ ""。遊ぶ側が言語を選ばないときと同じ)。 */
|
|
97
|
+
language?: string;
|
|
98
|
+
/** その言語の訳。省けば訳さない(原文の言語で流すとき)。 */
|
|
99
|
+
translator?: Translator | null;
|
|
100
|
+
}
|
|
101
|
+
/** 作品の設定から実行器の設定を作る(RUNTIME_OPTION_OWNERS で "project" にしたもの)。 */
|
|
102
|
+
export declare function projectRuntimeOptions(src: ProjectRuntimeSource): ProjectRuntimeOptions;
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Args } from "./runtime.js";
|
|
2
|
+
import type { Value } from "./value.js";
|
|
3
|
+
/**
|
|
4
|
+
* 置いたままの文字(@layer-text の文字、チャットの吹き出しなど、状態の stage.extra に残る文字)を、言語を替えたときと
|
|
5
|
+
* 別の言語でロードしたときに、今の言語で出し直すための元。
|
|
6
|
+
*
|
|
7
|
+
* 文字を持つものは、その横に `i18n: { 名前: TextOrigin }` を置く(名前はその文字を入れておく欄。text・title・label など)。
|
|
8
|
+
* Runtime.retranslate が stage.extra をたどり、i18n を持つものの欄を今の言語の訳に書き換える。
|
|
9
|
+
* - arg: コマンドの文字(仕様で translate: "text" の引数に字面で書いたもの)
|
|
10
|
+
* - line: 本文の行(チャットの吹き出し。欄の文字と、ルビや装飾つきの一片 parts を作り直す)
|
|
11
|
+
* - option: 選択肢の文
|
|
12
|
+
* - speaker: 話者名と表示名(欄が label で、訳が話者と同じなら label を外す)
|
|
13
|
+
*/
|
|
14
|
+
export interface TextOrigin {
|
|
15
|
+
kind: "arg" | "line" | "option" | "speaker";
|
|
16
|
+
/** 書いたファイル(speaker は無い)。 */
|
|
17
|
+
file?: string;
|
|
18
|
+
/** 原文(本文の行と選択肢は printInline で書き直したもの)。 */
|
|
19
|
+
source: string;
|
|
20
|
+
/** 場面(直前のラベル。訳のファイルの contexts)。 */
|
|
21
|
+
context?: string;
|
|
22
|
+
/** 行末の固定の行 ID(#line:ID。本文の行と選択肢。あれば ID で訳を引く)。 */
|
|
23
|
+
id?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const I18N_FIELD = "i18n";
|
|
26
|
+
/** 引数の文字の元を控える(実行器の resolveArgs だけが使う)。 */
|
|
27
|
+
export declare function noteArgOrigin(args: Args, name: string, origin: TextOrigin): void;
|
|
28
|
+
/**
|
|
29
|
+
* 命令の引数の、訳す印(translate: "text")のある文字の元。字面で書いた文字だけにあり、式で書いた文字には無い。
|
|
30
|
+
* 置いた文字を状態に残す命令は、これを i18n に入れておくと、言語を替えたときに出し直される。
|
|
31
|
+
*/
|
|
32
|
+
export declare function argOrigin(args: Args, name: string): TextOrigin | undefined;
|
|
33
|
+
/** i18n を一つ作る(元の無い欄は入れない。どれも無ければ undefined)。 */
|
|
34
|
+
export declare function textOrigins(fields: Record<string, TextOrigin | undefined>): Record<string, TextOrigin> | undefined;
|
|
35
|
+
/** stage.extra などの中で、i18n を持つものを順に渡す。 */
|
|
36
|
+
export declare function withOrigins(value: unknown, depth?: number): Generator<{
|
|
37
|
+
target: Record<string, Value>;
|
|
38
|
+
origins: Record<string, TextOrigin>;
|
|
39
|
+
}>;
|