@novely/core 0.19.4 → 0.20.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 +68 -47
- package/dist/index.global.js +439 -255
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +439 -255
- package/dist/index.js.map +1 -1
- package/package.json +62 -62
package/dist/index.d.ts
CHANGED
|
@@ -25,12 +25,6 @@ type StorageData = {
|
|
|
25
25
|
data: Data;
|
|
26
26
|
meta: StorageMeta;
|
|
27
27
|
};
|
|
28
|
-
type Stack = {
|
|
29
|
-
value: Save;
|
|
30
|
-
back(): void;
|
|
31
|
-
push(value: Save): void;
|
|
32
|
-
clear(): void;
|
|
33
|
-
};
|
|
34
28
|
type NovelyScreen = 'mainmenu' | 'game' | 'saves' | 'settings';
|
|
35
29
|
/**
|
|
36
30
|
* @see https://pendletonjones.com/deep-partial
|
|
@@ -43,14 +37,14 @@ type CoreData = {
|
|
|
43
37
|
dataLoaded: boolean;
|
|
44
38
|
};
|
|
45
39
|
|
|
46
|
-
type ValidAction = ['choice', [number]] | ['clear', [Set<keyof DefaultActionProxyProvider>?, Set<string>?]] | ['condition', [() => boolean, Record<string, ValidAction[]>]] | ['dialog', [string | undefined, Unwrappable<string>, string
|
|
40
|
+
type ValidAction = ['choice', [number]] | ['clear', [Set<keyof DefaultActionProxyProvider>?, Set<string>?]] | ['condition', [() => boolean, Record<string, ValidAction[]>]] | ['dialog', [string | undefined, Unwrappable<string>, string?]] | ['end', []] | ['showBackground', [string | NonEmptyRecord<BackgroundImage>]] | ['playMusic', [string]] | ['stopMusic', [string]] | ['voice', [string]] | ['stopVoice', []] | ['jump', [string]] | ['showCharacter', [string, keyof Character['emotions'], string?, string?]] | ['hideCharacter', [string, string?, string?, number?]] | ['animateCharacter', [string, number, ...string[]]] | ['wait', [FunctionableValue<number>]] | ['function', [() => Thenable<void>]] | ['input', [string, (meta: ActionInputOnInputMeta) => void, ActionInputSetup?]] | ['custom', [CustomHandler]] | ['vibrate', [...number[]]] | ['next', []] | ['text', [...string[]]] | ['exit', []] | ['preload', [string]] | ['block', [string]] | ValidAction[];
|
|
47
41
|
type Story = Record<string, ValidAction[]>;
|
|
48
42
|
type Unwrappable<L extends string> = string | (() => string) | Record<L, string | (() => string)>;
|
|
49
43
|
type FunctionableValue<T> = T | (() => T);
|
|
50
44
|
type CustomHandlerGetResultDataFunction = {
|
|
51
45
|
(data?: Record<string, unknown>): Record<string, unknown>;
|
|
52
46
|
};
|
|
53
|
-
type CustomHandlerGetResult = {
|
|
47
|
+
type CustomHandlerGetResult<I extends boolean> = {
|
|
54
48
|
delete: () => void;
|
|
55
49
|
/**
|
|
56
50
|
* Данные
|
|
@@ -59,7 +53,7 @@ type CustomHandlerGetResult = {
|
|
|
59
53
|
/**
|
|
60
54
|
* Элемент слоя
|
|
61
55
|
*/
|
|
62
|
-
element: HTMLDivElement
|
|
56
|
+
element: I extends true ? HTMLDivElement : null;
|
|
63
57
|
/**
|
|
64
58
|
* Корневой элемент Novely
|
|
65
59
|
*/
|
|
@@ -69,12 +63,13 @@ type CustomHandlerGetResult = {
|
|
|
69
63
|
*/
|
|
70
64
|
clear: (fn: () => void) => void;
|
|
71
65
|
};
|
|
72
|
-
type CustomHandlerFunction = (get:
|
|
66
|
+
type CustomHandlerFunction = (get: <I extends boolean>(insert?: I) => CustomHandlerGetResult<I>, goingBack: boolean, preview: boolean) => Thenable<void>;
|
|
73
67
|
type CustomHandler = CustomHandlerFunction & {
|
|
74
68
|
callOnlyLatest?: boolean;
|
|
75
69
|
requireUserAction?: boolean;
|
|
76
70
|
skipClearOnGoingBack?: boolean;
|
|
77
71
|
id?: string | symbol;
|
|
72
|
+
key: string;
|
|
78
73
|
};
|
|
79
74
|
interface ActionInputOnInputMeta {
|
|
80
75
|
/**
|
|
@@ -104,7 +99,10 @@ type ActionProxyProvider<Characters extends Record<string, Character>, Languages
|
|
|
104
99
|
(...choices: ([Unwrappable<Languages>, ValidAction[]] | [Unwrappable<Languages>, ValidAction[], () => boolean])[]): ValidAction;
|
|
105
100
|
(question: Unwrappable<Languages>, ...choices: ([Unwrappable<Languages>, ValidAction[]] | [Unwrappable<Languages>, ValidAction[], () => boolean])[]): ValidAction;
|
|
106
101
|
};
|
|
107
|
-
clear: (keep?: Set<keyof DefaultActionProxyProvider>, keepCharacters?: Set<string
|
|
102
|
+
clear: (keep?: Set<keyof DefaultActionProxyProvider>, keepCharacters?: Set<string>, keepAudio?: {
|
|
103
|
+
music: Set<string>;
|
|
104
|
+
sounds: Set<string>;
|
|
105
|
+
}) => ValidAction;
|
|
108
106
|
condition: <T extends string | true | false>(condition: () => T, variants: Record<T extends true ? 'true' : T extends false ? 'false' : T, ValidAction[]>) => ValidAction;
|
|
109
107
|
exit: () => ValidAction;
|
|
110
108
|
dialog: {
|
|
@@ -133,7 +131,7 @@ type ActionProxyProvider<Characters extends Record<string, Character>, Languages
|
|
|
133
131
|
hideCharacter: (character: keyof Characters, className?: string, style?: string, duration?: number) => ValidAction;
|
|
134
132
|
animateCharacter: (character: keyof Characters, timeout: number, ...classes: string[]) => ValidAction;
|
|
135
133
|
wait: (time: FunctionableValue<number>) => ValidAction;
|
|
136
|
-
function: (fn: (restoring: boolean, goingBack: boolean) => Thenable<void>) => ValidAction;
|
|
134
|
+
function: (fn: (restoring: boolean, goingBack: boolean, preview: boolean) => Thenable<void>) => ValidAction;
|
|
137
135
|
input: (question: Unwrappable<Languages>, onInput: (meta: ActionInputOnInputMeta) => void, setup?: ActionInputSetup) => ValidAction;
|
|
138
136
|
custom: (handler: CustomHandler) => ValidAction;
|
|
139
137
|
vibrate: (...pattern: number[]) => ValidAction;
|
|
@@ -195,15 +193,16 @@ declare const JP: Record<BaseTranslationStrings, string>;
|
|
|
195
193
|
type Stored<T> = {
|
|
196
194
|
subscribe: (cb: (value: T) => void) => () => void;
|
|
197
195
|
update: (fn: (prev: T) => T) => void;
|
|
196
|
+
set: (val: T) => void;
|
|
198
197
|
get: () => T;
|
|
199
198
|
};
|
|
200
199
|
|
|
201
200
|
interface CharacterHandle {
|
|
202
201
|
canvas: HTMLCanvasElement;
|
|
203
202
|
ctx: CanvasRenderingContext2D;
|
|
204
|
-
|
|
203
|
+
emotion: (emotion: string, render: boolean) => void;
|
|
205
204
|
append: (className?: string, style?: string, restoring?: boolean) => void;
|
|
206
|
-
remove: (className?: string, style?: string, duration?: number
|
|
205
|
+
remove: (className?: string, style?: string, duration?: number, restoring?: boolean) => Promise<void>;
|
|
207
206
|
emotions: Record<string, HTMLImageElement[]>;
|
|
208
207
|
}
|
|
209
208
|
type AudioHandle = {
|
|
@@ -211,37 +210,7 @@ type AudioHandle = {
|
|
|
211
210
|
pause: () => void;
|
|
212
211
|
play: () => void;
|
|
213
212
|
};
|
|
214
|
-
interface RendererStore {
|
|
215
|
-
characters: Record<string, CharacterHandle>;
|
|
216
|
-
}
|
|
217
213
|
type Renderer = {
|
|
218
|
-
character: (character: string) => CharacterHandle;
|
|
219
|
-
background: (background: string | BackgroundImage) => void;
|
|
220
|
-
dialog: (content: string, name: string, character?: string, emotion?: string) => (resolve: () => void, goingBack: boolean) => void;
|
|
221
|
-
choices: (question: string, choices: ([string, ValidAction[]] | [string, ValidAction[], () => boolean])[]) => (resolve: (selected: number) => void) => void;
|
|
222
|
-
input: (question: string, onInput: Parameters<DefaultActionProxyProvider['input']>[1], setup?: Parameters<DefaultActionProxyProvider['input']>[2]) => (resolve: () => void) => void;
|
|
223
|
-
audio: {
|
|
224
|
-
voice: (source: string) => void;
|
|
225
|
-
voiceStop: () => void;
|
|
226
|
-
music: (source: string, method: 'music' | 'sound', loop?: boolean) => AudioHandle;
|
|
227
|
-
/**
|
|
228
|
-
* Stop all sounds
|
|
229
|
-
*/
|
|
230
|
-
clear: () => void;
|
|
231
|
-
/**
|
|
232
|
-
* Destroy
|
|
233
|
-
*/
|
|
234
|
-
destroy: () => void;
|
|
235
|
-
/**
|
|
236
|
-
* Start
|
|
237
|
-
* @todo: more descriptive
|
|
238
|
-
*/
|
|
239
|
-
start: () => void;
|
|
240
|
-
};
|
|
241
|
-
clear: (goingBack: boolean, keep: Set<keyof DefaultActionProxyProvider>, keepCharacters: Set<string>) => (resolve: () => void) => void;
|
|
242
|
-
custom: (fn: Parameters<DefaultActionProxyProvider['custom']>[0], goingBack: boolean, push: () => void) => Thenable<void>;
|
|
243
|
-
text: (str: string, resolve: () => void, goingBack: boolean) => void;
|
|
244
|
-
vibrate: (pattern: VibratePattern) => void;
|
|
245
214
|
misc: {
|
|
246
215
|
/**
|
|
247
216
|
* Function to preload images async and await for all images to load or fail
|
|
@@ -261,7 +230,6 @@ type Renderer = {
|
|
|
261
230
|
*/
|
|
262
231
|
preloadAudioBlocking: (type: 'music', source: string) => Promise<void>;
|
|
263
232
|
};
|
|
264
|
-
store: RendererStore;
|
|
265
233
|
ui: {
|
|
266
234
|
/**
|
|
267
235
|
* Shows the screen
|
|
@@ -285,7 +253,55 @@ type Renderer = {
|
|
|
285
253
|
unmount(): void;
|
|
286
254
|
};
|
|
287
255
|
};
|
|
256
|
+
getContext: (context: string) => {
|
|
257
|
+
id: string;
|
|
258
|
+
get root(): HTMLElement;
|
|
259
|
+
set root(value: HTMLElement);
|
|
260
|
+
character: (character: string) => CharacterHandle;
|
|
261
|
+
background: (background: string | BackgroundImage) => void;
|
|
262
|
+
dialog: (content: string, name: string, character?: string, emotion?: string) => (resolve: () => void) => void;
|
|
263
|
+
choices: (question: string, choices: ([string, ValidAction[]] | [string, ValidAction[], () => boolean])[]) => (resolve: (selected: number) => void) => void;
|
|
264
|
+
input: (question: string, onInput: Parameters<DefaultActionProxyProvider['input']>[1], setup?: Parameters<DefaultActionProxyProvider['input']>[2]) => (resolve: () => void) => void;
|
|
265
|
+
clear: (keep: Set<keyof DefaultActionProxyProvider>, keepCharacters: Set<string>, keepAudio: {
|
|
266
|
+
music: Set<string>;
|
|
267
|
+
sounds: Set<string>;
|
|
268
|
+
}) => (resolve: () => void) => void;
|
|
269
|
+
custom: (fn: Parameters<DefaultActionProxyProvider['custom']>[0], push: () => void) => Thenable<void>;
|
|
270
|
+
clearCustom: (fn: Parameters<DefaultActionProxyProvider['custom']>[0]) => void;
|
|
271
|
+
text: (str: string, resolve: () => void) => void;
|
|
272
|
+
vibrate: (pattern: VibratePattern) => void;
|
|
273
|
+
audio: {
|
|
274
|
+
voice: (source: string) => void;
|
|
275
|
+
voiceStop: () => void;
|
|
276
|
+
music: (source: string, method: 'music' | 'sound', loop?: boolean) => AudioHandle;
|
|
277
|
+
/**
|
|
278
|
+
* Stop all sounds
|
|
279
|
+
*/
|
|
280
|
+
clear: () => void;
|
|
281
|
+
/**
|
|
282
|
+
* Destroy
|
|
283
|
+
*/
|
|
284
|
+
destroy: () => void;
|
|
285
|
+
/**
|
|
286
|
+
* Initialize audio service, attach events, etc
|
|
287
|
+
*/
|
|
288
|
+
start: () => void;
|
|
289
|
+
};
|
|
290
|
+
meta: {
|
|
291
|
+
get restoring(): boolean;
|
|
292
|
+
set restoring(value: boolean);
|
|
293
|
+
get preview(): boolean;
|
|
294
|
+
set preview(value: boolean);
|
|
295
|
+
get goingBack(): boolean;
|
|
296
|
+
set goingBack(value: boolean);
|
|
297
|
+
};
|
|
298
|
+
store: unknown;
|
|
299
|
+
setStore: unknown;
|
|
300
|
+
getCharacter: (character: string) => CharacterHandle | undefined;
|
|
301
|
+
};
|
|
302
|
+
removeContext: (context: string) => void;
|
|
288
303
|
};
|
|
304
|
+
type Context = ReturnType<Renderer['getContext']>;
|
|
289
305
|
type RendererInit = {
|
|
290
306
|
characters: Record<string, Character>;
|
|
291
307
|
set: (save: Save) => Promise<void>;
|
|
@@ -294,7 +310,6 @@ type RendererInit = {
|
|
|
294
310
|
newGame: () => void;
|
|
295
311
|
exit: (force?: boolean) => void;
|
|
296
312
|
back: () => Promise<void>;
|
|
297
|
-
stack: Stack;
|
|
298
313
|
languages: string[];
|
|
299
314
|
/**
|
|
300
315
|
* Translation function
|
|
@@ -308,6 +323,12 @@ type RendererInit = {
|
|
|
308
323
|
* Store that used to communicate between renderer and core
|
|
309
324
|
*/
|
|
310
325
|
$$: Stored<CoreData>;
|
|
326
|
+
/**
|
|
327
|
+
* There is different context, and the main one which is used for game
|
|
328
|
+
*/
|
|
329
|
+
mainContextKey: string;
|
|
330
|
+
preview: (save: Save, name: string) => Promise<void>;
|
|
331
|
+
removeContext: (name: string) => void;
|
|
311
332
|
};
|
|
312
333
|
|
|
313
334
|
interface LocalStorageStorageSettings {
|
|
@@ -443,4 +464,4 @@ declare const novely: <Languages extends string, Characters extends Record<strin
|
|
|
443
464
|
unwrap(content: string | (() => string) | Record<Languages, string> | Exclude<Record<Languages, string | (() => string)>, Record<string, string>>): string;
|
|
444
465
|
};
|
|
445
466
|
|
|
446
|
-
export { type ActionProxyProvider, type AllowedContent, type AudioHandle, type BaseTranslationStrings, type Character, type CharacterHandle, type CoreData, type CustomHandler, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type DefaultActionProxyProvider, EN, type Emotions, type FunctionableValue, type GetActionParameters, JP, KK, type Lang, type NovelyScreen, type Path, type PluralType, type Pluralization, RU, type Renderer, type RendererInit, type
|
|
467
|
+
export { type ActionProxyProvider, type AllowedContent, type AudioHandle, type BaseTranslationStrings, type Character, type CharacterHandle, type Context, type CoreData, type CustomHandler, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type DefaultActionProxyProvider, EN, type Emotions, type FunctionableValue, type GetActionParameters, JP, KK, type Lang, type NovelyScreen, type Path, type PluralType, type Pluralization, RU, type Renderer, type RendererInit, type Save, type Storage, type StorageData, type StorageMeta, type Stored, type Story, type Thenable, type TranslationActions, type TypewriterSpeed, type Unwrappable, type ValidAction, localStorageStorage, novely };
|