@novely/core 0.12.5 → 0.14.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/README.md +3 -1
- package/dist/index.d.ts +83 -29
- package/dist/index.global.js +269 -82
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +268 -56
- package/dist/index.js.map +1 -1
- package/package.json +60 -61
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import * as _novely_t9n from '@novely/t9n';
|
|
2
|
-
import { BaseTranslationStrings, SetupT9N } from '@novely/t9n';
|
|
3
|
-
export { BaseTranslationStrings } from '@novely/t9n';
|
|
4
|
-
|
|
5
1
|
type Name<Keys extends string = string> = string | Record<Keys, string>;
|
|
6
2
|
type Emotions<Keys extends string = string> = Record<Keys, string | {
|
|
7
3
|
body: Record<'left' | 'right', string>;
|
|
@@ -14,7 +10,7 @@ type Character<LanguageKeys extends string = string> = {
|
|
|
14
10
|
};
|
|
15
11
|
|
|
16
12
|
type Thenable<T> = T | Promise<T>;
|
|
17
|
-
type PathItem = [null, number | string] | ['choice', number] | ['choice:exit'] | ['condition', string] | ['condition:exit'] | ['exit'] | ['block', string] | ['block:exit'];
|
|
13
|
+
type PathItem = [null, number | string] | ['jump', string] | ['choice', number] | ['choice:exit'] | ['condition', string] | ['condition:exit'] | ['exit'] | ['block', string] | ['block:exit'];
|
|
18
14
|
type Path = PathItem[];
|
|
19
15
|
type State = Record<string, any>;
|
|
20
16
|
type Data = Record<string, any>;
|
|
@@ -49,9 +45,9 @@ type CoreData = {
|
|
|
49
45
|
dataLoaded: boolean;
|
|
50
46
|
};
|
|
51
47
|
|
|
52
|
-
type ValidAction = ['choice', [number]] | ['clear', [Set<keyof DefaultActionProxyProvider>?, Set<string>?]] | ['condition', [() => boolean, Record<string, ValidAction[]>]] | ['dialog', [string | undefined, Unwrappable
|
|
48
|
+
type ValidAction = ['choice', [number]] | ['clear', [Set<keyof DefaultActionProxyProvider>?, Set<string>?]] | ['condition', [() => boolean, Record<string, ValidAction[]>]] | ['dialog', [string | undefined, Unwrappable<string>, string | undefined]] | ['end', []] | ['showBackground', [string | NonEmptyRecord<BackgroundImage>]] | ['playMusic', [string]] | ['stopMusic', [string]] | ['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[];
|
|
53
49
|
type Story = Record<string, ValidAction[]>;
|
|
54
|
-
type Unwrappable = string | ((
|
|
50
|
+
type Unwrappable<L extends string> = string | (() => string) | Record<L, string | (() => string)>;
|
|
55
51
|
type FunctionableValue<T> = T | (() => T);
|
|
56
52
|
type CustomHandlerGetResultDataFunction = {
|
|
57
53
|
(data?: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -105,18 +101,18 @@ interface ActionInputOnInputMeta {
|
|
|
105
101
|
}
|
|
106
102
|
type ActionInputSetup = (input: HTMLInputElement, cleanup: (cb: () => void) => void) => void;
|
|
107
103
|
type BackgroundImage = Partial<Record<"portrait" | "landscape" | "all", string>> & Record<(string), string>;
|
|
108
|
-
type ActionProxyProvider<Characters extends Record<string, Character
|
|
104
|
+
type ActionProxyProvider<Characters extends Record<string, Character>, Languages extends string> = {
|
|
109
105
|
choice: {
|
|
110
|
-
(...choices: ([Unwrappable
|
|
111
|
-
(question: Unwrappable
|
|
106
|
+
(...choices: ([Unwrappable<Languages>, ValidAction[]] | [Unwrappable<Languages>, ValidAction[], () => boolean])[]): ValidAction;
|
|
107
|
+
(question: Unwrappable<Languages>, ...choices: ([Unwrappable<Languages>, ValidAction[]] | [Unwrappable<Languages>, ValidAction[], () => boolean])[]): ValidAction;
|
|
112
108
|
};
|
|
113
109
|
clear: (keep?: Set<keyof DefaultActionProxyProvider>, keepCharacters?: Set<string>) => ValidAction;
|
|
114
110
|
condition: <T extends string | true | false>(condition: () => T, variants: Record<T extends true ? 'true' : T extends false ? 'false' : T, ValidAction[]>) => ValidAction;
|
|
115
111
|
exit: () => ValidAction;
|
|
116
112
|
dialog: {
|
|
117
|
-
<C extends keyof Characters>(person: C, content: Unwrappable
|
|
118
|
-
(person: undefined, content: Unwrappable
|
|
119
|
-
(person: string, content: Unwrappable
|
|
113
|
+
<C extends keyof Characters>(person: C, content: Unwrappable<Languages>, emotion?: keyof Characters[C]['emotions']): ValidAction;
|
|
114
|
+
(person: undefined, content: Unwrappable<Languages>, emotion?: undefined): ValidAction;
|
|
115
|
+
(person: string, content: Unwrappable<Languages>, emotion?: undefined): ValidAction;
|
|
120
116
|
};
|
|
121
117
|
end: () => ValidAction;
|
|
122
118
|
showBackground: <T extends string | BackgroundImage>(background: T extends string ? T : T extends Record<PropertyKey, unknown> ? NonEmptyRecord<T> : never) => ValidAction;
|
|
@@ -130,17 +126,61 @@ type ActionProxyProvider<Characters extends Record<string, Character>> = {
|
|
|
130
126
|
animateCharacter: (character: keyof Characters, timeout: number, ...classes: string[]) => ValidAction;
|
|
131
127
|
wait: (time: FunctionableValue<number>) => ValidAction;
|
|
132
128
|
function: (fn: (restoring: boolean, goingBack: boolean) => Thenable<void>) => ValidAction;
|
|
133
|
-
input: (question: Unwrappable
|
|
129
|
+
input: (question: Unwrappable<Languages>, onInput: (meta: ActionInputOnInputMeta) => void, setup?: ActionInputSetup) => ValidAction;
|
|
134
130
|
custom: (handler: CustomHandler) => ValidAction;
|
|
135
131
|
vibrate: (...pattern: number[]) => ValidAction;
|
|
136
132
|
next: () => ValidAction;
|
|
137
|
-
text: (...text: Unwrappable[]) => ValidAction;
|
|
133
|
+
text: (...text: Unwrappable<Languages>[]) => ValidAction;
|
|
138
134
|
preload: (source: string) => ValidAction;
|
|
139
135
|
block: (scene: string) => ValidAction;
|
|
140
136
|
};
|
|
141
|
-
type DefaultActionProxyProvider = ActionProxyProvider<Record<string, Character
|
|
137
|
+
type DefaultActionProxyProvider = ActionProxyProvider<Record<string, Character>, string>;
|
|
142
138
|
type GetActionParameters<T extends Capitalize<keyof DefaultActionProxyProvider>> = Parameters<DefaultActionProxyProvider[Uncapitalize<T>]>;
|
|
143
139
|
|
|
140
|
+
declare const RU: {
|
|
141
|
+
NewGame: string;
|
|
142
|
+
HomeScreen: string;
|
|
143
|
+
ToTheGame: string;
|
|
144
|
+
Language: string;
|
|
145
|
+
NoSaves: string;
|
|
146
|
+
LoadSave: string;
|
|
147
|
+
Saves: string;
|
|
148
|
+
Settings: string;
|
|
149
|
+
Sumbit: string;
|
|
150
|
+
GoBack: string;
|
|
151
|
+
DoSave: string;
|
|
152
|
+
Auto: string;
|
|
153
|
+
Stop: string;
|
|
154
|
+
Exit: string;
|
|
155
|
+
Automatic: string;
|
|
156
|
+
Manual: string;
|
|
157
|
+
Remove: string;
|
|
158
|
+
LoadASaveFrom: string;
|
|
159
|
+
DeleteASaveFrom: string;
|
|
160
|
+
TextSpeed: string;
|
|
161
|
+
TextSpeedSlow: string;
|
|
162
|
+
TextSpeedMedium: string;
|
|
163
|
+
TextSpeedFast: string;
|
|
164
|
+
TextSpeedAuto: string;
|
|
165
|
+
CompleteText: string;
|
|
166
|
+
GoForward: string;
|
|
167
|
+
ExitDialogWarning: string;
|
|
168
|
+
ExitDialogExit: string;
|
|
169
|
+
ExitDialogBack: string;
|
|
170
|
+
OpenMenu: string;
|
|
171
|
+
CloseMenu: string;
|
|
172
|
+
};
|
|
173
|
+
type BaseTranslationStrings = keyof typeof RU;
|
|
174
|
+
declare const EN: Record<BaseTranslationStrings, string>;
|
|
175
|
+
/**
|
|
176
|
+
* Translated automatically
|
|
177
|
+
*/
|
|
178
|
+
declare const KK: Record<BaseTranslationStrings, string>;
|
|
179
|
+
/**
|
|
180
|
+
* Translated automatically
|
|
181
|
+
*/
|
|
182
|
+
declare const JP: Record<BaseTranslationStrings, string>;
|
|
183
|
+
|
|
144
184
|
type Stored<T> = {
|
|
145
185
|
subscribe: (cb: (value: T) => void) => () => void;
|
|
146
186
|
update: (fn: (prev: T) => T) => void;
|
|
@@ -194,7 +234,11 @@ type Renderer = {
|
|
|
194
234
|
/**
|
|
195
235
|
* Shows the screen
|
|
196
236
|
*/
|
|
197
|
-
showScreen(name:
|
|
237
|
+
showScreen(name: NovelyScreen | 'loading'): void;
|
|
238
|
+
/**
|
|
239
|
+
* Returns current screen
|
|
240
|
+
*/
|
|
241
|
+
getScreen(): NovelyScreen | 'loading' | (string & Record<never, never>);
|
|
198
242
|
/**
|
|
199
243
|
* Shows prompt to exit
|
|
200
244
|
*/
|
|
@@ -243,9 +287,14 @@ interface Storage {
|
|
|
243
287
|
}
|
|
244
288
|
declare const localStorageStorage: (options: LocalStorageStorageSettings) => Storage;
|
|
245
289
|
|
|
290
|
+
type PluralType = Intl.LDMLPluralRule;
|
|
291
|
+
type Pluralization = Partial<Record<PluralType, string>>;
|
|
292
|
+
type AllowedContent = string | (() => string | string[]) | string[] | (string | (() => string | string[]))[];
|
|
293
|
+
type TranslationActions = Partial<Record<string, (str: string) => string>>;
|
|
294
|
+
|
|
246
295
|
declare const getLanguage: (languages: string[]) => string;
|
|
247
296
|
|
|
248
|
-
interface NovelyInit<Languages extends string, Characters extends Record<string, Character<Languages>>,
|
|
297
|
+
interface NovelyInit<Languages extends string, Characters extends Record<string, Character<Languages>>, StateScheme extends State, DataScheme extends Data> {
|
|
249
298
|
/**
|
|
250
299
|
* An array of languages supported by the game.
|
|
251
300
|
*/
|
|
@@ -256,8 +305,9 @@ interface NovelyInit<Languages extends string, Characters extends Record<string,
|
|
|
256
305
|
characters: Characters;
|
|
257
306
|
/**
|
|
258
307
|
* An object that provides access to the game's storage system.
|
|
308
|
+
* @default localStorage // at key `novely-game-storage`
|
|
259
309
|
*/
|
|
260
|
-
storage
|
|
310
|
+
storage?: Storage;
|
|
261
311
|
/**
|
|
262
312
|
* Delay loading data until Promise is resolved
|
|
263
313
|
*/
|
|
@@ -273,7 +323,15 @@ interface NovelyInit<Languages extends string, Characters extends Record<string,
|
|
|
273
323
|
/**
|
|
274
324
|
* An object containing the translation functions used in the game
|
|
275
325
|
*/
|
|
276
|
-
|
|
326
|
+
translation: Record<Languages, {
|
|
327
|
+
internal: Record<BaseTranslationStrings, string>;
|
|
328
|
+
/**
|
|
329
|
+
* IETF BCP 47 language tag
|
|
330
|
+
*/
|
|
331
|
+
tag?: string;
|
|
332
|
+
plural?: Record<string, Pluralization>;
|
|
333
|
+
actions?: TranslationActions;
|
|
334
|
+
}>;
|
|
277
335
|
/**
|
|
278
336
|
* Initial state value
|
|
279
337
|
*/
|
|
@@ -324,15 +382,15 @@ interface NovelyInit<Languages extends string, Characters extends Record<string,
|
|
|
324
382
|
*/
|
|
325
383
|
preloadAssets?: "lazy" | "blocking";
|
|
326
384
|
}
|
|
327
|
-
declare const novely: <Languages extends string, Characters extends Record<string, Character<Languages>>,
|
|
385
|
+
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, languages, state: defaultState, data: defaultData, autosaves, migrations, throttleTimeout, getLanguage, overrideLanguage, askBeforeExit, preloadAssets }: NovelyInit<Languages, Characters, StateScheme, DataScheme>) => {
|
|
328
386
|
/**
|
|
329
387
|
* Function to set story
|
|
330
388
|
*/
|
|
331
|
-
withStory: (
|
|
389
|
+
withStory: (story: Story) => Promise<void>;
|
|
332
390
|
/**
|
|
333
391
|
* Function to get actions
|
|
334
392
|
*/
|
|
335
|
-
action: ActionProxyProvider<Characters>;
|
|
393
|
+
action: ActionProxyProvider<Characters, Languages>;
|
|
336
394
|
/**
|
|
337
395
|
* State that belongs to games
|
|
338
396
|
*/
|
|
@@ -350,11 +408,7 @@ declare const novely: <Languages extends string, Characters extends Record<strin
|
|
|
350
408
|
/**
|
|
351
409
|
* Unwraps translatable content to a string value
|
|
352
410
|
*/
|
|
353
|
-
unwrap(content:
|
|
354
|
-
/**
|
|
355
|
-
* Function that is used for translation
|
|
356
|
-
*/
|
|
357
|
-
t: Inter["t"];
|
|
411
|
+
unwrap(content: string | (() => string) | Record<Languages, string> | Exclude<Record<Languages, string | (() => string)>, Record<string, string>>): string;
|
|
358
412
|
};
|
|
359
413
|
|
|
360
|
-
export { ActionProxyProvider, AudioHandle, Character, CharacterHandle, CoreData, CustomHandler, CustomHandlerGetResult, CustomHandlerGetResultDataFunction, DefaultActionProxyProvider, Emotions, FunctionableValue, GetActionParameters, Lang, NovelyScreen, Path, Renderer, RendererInit, RendererStore, Storage, StorageData, StorageMeta, Stored, Story, Thenable, TypewriterSpeed, Unwrappable, ValidAction, localStorageStorage, novely };
|
|
414
|
+
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 RendererStore, type Storage, type StorageData, type StorageMeta, type Stored, type Story, type Thenable, type TranslationActions, type TypewriterSpeed, type Unwrappable, type ValidAction, localStorageStorage, novely };
|