@bgforge/mls-server 3.14.0 → 3.15.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.
@@ -28,6 +28,22 @@ interface Action {
28
28
 
29
29
  // --- IElib sync surface end ---
30
30
 
31
+ /**
32
+ * A dialogue state: a nullary function whose `say`/`reply`/`goTo` calls describe one state.
33
+ *
34
+ * Deliberately a call signature and not a brand, unlike `StrRef` and `Action` above. Those name values
35
+ * the runtime itself produces, so a brand costs their callers nothing; a state is written by the author
36
+ * with the `function` keyword (`function greeting() { ... }; begin("DLG", [greeting])`), and a branded
37
+ * type would reject every one of them.
38
+ *
39
+ * What this buys over `Function`, exactly: a function REQUIRING arguments is now rejected at the call
40
+ * site (`begin("DLG", [f])` where `f(a: string)` - "Target signature provides too few arguments").
41
+ * It is not airtight - anything callable with zero arguments still passes, `Math.max` included, since a
42
+ * rest parameter satisfies a nullary signature and every return type is assignable to `void`. Tightening
43
+ * further would need a brand, which the paragraph above rules out.
44
+ */
45
+ type StateFn = () => void;
46
+
31
47
  // ---------------------------------------------------------------------------
32
48
  // State-level functions (called inside state functions)
33
49
  // ---------------------------------------------------------------------------
@@ -69,7 +85,7 @@ interface TransitionBuilder<Self> {
69
85
  /** Set transition feature flags directly using the binary DLG format. */
70
86
  flags(n: number): Self;
71
87
  /** Continue dialogue at the given state label in the same DLG file. */
72
- goTo(target: string | number | Function): void;
88
+ goTo(target: string | number | StateFn): void;
73
89
  /** End the conversation. */
74
90
  exit(): void;
75
91
  /** Continue dialogue at the given state in another DLG file. */
@@ -100,7 +116,7 @@ declare function reply(text: StrRef): AfterReply;
100
116
  declare function action(...actions: Action[]): AfterAction;
101
117
 
102
118
  /** Continue dialogue at the given state label in the same DLG file. Synonym for GOTO. */
103
- declare function goTo(target: string | number | Function): void;
119
+ declare function goTo(target: string | number | StateFn): void;
104
120
 
105
121
  /** End the conversation. */
106
122
  declare function exit(): void;
@@ -139,26 +155,26 @@ declare function unsolvedJournal(text: StrRef): void;
139
155
  * Use inside begin(), append(), appendEarly() argument lists.
140
156
  * @example begin("DLG", [state("greeting", () => { say(tra(1)); exit(); })]);
141
157
  */
142
- declare function state(label: string, body: () => void): Function;
158
+ declare function state(label: string, body: StateFn): StateFn;
143
159
 
144
160
  /**
145
161
  * Create a new DLG file from scratch. Any existing DLG file with the same name
146
162
  * will be overwritten. The new DLG file contains exactly the states in the list.
147
163
  */
148
- declare function begin(dialog: string, states: (Function | string)[]): void;
149
- declare function begin(dialog: string, ...states: Function[]): void;
164
+ declare function begin(dialog: string, states: (StateFn | string)[]): void;
165
+ declare function begin(dialog: string, ...states: StateFn[]): void;
150
166
 
151
167
  /**
152
168
  * Add states to the end of an already-existing dialogue file.
153
169
  */
154
- declare function append(dialog: string, states: Function[]): void;
155
- declare function append(dialog: string, ...states: Function[]): void;
170
+ declare function append(dialog: string, states: StateFn[]): void;
171
+ declare function append(dialog: string, ...states: StateFn[]): void;
156
172
 
157
173
  /**
158
174
  * Like `append`, but the states are added early in the compilation timeline
159
175
  * (just after BEGIN is processed). They can be targets for INTERJECT_COPY_TRANS.
160
176
  */
161
- declare function appendEarly(dialog: string, ...states: Function[]): void;
177
+ declare function appendEarly(dialog: string, ...states: StateFn[]): void;
162
178
 
163
179
  /**
164
180
  * Load the given dialog and replace the state at the given numeric index
@@ -169,15 +185,15 @@ declare function replaceState(dialog: string, state: number, body: () => void):
169
185
  /**
170
186
  * Add transitions to the top of the transition list for the specified state.
171
187
  */
172
- declare function extendTop(dialog: string, state: string | number | Function, callback: () => void): void;
188
+ declare function extendTop(dialog: string, state: string | number | StateFn, callback: () => void): void;
173
189
 
174
190
  /**
175
191
  * Add transitions to the bottom of the transition list for the specified state.
176
192
  */
177
- declare function extendBottom(dialog: string, state: string | number | Function, callback: () => void): void;
193
+ declare function extendBottom(dialog: string, state: string | number | StateFn, callback: () => void): void;
178
194
  declare function extendBottom(
179
195
  dialog: string,
180
- state: string | number | Function,
196
+ state: string | number | StateFn,
181
197
  options: { position?: number },
182
198
  callback: () => void,
183
199
  ): void;
@@ -191,8 +207,8 @@ declare function extendBottom(
191
207
  * Useful when NPCs talk among themselves. CHAIN only appends to existing
192
208
  * dialogues; it cannot create a new DLG.
193
209
  */
194
- declare function chain(callback: Function): void;
195
- declare function chain(entryTrigger: boolean, callback: Function): void;
210
+ declare function chain(callback: () => void): void;
211
+ declare function chain(entryTrigger: boolean, callback: () => void): void;
196
212
  declare function chain(dialog: string, label: string, body: () => void): void;
197
213
  declare function chain(entryTrigger: boolean, dialog: string, label: string, body: () => void): void;
198
214
 
@@ -215,7 +231,7 @@ declare function interject(
215
231
  entryDialog: string,
216
232
  entryState: string,
217
233
  globalVar: string,
218
- callback: Function,
234
+ callback: () => void,
219
235
  exitDialog?: string,
220
236
  exitState?: string,
221
237
  ): void;
@@ -229,7 +245,7 @@ declare function interjectCopyTrans(
229
245
  entryDialog: string,
230
246
  entryState: string,
231
247
  globalVar: string,
232
- callback: Function,
248
+ callback: () => void,
233
249
  exitDialog?: string,
234
250
  exitState?: string,
235
251
  ): void;
@@ -242,7 +258,7 @@ declare function interjectCopyTrans2(
242
258
  entryDialog: string,
243
259
  entryState: string,
244
260
  globalVar: string,
245
- callback: Function,
261
+ callback: () => void,
246
262
  ): void;
247
263
 
248
264
  /**
@@ -253,7 +269,7 @@ declare function interjectCopyTrans3(
253
269
  entryDialog: string,
254
270
  entryState: string,
255
271
  globalVar: string,
256
- callback: Function,
272
+ callback: () => void,
257
273
  ): void;
258
274
 
259
275
  /**
@@ -264,7 +280,7 @@ declare function interjectCopyTrans4(
264
280
  entryDialog: string,
265
281
  entryState: string,
266
282
  globalVar: string,
267
- callback: Function,
283
+ callback: () => void,
268
284
  ): void;
269
285
 
270
286
  // ---------------------------------------------------------------------------
@@ -311,7 +327,7 @@ declare function addTransAction(dialog: string, states: (string | number)[], tra
311
327
  */
312
328
  declare function replaceTransTrigger(
313
329
  dialog: string,
314
- states: (string | number | Function)[],
330
+ states: (string | number | StateFn)[],
315
331
  trans: number[],
316
332
  from: string,
317
333
  to: string,
@@ -323,7 +339,7 @@ declare function replaceTransTrigger(
323
339
  */
324
340
  declare function replaceTransAction(
325
341
  dialog: string,
326
- states: (string | number | Function)[],
342
+ states: (string | number | StateFn)[],
327
343
  trans: number[],
328
344
  from: string,
329
345
  to: string,
Binary file
Binary file