@flare-engine/dialogue 0.2.0 → 0.3.0
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 +201 -21
- package/NOTICE +2 -0
- package/README.md +11 -10
- package/dist/index.d.mts +111 -93
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +111 -93
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +251 -240
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +242 -206
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Signal } from
|
|
2
|
-
|
|
1
|
+
import { Signal } from "@flare-engine/events";
|
|
2
|
+
//#region src/graph.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Dialogue graph data types.
|
|
5
5
|
*
|
|
@@ -13,117 +13,134 @@ import { Signal } from '@flare-engine/events';
|
|
|
13
13
|
* Graphs are plain JSON — no classes, no runtime coupling.
|
|
14
14
|
*/
|
|
15
15
|
interface LineNode {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
readonly kind: 'line';
|
|
17
|
+
/** Speaker name / id. */
|
|
18
|
+
readonly speaker: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional portrait key resolved by the UI layer to an avatar image /
|
|
21
|
+
* shape / atlas frame. The dialogue runtime is portrait-agnostic — it
|
|
22
|
+
* forwards the key via `DialogueLineEvent.speakerPortraitKey`.
|
|
23
|
+
*/
|
|
24
|
+
readonly speakerPortraitKey?: string;
|
|
25
|
+
/** Text template. Supports `{var}` interpolation via the runner's variable bag. */
|
|
26
|
+
readonly text: string;
|
|
27
|
+
/** Next node id, or null to end. */
|
|
28
|
+
readonly next: string | null;
|
|
29
29
|
}
|
|
30
30
|
interface ChoiceOption {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
/** Display text. Supports `{var}` interpolation. */
|
|
32
|
+
readonly text: string;
|
|
33
|
+
/** Node id to jump to when selected. */
|
|
34
|
+
readonly next: string;
|
|
35
|
+
/** Optional condition key — option is hidden when condition returns false. */
|
|
36
|
+
readonly condition?: string;
|
|
37
37
|
}
|
|
38
38
|
interface ChoiceNode {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
readonly kind: 'choice';
|
|
40
|
+
/** Optional prompt text before the choices. */
|
|
41
|
+
readonly prompt?: string;
|
|
42
|
+
/** Speaker for the prompt, if any. */
|
|
43
|
+
readonly speaker?: string;
|
|
44
|
+
readonly options: readonly ChoiceOption[];
|
|
45
45
|
}
|
|
46
46
|
interface BranchArm {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
/** Condition key evaluated by the runner's condition resolver. */
|
|
48
|
+
readonly condition: string;
|
|
49
|
+
/** Node id to jump to when condition is true. */
|
|
50
|
+
readonly next: string;
|
|
51
51
|
}
|
|
52
52
|
interface BranchNode {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
readonly kind: 'branch';
|
|
54
|
+
readonly arms: readonly BranchArm[];
|
|
55
|
+
/** Fallback node id if no arm matches. Null → end. */
|
|
56
|
+
readonly fallback: string | null;
|
|
57
57
|
}
|
|
58
58
|
interface ActionNode {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
readonly kind: 'action';
|
|
60
|
+
/** Callback key. Runner looks this up in the action registry. */
|
|
61
|
+
readonly action: string;
|
|
62
|
+
/** Next node id after the action fires. */
|
|
63
|
+
readonly next: string | null;
|
|
64
64
|
}
|
|
65
65
|
interface EndNode {
|
|
66
|
-
|
|
66
|
+
readonly kind: 'end';
|
|
67
67
|
}
|
|
68
68
|
type DialogueNode = LineNode | ChoiceNode | BranchNode | ActionNode | EndNode;
|
|
69
69
|
interface DialogueGraph {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
/** Unique graph identifier. */
|
|
71
|
+
readonly id: string;
|
|
72
|
+
/** Node id to start from. */
|
|
73
|
+
readonly start: string;
|
|
74
|
+
/** All nodes keyed by id. */
|
|
75
|
+
readonly nodes: Record<string, DialogueNode>;
|
|
76
76
|
}
|
|
77
77
|
declare function createDialogueGraph(id: string, start: string, nodes: Record<string, DialogueNode>): DialogueGraph;
|
|
78
78
|
declare function getNode(graph: DialogueGraph, nodeId: string): DialogueNode | undefined;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/runner.d.ts
|
|
81
|
+
type DialogueErrorCode = 'missing-node' | 'cycle';
|
|
82
|
+
declare class DialogueError extends Error {
|
|
83
|
+
readonly code: DialogueErrorCode;
|
|
84
|
+
/** Source node whose transition triggered the error (or the entry id when there is no source). */
|
|
85
|
+
readonly nodeId: string;
|
|
86
|
+
/** 'missing-node': the target id that could not be resolved. */
|
|
87
|
+
readonly missingId?: string;
|
|
88
|
+
/** 'cycle': the node-id chain walked before the step budget was exceeded. */
|
|
89
|
+
readonly chain?: readonly string[];
|
|
90
|
+
constructor(code: DialogueErrorCode, message: string, detail: {
|
|
91
|
+
nodeId: string;
|
|
92
|
+
missingId?: string;
|
|
93
|
+
chain?: readonly string[];
|
|
94
|
+
});
|
|
95
|
+
}
|
|
85
96
|
type ConditionResolver = (key: string) => boolean;
|
|
86
97
|
type ActionHandler = (key: string) => void | Promise<void>;
|
|
87
98
|
type VariableBag = Record<string, string | number>;
|
|
88
99
|
interface DialogueLineEvent {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
100
|
+
readonly speaker: string;
|
|
101
|
+
/** Optional portrait key forwarded verbatim from the source LineNode. */
|
|
102
|
+
readonly speakerPortraitKey?: string;
|
|
103
|
+
readonly text: string;
|
|
104
|
+
readonly nodeId: string;
|
|
94
105
|
}
|
|
95
106
|
interface DialogueChoiceEvent {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
107
|
+
readonly prompt: string | undefined;
|
|
108
|
+
readonly speaker: string | undefined;
|
|
109
|
+
readonly options: readonly ActiveOption[];
|
|
110
|
+
readonly nodeId: string;
|
|
100
111
|
}
|
|
101
112
|
interface ActiveOption {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
113
|
+
readonly index: number;
|
|
114
|
+
readonly text: string;
|
|
115
|
+
readonly next: string;
|
|
105
116
|
}
|
|
106
117
|
type DialogueRunnerState = 'idle' | 'running' | 'waiting-choice' | 'ended';
|
|
107
118
|
declare function interpolate(template: string, vars: VariableBag): string;
|
|
108
119
|
interface DialogueRunner {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
readonly onLine: Signal<DialogueLineEvent>;
|
|
121
|
+
readonly onChoice: Signal<DialogueChoiceEvent>;
|
|
122
|
+
readonly onAction: Signal<string>;
|
|
123
|
+
readonly onEnd: Signal<string>;
|
|
124
|
+
readonly state: DialogueRunnerState;
|
|
125
|
+
readonly currentNodeId: string | null;
|
|
126
|
+
readonly graphId: string | null;
|
|
127
|
+
start(graph: DialogueGraph, variables?: VariableBag): void;
|
|
128
|
+
advance(): void;
|
|
129
|
+
selectChoice(index: number): void;
|
|
130
|
+
stop(): void;
|
|
120
131
|
}
|
|
121
132
|
interface DialogueRunnerOptions {
|
|
122
|
-
|
|
123
|
-
|
|
133
|
+
conditions?: ConditionResolver;
|
|
134
|
+
actions?: ActionHandler;
|
|
135
|
+
/**
|
|
136
|
+
* Invoked on a recoverable dialogue error — currently a transition to a
|
|
137
|
+
* missing node. Default (no hook): logs a console.warn, then ends.
|
|
138
|
+
*/
|
|
139
|
+
onError?: (err: DialogueError) => void;
|
|
124
140
|
}
|
|
125
141
|
declare function createDialogueRunner(options?: DialogueRunnerOptions): DialogueRunner;
|
|
126
|
-
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/text-reveal.d.ts
|
|
127
144
|
/**
|
|
128
145
|
* Text-over-time reveal hook for dialogue lines.
|
|
129
146
|
*
|
|
@@ -132,24 +149,25 @@ declare function createDialogueRunner(options?: DialogueRunnerOptions): Dialogue
|
|
|
132
149
|
* Supports per-character speed, instant-complete, and pause-on-punctuation.
|
|
133
150
|
*/
|
|
134
151
|
interface TextRevealState {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
152
|
+
/** Full text being revealed. */
|
|
153
|
+
readonly fullText: string;
|
|
154
|
+
/** Characters revealed so far. */
|
|
155
|
+
visibleText: string;
|
|
156
|
+
/** Whether the full text has been revealed. */
|
|
157
|
+
complete: boolean;
|
|
158
|
+
/** Internal fractional character cursor. */
|
|
159
|
+
_cursor: number;
|
|
143
160
|
}
|
|
144
161
|
interface TextRevealOptions {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
162
|
+
/** Characters per second. Default: 30. */
|
|
163
|
+
speed?: number;
|
|
164
|
+
/** Extra delay (in seconds) after punctuation (.!?). Default: 0.15. */
|
|
165
|
+
punctuationDelay?: number;
|
|
149
166
|
}
|
|
150
167
|
declare function createTextReveal(text: string): TextRevealState;
|
|
151
168
|
declare function updateTextReveal(state: TextRevealState, dt: number, options?: TextRevealOptions): void;
|
|
152
169
|
declare function completeTextReveal(state: TextRevealState): void;
|
|
153
170
|
declare function resetTextReveal(state: TextRevealState, newText?: string): void;
|
|
154
|
-
|
|
155
|
-
export { type ActionHandler, type ActionNode, type ActiveOption, type BranchArm, type BranchNode, type ChoiceNode, type ChoiceOption, type ConditionResolver, type DialogueChoiceEvent, type DialogueGraph, type DialogueLineEvent, type DialogueNode, type DialogueRunner, type DialogueRunnerOptions, type DialogueRunnerState, type EndNode, type LineNode, type TextRevealOptions, type TextRevealState, type VariableBag, completeTextReveal, createDialogueGraph, createDialogueRunner, createTextReveal, getNode, interpolate, resetTextReveal, updateTextReveal };
|
|
171
|
+
//#endregion
|
|
172
|
+
export { type ActionHandler, type ActionNode, type ActiveOption, type BranchArm, type BranchNode, type ChoiceNode, type ChoiceOption, type ConditionResolver, type DialogueChoiceEvent, DialogueError, type DialogueErrorCode, type DialogueGraph, type DialogueLineEvent, type DialogueNode, type DialogueRunner, type DialogueRunnerOptions, type DialogueRunnerState, type EndNode, type LineNode, type TextRevealOptions, type TextRevealState, type VariableBag, completeTextReveal, createDialogueGraph, createDialogueRunner, createTextReveal, getNode, interpolate, resetTextReveal, updateTextReveal };
|
|
173
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/graph.ts","../src/runner.ts","../src/text-reveal.ts"],"mappings":";;;;;;;;;;;;;;UAeiB;WACN;;WAEA;;;;;;WAMA;;WAEA;;WAEA;;UAGM;;WAEN;;WAEA;;WAEA;;UAGM;WACN;;WAEA;;WAEA;WACA,kBAAkB;;UAGZ;;WAEN;;WAEA;;UAGM;WACN;WACA,eAAe;;WAEf;;UAGM;WACN;;WAEA;;WAEA;;UAGM;WACN;;KAGC,eAAe,WAAW,aAAa,aAAa,aAAa;UAI5D;;WAEN;;WAEA;;WAEA,OAAO,eAAe;;iBAGjB,oBACd,YACA,eACA,OAAO,eAAe,gBACrB;iBAIa,QAAQ,OAAO,eAAe,iBAAiB;;;KCrFnD;cAEC,sBAAsB;WACxB,MAAM;;WAEN;;WAEA;;WAEA;cAGP,MAAM,mBACN,iBACA;IAAU;IAAgB;IAAoB;;;KAatC,qBAAqB;KACrB,iBAAiB,uBAAuB;KACxC,cAAc;UAET;WACN;;WAEA;WACA;WACA;;UAGM;WACN;WACA;WACA,kBAAkB;WAClB;;UAGM;WACN;WACA;WACA;;KAGC;iBAII,YAAY,kBAAkB,MAAM;UASnC;WACN,QAAQ,OAAO;WACf,UAAU,OAAO;WACjB,UAAU;WACV,OAAO;WAEP,OAAO;WACP;WACA;EAET,MAAM,OAAO,eAAe,YAAY;EACxC;EACA,aAAa;EACb;;UAGe;EACf,aAAa;EACb,UAAU;;;;;EAKV,WAAW,KAAK;;iBAKF,qBAAqB,UAAU,wBAAwB;;;;;;;;;;UC9FtD;;WAEN;;EAET;;EAEA;;EAEA;;UAGe;;EAEf;;EAEA;;iBAUc,iBAAiB,eAAe;iBAOhC,iBACd,OAAO,iBACP,YACA,UAAU;iBA8BI,mBAAmB,OAAO;iBAM1B,gBAAgB,OAAO,iBAAiB"}
|