@novely/core 0.24.0 → 0.26.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/dist/index.d.ts +201 -107
- package/dist/index.global.js +265 -139
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +265 -139
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare const localStorageStorage: (options: LocalStorageStorageSettings) => Sto
|
|
|
17
17
|
|
|
18
18
|
type PluralType = Intl.LDMLPluralRule;
|
|
19
19
|
type Pluralization = Partial<Record<PluralType, string>>;
|
|
20
|
-
type AllowedContent = string | (() => string | string[]) | string[] | (string | (() => string | string[]))[];
|
|
20
|
+
type AllowedContent = string | ((state: State) => string | string[]) | string[] | (string | ((state: State) => string | string[]))[];
|
|
21
21
|
type TranslationActions = Partial<Record<string, (str: string) => string>>;
|
|
22
22
|
|
|
23
23
|
declare const RU: {
|
|
@@ -88,6 +88,49 @@ type AudioHandle = {
|
|
|
88
88
|
pause: () => void;
|
|
89
89
|
play: () => void;
|
|
90
90
|
};
|
|
91
|
+
type Context = {
|
|
92
|
+
id: string;
|
|
93
|
+
get root(): HTMLElement;
|
|
94
|
+
set root(value: HTMLElement);
|
|
95
|
+
character: (character: string) => CharacterHandle;
|
|
96
|
+
background: (background: string | BackgroundImage) => void;
|
|
97
|
+
dialog: (content: string, name: string, character: string | undefined, emotion: string | undefined, resolve: () => void) => void;
|
|
98
|
+
choices: (question: string, choices: [name: string, active: boolean][], resolve: (selected: number) => void) => void;
|
|
99
|
+
input: (question: string, onInput: (meta: ActionInputOnInputMeta<Lang, State>) => void, setup: ActionInputSetup, resolve: () => void) => void;
|
|
100
|
+
clear: (keep: Set<keyof DefaultActionProxy>, keepCharacters: Set<string>, keepAudio: {
|
|
101
|
+
music: Set<string>;
|
|
102
|
+
sounds: Set<string>;
|
|
103
|
+
}, resolve: () => void) => void;
|
|
104
|
+
custom: (fn: CustomHandler<Lang, State>, push: () => void) => Thenable<void>;
|
|
105
|
+
clearCustom: (fn: CustomHandler<Lang, State>) => void;
|
|
106
|
+
text: (str: string, resolve: () => void) => void;
|
|
107
|
+
vibrate: (pattern: VibratePattern) => void;
|
|
108
|
+
audio: {
|
|
109
|
+
voice: (source: string) => void;
|
|
110
|
+
voiceStop: () => void;
|
|
111
|
+
music: (source: string, method: 'music' | 'sound', loop?: boolean) => AudioHandle;
|
|
112
|
+
/**
|
|
113
|
+
* Stop all sounds
|
|
114
|
+
*/
|
|
115
|
+
clear: () => void;
|
|
116
|
+
/**
|
|
117
|
+
* Destroy
|
|
118
|
+
*/
|
|
119
|
+
destroy: () => void;
|
|
120
|
+
/**
|
|
121
|
+
* Initialize audio service, attach events, etc
|
|
122
|
+
*/
|
|
123
|
+
start: () => void;
|
|
124
|
+
};
|
|
125
|
+
meta: {
|
|
126
|
+
get restoring(): boolean;
|
|
127
|
+
set restoring(value: boolean);
|
|
128
|
+
get preview(): boolean;
|
|
129
|
+
set preview(value: boolean);
|
|
130
|
+
get goingBack(): boolean;
|
|
131
|
+
set goingBack(value: boolean);
|
|
132
|
+
};
|
|
133
|
+
};
|
|
91
134
|
type Renderer = {
|
|
92
135
|
misc: {
|
|
93
136
|
/**
|
|
@@ -112,11 +155,11 @@ type Renderer = {
|
|
|
112
155
|
/**
|
|
113
156
|
* Shows the screen
|
|
114
157
|
*/
|
|
115
|
-
showScreen(name: NovelyScreen
|
|
158
|
+
showScreen(name: NovelyScreen): void;
|
|
116
159
|
/**
|
|
117
160
|
* Returns current screen
|
|
118
161
|
*/
|
|
119
|
-
getScreen(): NovelyScreen |
|
|
162
|
+
getScreen(): NovelyScreen | (string & Record<never, never>);
|
|
120
163
|
/**
|
|
121
164
|
* Shows prompt to exit
|
|
122
165
|
*/
|
|
@@ -131,86 +174,43 @@ type Renderer = {
|
|
|
131
174
|
unmount(): void;
|
|
132
175
|
};
|
|
133
176
|
};
|
|
134
|
-
getContext: (context: string) =>
|
|
135
|
-
id: string;
|
|
136
|
-
get root(): HTMLElement;
|
|
137
|
-
set root(value: HTMLElement);
|
|
138
|
-
character: (character: string) => CharacterHandle;
|
|
139
|
-
background: (background: string | BackgroundImage) => void;
|
|
140
|
-
dialog: (content: string, name: string, character: string | undefined, emotion: string | undefined, resolve: () => void) => void;
|
|
141
|
-
choices: (question: string, choices: ([string, ValidAction[]] | [string, ValidAction[], () => boolean])[], resolve: (selected: number) => void) => void;
|
|
142
|
-
input: (question: string, onInput: (meta: ActionInputOnInputMeta<string>) => void, setup: ActionInputSetup, resolve: () => void) => void;
|
|
143
|
-
clear: (keep: Set<keyof DefaultActionProxyProvider>, keepCharacters: Set<string>, keepAudio: {
|
|
144
|
-
music: Set<string>;
|
|
145
|
-
sounds: Set<string>;
|
|
146
|
-
}, resolve: () => void) => void;
|
|
147
|
-
custom: (fn: Parameters<DefaultActionProxyProvider['custom']>[0], push: () => void) => Thenable<void>;
|
|
148
|
-
clearCustom: (fn: Parameters<DefaultActionProxyProvider['custom']>[0]) => void;
|
|
149
|
-
text: (str: string, resolve: () => void) => void;
|
|
150
|
-
vibrate: (pattern: VibratePattern) => void;
|
|
151
|
-
audio: {
|
|
152
|
-
voice: (source: string) => void;
|
|
153
|
-
voiceStop: () => void;
|
|
154
|
-
music: (source: string, method: 'music' | 'sound', loop?: boolean) => AudioHandle;
|
|
155
|
-
/**
|
|
156
|
-
* Stop all sounds
|
|
157
|
-
*/
|
|
158
|
-
clear: () => void;
|
|
159
|
-
/**
|
|
160
|
-
* Destroy
|
|
161
|
-
*/
|
|
162
|
-
destroy: () => void;
|
|
163
|
-
/**
|
|
164
|
-
* Initialize audio service, attach events, etc
|
|
165
|
-
*/
|
|
166
|
-
start: () => void;
|
|
167
|
-
};
|
|
168
|
-
meta: {
|
|
169
|
-
get restoring(): boolean;
|
|
170
|
-
set restoring(value: boolean);
|
|
171
|
-
get preview(): boolean;
|
|
172
|
-
set preview(value: boolean);
|
|
173
|
-
get goingBack(): boolean;
|
|
174
|
-
set goingBack(value: boolean);
|
|
175
|
-
};
|
|
176
|
-
store: unknown;
|
|
177
|
-
setStore: unknown;
|
|
178
|
-
};
|
|
177
|
+
getContext: (context: string) => Context;
|
|
179
178
|
removeContext: (context: string) => void;
|
|
180
179
|
};
|
|
181
|
-
type Context = ReturnType<Renderer['getContext']>;
|
|
182
180
|
type RendererInit = {
|
|
183
|
-
characters: Record<string, Character
|
|
184
|
-
set: (save: Save) => Promise<void>;
|
|
185
|
-
restore: (save?: Save) => Promise<void>;
|
|
186
|
-
save: (override?: boolean, type?: Save[2][1]) => void;
|
|
181
|
+
characters: Record<string, Character<Lang>>;
|
|
182
|
+
set: (save: Save<State>) => Promise<void>;
|
|
183
|
+
restore: (save?: Save<State>) => Promise<void>;
|
|
184
|
+
save: (override?: boolean, type?: Save<State>[2][1]) => void;
|
|
187
185
|
newGame: () => void;
|
|
188
186
|
exit: (force?: boolean) => void;
|
|
189
187
|
back: () => Promise<void>;
|
|
190
|
-
languages:
|
|
188
|
+
languages: Lang[];
|
|
191
189
|
/**
|
|
192
190
|
* Translation function
|
|
193
191
|
*/
|
|
194
|
-
t: (key: BaseTranslationStrings, lang:
|
|
192
|
+
t: (key: BaseTranslationStrings, lang: Lang) => string;
|
|
195
193
|
/**
|
|
196
194
|
* Store that tracks data updates
|
|
197
195
|
*/
|
|
198
|
-
|
|
196
|
+
storageData: Stored<StorageData<Lang, Data>>;
|
|
199
197
|
/**
|
|
200
198
|
* Store that used to communicate between renderer and core
|
|
201
199
|
*/
|
|
202
|
-
|
|
200
|
+
coreData: Stored<CoreData>;
|
|
203
201
|
/**
|
|
204
202
|
* There is different context, and the main one which is used for game
|
|
205
203
|
*/
|
|
206
204
|
mainContextKey: string;
|
|
207
|
-
preview: (save: Save
|
|
205
|
+
preview: (save: Save<State>, name: string) => Promise<void>;
|
|
208
206
|
removeContext: (name: string) => void;
|
|
207
|
+
getStateFunction: (context: string) => StateFunction<State>;
|
|
209
208
|
};
|
|
210
209
|
|
|
211
210
|
declare const getLanguage: (languages: string[]) => string;
|
|
212
211
|
|
|
213
212
|
type Thenable<T> = T | Promise<T>;
|
|
213
|
+
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
214
214
|
type PathItem = [null, number | string] | ['jump', string] | ['choice', number] | ['choice:exit'] | ['condition', string] | ['condition:exit'] | ['exit'] | ['block', string] | ['block:exit'];
|
|
215
215
|
type Path = PathItem[];
|
|
216
216
|
type State = Record<string, any>;
|
|
@@ -218,16 +218,26 @@ type Data = Record<string, any>;
|
|
|
218
218
|
type SaveDate = number;
|
|
219
219
|
type SaveType = 'manual' | 'auto';
|
|
220
220
|
type SaveMeta = [date: SaveDate, type: SaveType];
|
|
221
|
-
type Save
|
|
221
|
+
type Save<S extends State = State> = [
|
|
222
|
+
path: Path,
|
|
223
|
+
state: S,
|
|
224
|
+
meta: SaveMeta
|
|
225
|
+
];
|
|
222
226
|
type Lang = string;
|
|
223
|
-
type TypewriterSpeed = 'Slow' | 'Medium' | 'Fast' | 'Auto'
|
|
227
|
+
type TypewriterSpeed = 'Slow' | 'Medium' | 'Fast' | 'Auto';
|
|
224
228
|
type SoundVolume = number;
|
|
225
|
-
type StorageMeta
|
|
229
|
+
type StorageMeta<L extends string = string> = [
|
|
230
|
+
lang: L,
|
|
231
|
+
typewriter_speed: TypewriterSpeed,
|
|
232
|
+
music_volume: SoundVolume,
|
|
233
|
+
sound_volume: SoundVolume,
|
|
234
|
+
voice_volume: SoundVolume
|
|
235
|
+
];
|
|
226
236
|
type Migration = (save: unknown) => unknown;
|
|
227
|
-
type StorageData = {
|
|
237
|
+
type StorageData<L extends string = string, D extends Data = Data> = {
|
|
228
238
|
saves: Save[];
|
|
229
|
-
data:
|
|
230
|
-
meta: StorageMeta
|
|
239
|
+
data: D;
|
|
240
|
+
meta: StorageMeta<L>;
|
|
231
241
|
};
|
|
232
242
|
type Stack = {
|
|
233
243
|
value: Save;
|
|
@@ -235,7 +245,7 @@ type Stack = {
|
|
|
235
245
|
push(value: Save): void;
|
|
236
246
|
clear(): void;
|
|
237
247
|
};
|
|
238
|
-
type NovelyScreen = 'mainmenu' | 'game' | 'saves' | 'settings';
|
|
248
|
+
type NovelyScreen = 'mainmenu' | 'game' | 'saves' | 'settings' | 'loading';
|
|
239
249
|
/**
|
|
240
250
|
* @see https://pendletonjones.com/deep-partial
|
|
241
251
|
*/
|
|
@@ -258,7 +268,7 @@ type TranslationDescription = {
|
|
|
258
268
|
plural?: Record<string, Pluralization>;
|
|
259
269
|
actions?: TranslationActions;
|
|
260
270
|
};
|
|
261
|
-
interface NovelyInit
|
|
271
|
+
interface NovelyInit<$Language extends Lang, Characters extends Record<string, Character<NoInfer<$Language>>>, StateScheme extends State, DataScheme extends Data> {
|
|
262
272
|
/**
|
|
263
273
|
* An object containing the characters in the game.
|
|
264
274
|
* @example
|
|
@@ -290,7 +300,7 @@ interface NovelyInit<Languages extends string, Characters extends Record<string,
|
|
|
290
300
|
/**
|
|
291
301
|
* A function that returns a Renderer object used to display the game's content
|
|
292
302
|
*/
|
|
293
|
-
renderer: (
|
|
303
|
+
renderer: (initializationData: RendererInit) => Renderer;
|
|
294
304
|
/**
|
|
295
305
|
* An optional property that specifies the initial screen to display when the game starts
|
|
296
306
|
*/
|
|
@@ -317,7 +327,7 @@ interface NovelyInit<Languages extends string, Characters extends Record<string,
|
|
|
317
327
|
* })
|
|
318
328
|
* ```
|
|
319
329
|
*/
|
|
320
|
-
translation: Record
|
|
330
|
+
translation: Record<$Language, TranslationDescription>;
|
|
321
331
|
/**
|
|
322
332
|
* Initial state value
|
|
323
333
|
*
|
|
@@ -364,7 +374,7 @@ interface NovelyInit<Languages extends string, Characters extends Record<string,
|
|
|
364
374
|
* })
|
|
365
375
|
* ```
|
|
366
376
|
*/
|
|
367
|
-
getLanguage?: (languages:
|
|
377
|
+
getLanguage?: (languages: NoInfer<$Language>[], original: typeof getLanguage) => $Language | (string & Record<never, never>);
|
|
368
378
|
/**
|
|
369
379
|
* Ignores saved language, and uses `getLanguage` to get it on every engine start
|
|
370
380
|
* @default false
|
|
@@ -383,11 +393,24 @@ interface NovelyInit<Languages extends string, Characters extends Record<string,
|
|
|
383
393
|
* Fetching function
|
|
384
394
|
*/
|
|
385
395
|
fetch?: typeof fetch;
|
|
396
|
+
/**
|
|
397
|
+
* When page is going to be unloaded will call `storage.set` method
|
|
398
|
+
* If 'prod' is passed enable only in production env.
|
|
399
|
+
* @default true
|
|
400
|
+
*/
|
|
401
|
+
saveOnUnload?: boolean | 'prod';
|
|
386
402
|
}
|
|
403
|
+
type StateFunction<S extends State> = {
|
|
404
|
+
(value: DeepPartial<S> | ((prev: S) => S)): void;
|
|
405
|
+
(): S;
|
|
406
|
+
};
|
|
387
407
|
|
|
388
|
-
type ValidAction = ['choice',
|
|
408
|
+
type ValidAction = ['choice', number] | ['clear', Set<keyof DefaultActionProxy>?, Set<string>?, {
|
|
409
|
+
music: Set<string>;
|
|
410
|
+
sounds: Set<string>;
|
|
411
|
+
}?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['say', string, TextContent<string, State>] | ['end'] | ['showBackground', string | NonEmptyRecord<BackgroundImage>] | ['playMusic', string] | ['stopMusic', string] | ['playSound', audio: string, loop?: boolean] | ['voice', string] | ['stopVoice'] | ['jump', string] | ['showCharacter', string, keyof Character['emotions'], string?, string?] | ['hideCharacter', string, string?, string?, number?] | ['animateCharacter', string, number, ...string[]] | ['wait', (number | ((state: State) => number))] | ['function', FunctionAction<string, State>] | ['input', string, (meta: ActionInputOnInputMeta<string, State>) => void, ActionInputSetup?] | ['custom', CustomHandler<string, State>] | ['vibrate', ...number[]] | ['next'] | ['text', ...TextContent<string, State>[]] | ['exit'] | ['preload', string] | ['block', string] | ValidAction[];
|
|
389
412
|
type Story = Record<string, ValidAction[]>;
|
|
390
|
-
type
|
|
413
|
+
type TextContent<L extends string, S extends State> = string | ((state: S) => string) | Record<L, string | ((state: S) => string)>;
|
|
391
414
|
type FunctionableValue<T> = T | (() => T);
|
|
392
415
|
type CustomHandlerGetResultDataFunction = {
|
|
393
416
|
(data?: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -412,21 +435,22 @@ type CustomHandlerGetResult<I extends boolean> = {
|
|
|
412
435
|
clear: (fn: () => void) => void;
|
|
413
436
|
};
|
|
414
437
|
type CustomHandlerFunctionGetFn = <I extends boolean = true>(insert?: I) => CustomHandlerGetResult<I>;
|
|
415
|
-
type CustomHandlerFunctionParameters = {
|
|
438
|
+
type CustomHandlerFunctionParameters<L extends string, S extends State> = {
|
|
416
439
|
get: CustomHandlerFunctionGetFn;
|
|
440
|
+
state: StateFunction<S>;
|
|
417
441
|
goingBack: boolean;
|
|
418
442
|
preview: boolean;
|
|
419
|
-
lang:
|
|
443
|
+
lang: L;
|
|
420
444
|
};
|
|
421
|
-
type CustomHandlerFunction = (parameters: CustomHandlerFunctionParameters) => Thenable<void>;
|
|
422
|
-
type CustomHandler = CustomHandlerFunction & {
|
|
445
|
+
type CustomHandlerFunction<L extends string, S extends State> = (parameters: CustomHandlerFunctionParameters<L, S>) => Thenable<void>;
|
|
446
|
+
type CustomHandler<L extends string = string, S extends State = State> = CustomHandlerFunction<L, S> & {
|
|
423
447
|
callOnlyLatest?: boolean;
|
|
424
448
|
requireUserAction?: boolean;
|
|
425
449
|
skipClearOnGoingBack?: boolean;
|
|
426
450
|
id?: string | symbol;
|
|
427
451
|
key: string;
|
|
428
452
|
};
|
|
429
|
-
interface ActionInputOnInputMeta<L extends string> {
|
|
453
|
+
interface ActionInputOnInputMeta<L extends string, S extends State> {
|
|
430
454
|
/**
|
|
431
455
|
* Input Element itself
|
|
432
456
|
*/
|
|
@@ -450,25 +474,57 @@ interface ActionInputOnInputMeta<L extends string> {
|
|
|
450
474
|
* Language
|
|
451
475
|
*/
|
|
452
476
|
lang: L;
|
|
477
|
+
/**
|
|
478
|
+
* State function
|
|
479
|
+
*/
|
|
480
|
+
state: StateFunction<S>;
|
|
453
481
|
}
|
|
482
|
+
type FunctionActionProps<L extends string, S extends State> = {
|
|
483
|
+
restoring: boolean;
|
|
484
|
+
goingBack: boolean;
|
|
485
|
+
preview: boolean;
|
|
486
|
+
/**
|
|
487
|
+
* Language
|
|
488
|
+
*/
|
|
489
|
+
lang: L;
|
|
490
|
+
/**
|
|
491
|
+
* State function
|
|
492
|
+
*/
|
|
493
|
+
state: StateFunction<S>;
|
|
494
|
+
};
|
|
495
|
+
type ChoiceCheckFunctionProps<L extends string, S extends State> = {
|
|
496
|
+
/**
|
|
497
|
+
* Language
|
|
498
|
+
*/
|
|
499
|
+
lang: L;
|
|
500
|
+
/**
|
|
501
|
+
* State
|
|
502
|
+
*/
|
|
503
|
+
state: S;
|
|
504
|
+
};
|
|
505
|
+
type ChoiceCheckFunction<L extends string, S extends State> = {
|
|
506
|
+
(props: ChoiceCheckFunctionProps<L, S>): boolean;
|
|
507
|
+
};
|
|
508
|
+
type FunctionAction<L extends string, S extends State> = (props: FunctionActionProps<L, S>) => Thenable<void>;
|
|
454
509
|
type ActionInputSetup = (input: HTMLInputElement, cleanup: (cb: () => void) => void) => void;
|
|
455
510
|
type BackgroundImage = Partial<Record<'portrait' | 'landscape' | 'all', string>> & Record<string, string>;
|
|
456
|
-
type
|
|
511
|
+
type ActionProxy<Characters extends Record<string, Character>, Languages extends string, S extends State> = {
|
|
457
512
|
choice: {
|
|
458
|
-
(...choices:
|
|
459
|
-
(question:
|
|
513
|
+
(...choices: [name: TextContent<Languages, S>, actions: ValidAction[], active?: ChoiceCheckFunction<Languages, S>][]): ValidAction;
|
|
514
|
+
(question: TextContent<Languages, S>, ...choices: [name: TextContent<Languages, S>, actions: ValidAction[], active?: ChoiceCheckFunction<Languages, S>][]): ValidAction;
|
|
460
515
|
};
|
|
461
|
-
clear: (keep?: Set<keyof
|
|
516
|
+
clear: (keep?: Set<keyof DefaultActionProxy>, keepCharacters?: Set<string>, keepAudio?: {
|
|
462
517
|
music: Set<string>;
|
|
463
518
|
sounds: Set<string>;
|
|
464
519
|
}) => ValidAction;
|
|
465
|
-
condition: <T extends string | true | false>(condition: () => T, variants: Record<T extends true ? 'true' : T extends false ? 'false' : T, ValidAction[]>) => ValidAction;
|
|
520
|
+
condition: <T extends string | true | false>(condition: (state: S) => T, variants: Record<T extends true ? 'true' : T extends false ? 'false' : T, ValidAction[]>) => ValidAction;
|
|
466
521
|
exit: () => ValidAction;
|
|
467
522
|
dialog: {
|
|
468
|
-
<C extends keyof Characters>(
|
|
469
|
-
(
|
|
470
|
-
(
|
|
523
|
+
<C extends keyof Characters>(character: C, content: TextContent<Languages, S>, emotion?: keyof Characters[C]['emotions']): ValidAction;
|
|
524
|
+
(character: undefined, content: TextContent<Languages, S>, emotion?: undefined): ValidAction;
|
|
525
|
+
(character: string, content: TextContent<Languages, S>, emotion?: undefined): ValidAction;
|
|
471
526
|
};
|
|
527
|
+
say: (character: keyof Characters, content: TextContent<Languages, S>) => ValidAction;
|
|
472
528
|
end: () => ValidAction;
|
|
473
529
|
showBackground: <T extends string | BackgroundImage>(background: T extends string ? T : T extends Record<PropertyKey, unknown> ? NonEmptyRecord<T> : never) => ValidAction;
|
|
474
530
|
playMusic: (audio: string) => ValidAction;
|
|
@@ -489,46 +545,84 @@ type ActionProxyProvider<Characters extends Record<string, Character>, Languages
|
|
|
489
545
|
};
|
|
490
546
|
hideCharacter: (character: keyof Characters, className?: string, style?: string, duration?: number) => ValidAction;
|
|
491
547
|
animateCharacter: (character: keyof Characters, timeout: number, ...classes: string[]) => ValidAction;
|
|
492
|
-
wait: (time:
|
|
493
|
-
function: (fn:
|
|
494
|
-
input: (question:
|
|
495
|
-
custom: (handler: CustomHandler) => ValidAction;
|
|
548
|
+
wait: (time: number | ((state: State) => number)) => ValidAction;
|
|
549
|
+
function: (fn: FunctionAction<Languages, S>) => ValidAction;
|
|
550
|
+
input: (question: TextContent<Languages, S>, onInput: (meta: ActionInputOnInputMeta<Languages, S>) => void, setup?: ActionInputSetup) => ValidAction;
|
|
551
|
+
custom: (handler: CustomHandler<Languages, S> | CustomHandler) => ValidAction;
|
|
496
552
|
vibrate: (...pattern: number[]) => ValidAction;
|
|
497
553
|
next: () => ValidAction;
|
|
498
|
-
text: (...text:
|
|
554
|
+
text: (...text: TextContent<Languages, S>[]) => ValidAction;
|
|
499
555
|
preload: (source: string) => ValidAction;
|
|
500
556
|
block: (scene: string) => ValidAction;
|
|
501
557
|
};
|
|
502
|
-
type
|
|
503
|
-
type GetActionParameters<T extends Capitalize<keyof
|
|
558
|
+
type DefaultActionProxy = ActionProxy<Record<string, Character>, string, State>;
|
|
559
|
+
type GetActionParameters<T extends Capitalize<keyof DefaultActionProxy>> = Parameters<DefaultActionProxy[Uncapitalize<T>]>;
|
|
504
560
|
|
|
505
|
-
declare const novely: <Languages extends string, Characters extends Record<string, Character<Languages>>, StateScheme extends State, DataScheme extends Data>({ characters, storage, storageDelay, renderer: createRenderer, initialScreen, translation, state: defaultState, data: defaultData, autosaves, migrations, throttleTimeout, getLanguage, overrideLanguage, askBeforeExit, preloadAssets, parallelAssetsDownloadLimit, fetch: request }: NovelyInit<Languages, Characters, StateScheme, DataScheme>) => {
|
|
561
|
+
declare const novely: <Languages extends string, Characters extends Record<string, Character<Languages>>, StateScheme extends State, DataScheme extends Data>({ characters, storage, storageDelay, renderer: createRenderer, initialScreen, translation, state: defaultState, data: defaultData, autosaves, migrations, throttleTimeout, getLanguage, overrideLanguage, askBeforeExit, preloadAssets, parallelAssetsDownloadLimit, fetch: request, saveOnUnload }: NovelyInit<Languages, Characters, StateScheme, DataScheme>) => {
|
|
506
562
|
/**
|
|
507
563
|
* Function to set game script
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* ```ts
|
|
567
|
+
* engine.script({
|
|
568
|
+
* start: [
|
|
569
|
+
* action.function(() => {})
|
|
570
|
+
* ]
|
|
571
|
+
* })
|
|
572
|
+
* ```
|
|
508
573
|
*/
|
|
509
574
|
script: (part: Story) => Promise<void>;
|
|
510
575
|
/**
|
|
511
|
-
*
|
|
576
|
+
* Get actions
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
579
|
+
* ```ts
|
|
580
|
+
* engine.script({
|
|
581
|
+
* start: [
|
|
582
|
+
* action.function(() => {})
|
|
583
|
+
* ]
|
|
584
|
+
* })
|
|
585
|
+
* ```
|
|
586
|
+
*/
|
|
587
|
+
action: ActionProxy<Characters, Languages, StateScheme>;
|
|
588
|
+
/**
|
|
589
|
+
* @deprecated Will be removed BUT replaced with state passed into actions as a parameter
|
|
512
590
|
*/
|
|
513
|
-
|
|
591
|
+
state: StateFunction<State>;
|
|
514
592
|
/**
|
|
515
|
-
*
|
|
593
|
+
* Store data between games
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```ts
|
|
597
|
+
* engine.script({
|
|
598
|
+
* start: [
|
|
599
|
+
* action.function(() => {
|
|
600
|
+
* // Paid content should be purchased only once
|
|
601
|
+
* // So it will be available in any save
|
|
602
|
+
* data({ paid_content_purchased: true })
|
|
603
|
+
* })
|
|
604
|
+
* ]
|
|
605
|
+
* })
|
|
606
|
+
* ```
|
|
516
607
|
*/
|
|
517
|
-
|
|
518
|
-
(value: DeepPartial<StateScheme> | ((prev: StateScheme) => StateScheme)): void;
|
|
519
|
-
(): StateScheme;
|
|
520
|
-
};
|
|
608
|
+
data: StateFunction<DataScheme>;
|
|
521
609
|
/**
|
|
522
|
-
*
|
|
610
|
+
* @deprecated Renamed into `templateReplace`
|
|
523
611
|
*/
|
|
524
|
-
|
|
525
|
-
(value: DeepPartial<DataScheme> | ((prev: DataScheme) => DataScheme)): void;
|
|
526
|
-
(): DataScheme;
|
|
527
|
-
};
|
|
612
|
+
unwrap(content: TextContent<Languages, DataScheme>): string;
|
|
528
613
|
/**
|
|
529
|
-
*
|
|
614
|
+
* Replaces content inside {{braces}} with using global data
|
|
615
|
+
* @example
|
|
616
|
+
* ```ts
|
|
617
|
+
* data({ name: 'Alexei' })
|
|
618
|
+
*
|
|
619
|
+
* templateReplace('{{name}} is our hero')
|
|
620
|
+
* templateReplace({
|
|
621
|
+
* en: (data) => 'Hello, ' + data.name
|
|
622
|
+
* })
|
|
623
|
+
* ```
|
|
530
624
|
*/
|
|
531
|
-
|
|
625
|
+
templateReplace(content: TextContent<Languages, DataScheme>): string;
|
|
532
626
|
/**
|
|
533
627
|
* Cancel data loading, hide UI, ignore page change events
|
|
534
628
|
* Data updates still will work in case Novely already was loaded
|
|
@@ -536,4 +630,4 @@ declare const novely: <Languages extends string, Characters extends Record<strin
|
|
|
536
630
|
destroy(): void;
|
|
537
631
|
};
|
|
538
632
|
|
|
539
|
-
export { type
|
|
633
|
+
export { type ActionInputOnInputMeta, type ActionInputSetup, type ActionProxy, type AllowedContent, type AudioHandle, type BackgroundImage, type BaseTranslationStrings, type Character, type CharacterHandle, type Context, type CoreData, type CustomHandler, type CustomHandlerFunctionGetFn, type CustomHandlerFunctionParameters, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type Data, type DeepPartial, type DefaultActionProxy, EN, type Emotions, type FunctionableValue, type GetActionParameters, JP, KK, type Lang, type NovelyInit, type NovelyScreen, type Path, type PluralType, type Pluralization, RU, type Renderer, type RendererInit, type Save, type Stack, type StackHolder, type State, type StateFunction, type Storage, type StorageData, type StorageMeta, type Stored, type Story, type TextContent, type Thenable, type TranslationActions, type TypewriterSpeed, type ValidAction, localStorageStorage, novely };
|