@novely/core 0.49.0 → 0.51.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 +100 -23
- package/dist/index.js +542 -483
- package/dist/index.js.map +1 -1
- package/package.json +10 -13
- package/dist/index.global.js +0 -2867
- package/dist/index.global.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ type Stored<T> = {
|
|
|
4
4
|
set: (val: T) => void;
|
|
5
5
|
get: () => T;
|
|
6
6
|
};
|
|
7
|
+
type Derived<T> = {
|
|
8
|
+
subscribe: (cb: (value: T) => void) => () => void;
|
|
9
|
+
get: () => T;
|
|
10
|
+
};
|
|
7
11
|
|
|
8
12
|
declare const RU: {
|
|
9
13
|
NewGame: string;
|
|
@@ -45,14 +49,6 @@ declare const RU: {
|
|
|
45
49
|
};
|
|
46
50
|
type BaseTranslationStrings = keyof typeof RU;
|
|
47
51
|
declare const EN: Record<BaseTranslationStrings, string>;
|
|
48
|
-
/**
|
|
49
|
-
* Translated automatically
|
|
50
|
-
*/
|
|
51
|
-
declare const KK: Record<BaseTranslationStrings, string>;
|
|
52
|
-
/**
|
|
53
|
-
* Translated automatically
|
|
54
|
-
*/
|
|
55
|
-
declare const JP: Record<BaseTranslationStrings, string>;
|
|
56
52
|
|
|
57
53
|
type CharacterHandle = {
|
|
58
54
|
emotion: (emotion: string, render: boolean) => void;
|
|
@@ -108,9 +104,9 @@ type Context = {
|
|
|
108
104
|
text: (str: string, resolve: () => void) => void;
|
|
109
105
|
vibrate: (pattern: VibratePattern) => void;
|
|
110
106
|
audio: {
|
|
111
|
-
voice: (source: string) => void;
|
|
107
|
+
voice: (source: string, paused: Derived<boolean>) => void;
|
|
112
108
|
voiceStop: () => void;
|
|
113
|
-
music: (source: string, method: 'music' | 'sound') => AudioHandle;
|
|
109
|
+
music: (source: string, paused: Derived<boolean>, method: 'music' | 'sound') => AudioHandle;
|
|
114
110
|
/**
|
|
115
111
|
* Stop all sounds
|
|
116
112
|
*/
|
|
@@ -232,6 +228,7 @@ type RendererInit<$Language extends Lang, $Characters extends Record<string, Cha
|
|
|
232
228
|
getCharacterAssets: (character: string, emotion: string) => string[];
|
|
233
229
|
getDialogOverview: () => Promise<DialogOverview>;
|
|
234
230
|
getResourseType: (url: string) => Promise<'image' | 'audio' | 'other'>;
|
|
231
|
+
setLanguage: (language: string) => void;
|
|
235
232
|
};
|
|
236
233
|
|
|
237
234
|
type LocalStorageStorageSettings = {
|
|
@@ -256,7 +253,7 @@ type NovelyAsset = {
|
|
|
256
253
|
readonly type: 'audio' | 'image';
|
|
257
254
|
};
|
|
258
255
|
type Thenable<T> = T | Promise<T>;
|
|
259
|
-
type PathItem = [null, number
|
|
256
|
+
type PathItem = [null, number] | ['jump', string] | ['choice', number] | ['choice:exit'] | ['condition', string] | ['condition:exit'] | ['exit'] | ['block', string] | ['block:exit'];
|
|
260
257
|
type Path = PathItem[];
|
|
261
258
|
type State = Record<string, any>;
|
|
262
259
|
type Data = Record<string, any>;
|
|
@@ -300,6 +297,8 @@ type Assign<A extends object, B extends object> = Pick<A, Exclude<keyof A, keyof
|
|
|
300
297
|
type NonEmptyRecord<T extends Record<PropertyKey, unknown>> = keyof T extends never ? never : T;
|
|
301
298
|
type CoreData = {
|
|
302
299
|
dataLoaded: boolean;
|
|
300
|
+
paused: boolean;
|
|
301
|
+
focused: boolean;
|
|
303
302
|
};
|
|
304
303
|
type StackHolder = Save[] & {
|
|
305
304
|
previous: Save | undefined;
|
|
@@ -332,7 +331,7 @@ type CharactersData<$Characters extends Record<string, Character<Lang>>> = {
|
|
|
332
331
|
emotions: Array<keyof $Characters[Character]['emotions']>;
|
|
333
332
|
};
|
|
334
333
|
};
|
|
335
|
-
type AssetsPreloading = 'lazy' | '
|
|
334
|
+
type AssetsPreloading = 'lazy' | 'automatic';
|
|
336
335
|
type CloneFN = <T>(value: T) => T;
|
|
337
336
|
type StoryOptionsStatic = {
|
|
338
337
|
/**
|
|
@@ -378,6 +377,7 @@ type StoryOptionsDynamic = {
|
|
|
378
377
|
load: (scene: string) => Promise<Story>;
|
|
379
378
|
};
|
|
380
379
|
type StoryOptions = StoryOptionsStatic | StoryOptionsDynamic;
|
|
380
|
+
type OnLanguageChange<$Lang extends Lang> = (language: $Lang) => void;
|
|
381
381
|
interface NovelyInit<$Language extends Lang, $Characters extends Record<string, Character<NoInfer<$Language>>>, $State extends State, $Data extends Data, $Actions extends Record<string, (...args: any[]) => ValidAction>> {
|
|
382
382
|
/**
|
|
383
383
|
* An object containing the characters in the game.
|
|
@@ -552,7 +552,11 @@ interface NovelyInit<$Language extends Lang, $Characters extends Record<string,
|
|
|
552
552
|
*/
|
|
553
553
|
askBeforeExit?: boolean;
|
|
554
554
|
/**
|
|
555
|
-
*
|
|
555
|
+
* "automatic" will try to preload assets when possible
|
|
556
|
+
*
|
|
557
|
+
* "lazy" will load assets only when they are shown
|
|
558
|
+
*
|
|
559
|
+
* @default "automatic"
|
|
556
560
|
*/
|
|
557
561
|
preloadAssets?: AssetsPreloading;
|
|
558
562
|
/**
|
|
@@ -594,20 +598,33 @@ interface NovelyInit<$Language extends Lang, $Characters extends Record<string,
|
|
|
594
598
|
*/
|
|
595
599
|
defaultTypewriterSpeed?: TypewriterSpeed;
|
|
596
600
|
/**
|
|
597
|
-
*
|
|
601
|
+
* Options to control story loading behaviour
|
|
598
602
|
*/
|
|
599
603
|
storyOptions?: StoryOptions;
|
|
604
|
+
/**
|
|
605
|
+
* Will be called ONLY when language was changed by player
|
|
606
|
+
*/
|
|
607
|
+
onLanguageChange?: OnLanguageChange<NoInfer<$Language>>;
|
|
600
608
|
}
|
|
601
609
|
type StateFunction<S extends State> = {
|
|
602
610
|
(value: DeepPartial<S> | ((prev: S) => S)): void;
|
|
603
611
|
(): S;
|
|
604
612
|
};
|
|
613
|
+
/**
|
|
614
|
+
* @deprecated `EngineTypes` should be used instead
|
|
615
|
+
*/
|
|
605
616
|
type TypeEssentials<$Lang extends Lang, $State extends State, $Data extends Data, $Characters extends Record<string, Character<$Lang>>> = {
|
|
606
617
|
readonly l: $Lang | null;
|
|
607
618
|
readonly s: $State | null;
|
|
608
619
|
readonly d: $Data | null;
|
|
609
620
|
readonly c: $Characters | null;
|
|
610
621
|
};
|
|
622
|
+
type EngineTypes<$Lang extends Lang = Lang, $State extends State = State, $Data extends Data = Data, $Characters extends Record<string, Character<$Lang>> = Record<string, Character<$Lang>>> = {
|
|
623
|
+
readonly l: $Lang;
|
|
624
|
+
readonly s: $State;
|
|
625
|
+
readonly d: $Data;
|
|
626
|
+
readonly c: $Characters;
|
|
627
|
+
};
|
|
611
628
|
type DialogOverviewEntry = {
|
|
612
629
|
/**
|
|
613
630
|
* Link to character voice
|
|
@@ -635,7 +652,7 @@ type Character<$Lang extends Lang = string> = {
|
|
|
635
652
|
type ValidAction = ['choice', string | undefined, ...[string, unknown[], (() => boolean)?, (() => boolean)?, string?][]] | ['clear', Set<keyof DefaultActionProxy>?, Set<string>?, {
|
|
636
653
|
music: Set<string>;
|
|
637
654
|
sounds: Set<string>;
|
|
638
|
-
}?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['end'] | ['showBackground', string | NovelyAsset | BackgroundImage] | ['playMusic', string | NovelyAsset] | ['stopMusic', string | NovelyAsset] | ['pauseMusic', string | NovelyAsset] | ['playSound', audio: string | NovelyAsset, loop?: boolean] | ['pauseSound', string | NovelyAsset] | ['stopSound', string | NovelyAsset] | ['voice', string | NovelyAsset | Record<string, string | NovelyAsset>] | ['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[];
|
|
655
|
+
}?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['end'] | ['showBackground', string | NovelyAsset | BackgroundImage] | ['playMusic', string | NovelyAsset] | ['stopMusic', string | NovelyAsset] | ['pauseMusic', string | NovelyAsset] | ['playSound', audio: string | NovelyAsset, loop?: boolean] | ['pauseSound', string | NovelyAsset] | ['stopSound', string | NovelyAsset] | ['voice', string | NovelyAsset | Record<string, string | NovelyAsset>] | ['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 | NovelyAsset] | ['block', string] | ValidAction[];
|
|
639
656
|
type Story = Record<string, ValidAction[]>;
|
|
640
657
|
type TextContent<L extends string, S extends State> = string | ((state: S) => string) | Record<L, string | ((state: S) => string)>;
|
|
641
658
|
type FunctionableValue<T> = T | (() => T);
|
|
@@ -710,6 +727,10 @@ type CustomHandlerFunctionParameters<L extends string, S extends State> = {
|
|
|
710
727
|
* Function to replace template content
|
|
711
728
|
*/
|
|
712
729
|
templateReplace: (content: TextContent<L, State>, values?: State) => string;
|
|
730
|
+
/**
|
|
731
|
+
* Is game currently paused
|
|
732
|
+
*/
|
|
733
|
+
paused: Derived<boolean>;
|
|
713
734
|
};
|
|
714
735
|
type CustomHandlerFunction<L extends string, S extends State> = (parameters: CustomHandlerFunctionParameters<L, S>) => Thenable<void>;
|
|
715
736
|
type CustomHandlerCalling = {
|
|
@@ -892,7 +913,7 @@ type ActionProxy<Characters extends Record<string, Character>, Languages extends
|
|
|
892
913
|
vibrate: (...pattern: number[]) => ValidAction;
|
|
893
914
|
next: () => ValidAction;
|
|
894
915
|
text: (...text: TextContent<Languages, S>[]) => ValidAction;
|
|
895
|
-
preload: (source: string) => ValidAction;
|
|
916
|
+
preload: (source: string | NovelyAsset) => ValidAction;
|
|
896
917
|
block: (scene: string) => ValidAction;
|
|
897
918
|
};
|
|
898
919
|
type DefaultActionProxy = ActionProxy<Record<string, Character>, Lang, State>;
|
|
@@ -902,12 +923,21 @@ type VirtualActions<$Characters extends Record<string, Character>, $Lang extends
|
|
|
902
923
|
say: (character: keyof $Characters, content: TextContent<$Lang, $State>) => ValidAction;
|
|
903
924
|
};
|
|
904
925
|
|
|
905
|
-
type ConditionParams<T> = T extends
|
|
906
|
-
type ChoiceParams<T> = T extends
|
|
907
|
-
type FunctionParams<T> = T extends
|
|
908
|
-
type InputHandler<T> = T extends
|
|
926
|
+
type ConditionParams<T> = T extends EngineTypes<any, infer $State, any, any> ? $State : never;
|
|
927
|
+
type ChoiceParams<T> = T extends EngineTypes<infer $Lang, infer $State, any, any> ? ChoiceCheckFunctionProps<$Lang, $State> : never;
|
|
928
|
+
type FunctionParams<T> = T extends EngineTypes<infer $Lang, infer $State, any, any> ? FunctionActionProps<$Lang, $State> : never;
|
|
929
|
+
type InputHandler<T> = T extends EngineTypes<infer $Lang, infer $State, any, any> ? ActionInputOnInputMeta<$Lang, $State> : never;
|
|
930
|
+
/**
|
|
931
|
+
* @example
|
|
932
|
+
* ```ts
|
|
933
|
+
* type Types = TypesFromEngine<typeof engine>;
|
|
934
|
+
* ```
|
|
935
|
+
*/
|
|
936
|
+
type TypesFromEngine<T> = T extends {
|
|
937
|
+
types: EngineTypes<infer $Lang, infer $State, infer $Data, infer $Characters> | null;
|
|
938
|
+
} ? EngineTypes<$Lang, $State, $Data, $Characters> : never;
|
|
909
939
|
|
|
910
|
-
declare const novely: <$Language extends string, $Characters extends Record<string, Character<$Language>>, $State extends State, $Data extends Data, $Actions extends Record<string, (...args: any[]) => ValidAction>>({ characters, characterAssetSizes, defaultEmotions, storage, storageDelay, renderer: createRenderer, initialScreen, translation, state: defaultState, data: defaultData, autosaves, migrations, throttleTimeout, getLanguage, overrideLanguage, askBeforeExit, preloadAssets, parallelAssetsDownloadLimit, fetch: request, cloneFunction: clone, saveOnUnload, startKey, defaultTypewriterSpeed, storyOptions, }: NovelyInit<$Language, $Characters, $State, $Data, $Actions>) => {
|
|
940
|
+
declare const novely: <$Language extends string, $Characters extends Record<string, Character<$Language>>, $State extends State, $Data extends Data, $Actions extends Record<string, (...args: any[]) => ValidAction>>({ characters, characterAssetSizes, defaultEmotions, storage, storageDelay, renderer: createRenderer, initialScreen, translation, state: defaultState, data: defaultData, autosaves, migrations, throttleTimeout, getLanguage, overrideLanguage, askBeforeExit, preloadAssets, parallelAssetsDownloadLimit, fetch: request, cloneFunction: clone, saveOnUnload, startKey, defaultTypewriterSpeed, storyOptions, onLanguageChange, }: NovelyInit<$Language, $Characters, $State, $Data, $Actions>) => {
|
|
911
941
|
/**
|
|
912
942
|
* Function to set game script
|
|
913
943
|
*
|
|
@@ -958,7 +988,7 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
|
|
|
958
988
|
data: StateFunction<$Data>;
|
|
959
989
|
/**
|
|
960
990
|
* Used in combination with type utilities
|
|
961
|
-
*
|
|
991
|
+
* @deprecated Use `engine.types` instead
|
|
962
992
|
* @example
|
|
963
993
|
* ```ts
|
|
964
994
|
* import type { ConditionParams, StateFunction } from '@novely/core';
|
|
@@ -969,6 +999,20 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
|
|
|
969
999
|
* ```
|
|
970
1000
|
*/
|
|
971
1001
|
typeEssentials: TypeEssentials<$Language, $State, $Data, $Characters>;
|
|
1002
|
+
/**
|
|
1003
|
+
* Used in combination with type utilities
|
|
1004
|
+
* @example
|
|
1005
|
+
* ```ts
|
|
1006
|
+
* import type { TypesFromEngine, ConditionParams, StateFunction } from '@novely/core';
|
|
1007
|
+
*
|
|
1008
|
+
* type Types = TypesFromEngine<typeof engine>;
|
|
1009
|
+
*
|
|
1010
|
+
* const conditionCheck = (state: StateFunction<ConditionParams<Types>>) => {
|
|
1011
|
+
* return state.age >= 18;
|
|
1012
|
+
* }
|
|
1013
|
+
* ```
|
|
1014
|
+
*/
|
|
1015
|
+
types: EngineTypes<$Language, $State, $Data, $Characters> | null;
|
|
972
1016
|
/**
|
|
973
1017
|
* Replaces content inside {{braces}} using global data
|
|
974
1018
|
* @example
|
|
@@ -1017,6 +1061,33 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
|
|
|
1017
1061
|
* ```
|
|
1018
1062
|
*/
|
|
1019
1063
|
setStorageData: (data: StorageData<$Language, $Data>) => void;
|
|
1064
|
+
/**
|
|
1065
|
+
* Function to control paused state. Custom Actions are provided with `paused` store they can subscribe to.
|
|
1066
|
+
* This function will notify Custom Actions. Pause state can be used when showing ads.
|
|
1067
|
+
* @example
|
|
1068
|
+
* ```ts
|
|
1069
|
+
* sdk.on('pause' () => engine.setPaused(true));
|
|
1070
|
+
* sdk.on('resume', () => engine.setPaused(false));
|
|
1071
|
+
* ```
|
|
1072
|
+
*/
|
|
1073
|
+
setPaused: (paused: boolean) => void;
|
|
1074
|
+
/**
|
|
1075
|
+
* Function to control focused state. It will affect `paused` store passed to Custom Actions.
|
|
1076
|
+
* This function can be used to pause game when it's not focused.
|
|
1077
|
+
* @example
|
|
1078
|
+
* ```ts
|
|
1079
|
+
* import { pauseOnBlur } from '@novely/core';
|
|
1080
|
+
*
|
|
1081
|
+
* // Will subscribe to blur/focus events and call `setFocused`
|
|
1082
|
+
* pauseOnBlur(engine);
|
|
1083
|
+
*
|
|
1084
|
+
* // OR
|
|
1085
|
+
*
|
|
1086
|
+
* sdk.on('focus' () => engine.setFocused(true));
|
|
1087
|
+
* sdk.on('blur', () => engine.setFocused(false));
|
|
1088
|
+
* ```
|
|
1089
|
+
*/
|
|
1090
|
+
setFocused: (focused: boolean) => void;
|
|
1020
1091
|
};
|
|
1021
1092
|
|
|
1022
1093
|
type Part = Record<string, (...args: any[]) => ValidAction>;
|
|
@@ -1065,4 +1136,10 @@ declare const asset: {
|
|
|
1065
1136
|
audio(source: string): NovelyAsset;
|
|
1066
1137
|
};
|
|
1067
1138
|
|
|
1068
|
-
|
|
1139
|
+
declare const pauseOnBlur: (engine: {
|
|
1140
|
+
setFocused: (focused: boolean) => void;
|
|
1141
|
+
}) => {
|
|
1142
|
+
unsubscribe: () => void;
|
|
1143
|
+
};
|
|
1144
|
+
|
|
1145
|
+
export { type ActionChoiceChoice, type ActionChoiceChoiceObject, type ActionInputOnInputMeta, type ActionInputSetup, type ActionInputSetupCleanup, type ActionProxy, type AllowedContent, type AudioHandle, type BackgroundImage, type BaseTranslationStrings, type Character, type CharacterAssetSizes, type CharacterHandle, type CharactersData, type ChoiceCheckFunction, type ChoiceCheckFunctionProps, type ChoiceOnSelectFunction, type ChoiceOnSelectFunctionProps, type ChoiceParams, type ConditionCheckFunction, type ConditionParams, type Context, type CoreData, type CustomActionHandle, type CustomHandler, type CustomHandlerFunction, type CustomHandlerFunctionGetFn, type CustomHandlerFunctionParameters, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type CustomHandlerInfo, type Data, type DeepPartial, type DefaultActionProxy, type Derived, EN, type Emotions, type EngineTypes, type FunctionParams, type FunctionableValue, type GetActionParameters, type InputHandler, type Lang, type NovelyAsset, type NovelyInit, type NovelyScreen, type NovelyStorage, type Path, type PathItem, type PluralType, type Pluralization, RU, type Renderer, type RendererInit, type RendererInitPreviewReturn, type Save, type Stack, type StackHolder, type State, type StateFunction, type StorageData, type StorageMeta, type Stored, type Story, type TextContent, type Thenable, type TranslationActions, type TypeEssentials, type TypesFromEngine, type TypewriterSpeed, type ValidAction, asset, extendAction, localStorageStorage, novely, pauseOnBlur };
|