@novely/core 0.45.1 → 0.46.0-next.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 CHANGED
@@ -1,16 +1,9 @@
1
- type LocalStorageStorageSettings = {
2
- key: string;
3
- };
4
- type NovelyStorage = {
5
- get: () => Promise<StorageData>;
6
- set: (data: StorageData) => Promise<void>;
1
+ type Stored<T> = {
2
+ subscribe: (cb: (value: T) => void) => () => void;
3
+ update: (fn: (prev: T) => T) => void;
4
+ set: (val: T) => void;
5
+ get: () => T;
7
6
  };
8
- declare const localStorageStorage: (options: LocalStorageStorageSettings) => NovelyStorage;
9
-
10
- type PluralType = Intl.LDMLPluralRule;
11
- type Pluralization = Partial<Record<PluralType, string>>;
12
- type AllowedContent = string | ((state: State | Data) => string | string[]) | string[] | (string | ((state: State | Data) => string | string[]))[];
13
- type TranslationActions = Partial<Record<string, (str: string) => string>>;
14
7
 
15
8
  declare const RU: {
16
9
  NewGame: string;
@@ -47,6 +40,8 @@ declare const RU: {
47
40
  MusicVolume: string;
48
41
  SoundVolume: string;
49
42
  VoiceVolume: string;
43
+ Close: string;
44
+ DialogOverview: string;
50
45
  };
51
46
  type BaseTranslationStrings = keyof typeof RU;
52
47
  declare const EN: Record<BaseTranslationStrings, string>;
@@ -59,14 +54,7 @@ declare const KK: Record<BaseTranslationStrings, string>;
59
54
  */
60
55
  declare const JP: Record<BaseTranslationStrings, string>;
61
56
 
62
- type Stored<T> = {
63
- subscribe: (cb: (value: T) => void) => () => void;
64
- update: (fn: (prev: T) => T) => void;
65
- set: (val: T) => void;
66
- get: () => T;
67
- };
68
-
69
- interface CharacterHandle {
57
+ type CharacterHandle = {
70
58
  canvas: HTMLCanvasElement;
71
59
  ctx: CanvasRenderingContext2D;
72
60
  emotion: (emotion: string, render: boolean) => void;
@@ -74,7 +62,7 @@ interface CharacterHandle {
74
62
  remove: (className?: string, style?: string, duration?: number, restoring?: boolean) => Promise<void>;
75
63
  animate: (classes: string[]) => void;
76
64
  emotions: Record<string, HTMLImageElement[]>;
77
- }
65
+ };
78
66
  type CustomActionHandle = {
79
67
  /**
80
68
  * Function to remove custom action from screen (and from your state if any completely)
@@ -101,7 +89,13 @@ type Context = {
101
89
  character: (character: string) => CharacterHandle;
102
90
  background: (background: Record<string, string>) => void;
103
91
  dialog: (content: string, name: string, character: string | undefined, emotion: string | undefined, resolve: () => void) => void;
104
- choices: (question: string, choices: [name: string, active: Stored<boolean>, visible: Stored<boolean>, onselect: () => void, image: string][], resolve: (selected: number) => void) => void;
92
+ choices: (question: string, choices: [
93
+ name: string,
94
+ active: Stored<boolean>,
95
+ visible: Stored<boolean>,
96
+ onselect: () => void,
97
+ image: string
98
+ ][], resolve: (selected: number) => void) => void;
105
99
  input: (question: string, onInput: (meta: ActionInputOnInputMeta<Lang, State>) => void, setup: ActionInputSetup, resolve: () => void) => void;
106
100
  clear: (keep: Set<keyof DefaultActionProxy>, keepCharacters: Set<string>, keepAudio: {
107
101
  music: Set<string>;
@@ -237,14 +231,29 @@ type RendererInit<$Language extends Lang, $Characters extends Record<string, Cha
237
231
  getLanguageDisplayName: (lang: Lang) => string;
238
232
  getCharacterColor: (character: string) => string;
239
233
  getCharacterAssets: (character: string, emotion: string) => string[];
240
- getResourseType: (url: string) => Promise<"image" | "audio" | "other">;
234
+ getResourseType: (url: string) => Promise<'image' | 'audio' | 'other'>;
235
+ getDialogOverview: () => DialogOverview;
241
236
  };
242
237
 
238
+ type LocalStorageStorageSettings = {
239
+ key: string;
240
+ };
241
+ type NovelyStorage = {
242
+ get: () => Promise<StorageData>;
243
+ set: (data: StorageData) => Promise<void>;
244
+ };
245
+ declare const localStorageStorage: (options: LocalStorageStorageSettings) => NovelyStorage;
246
+
247
+ type PluralType = Intl.LDMLPluralRule;
248
+ type Pluralization = Partial<Record<PluralType, string>>;
249
+ type AllowedContent = string | ((state: State | Data) => string | string[]) | string[] | (string | ((state: State | Data) => string | string[]))[];
250
+ type TranslationActions = Partial<Record<string, (str: string) => string>>;
251
+
243
252
  declare const getLanguage: (languages: string[]) => string;
244
253
 
245
254
  type NovelyAsset = {
246
255
  readonly source: string;
247
- readonly type: "audio" | "image";
256
+ readonly type: 'audio' | 'image';
248
257
  };
249
258
  type Thenable<T> = T | Promise<T>;
250
259
  type PathItem = [null, number | string] | ['jump', string] | ['choice', number] | ['choice:exit'] | ['condition', string] | ['condition:exit'] | ['exit'] | ['block', string] | ['block:exit'];
@@ -254,11 +263,7 @@ type Data = Record<string, any>;
254
263
  type SaveDate = number;
255
264
  type SaveType = 'manual' | 'auto';
256
265
  type SaveMeta = [date: SaveDate, type: SaveType];
257
- type Save<S extends State = State> = [
258
- path: Path,
259
- state: S,
260
- meta: SaveMeta
261
- ];
266
+ type Save<S extends State = State> = [path: Path, state: S, meta: SaveMeta, state_snapshots: S[]];
262
267
  type Lang = string;
263
268
  type TypewriterSpeed = 'Slow' | 'Medium' | 'Fast' | 'Auto';
264
269
  type SoundVolume = number;
@@ -313,7 +318,7 @@ type TranslationDescription = {
313
318
  actions?: TranslationActions;
314
319
  };
315
320
  type DefaultEmotions<$Characters extends Record<string, Character<Lang>>> = {
316
- [Character in keyof $Characters]?: (keyof $Characters[Character]['emotions'] & string);
321
+ [Character in keyof $Characters]?: keyof $Characters[Character]['emotions'] & string;
317
322
  };
318
323
  type CharacterAssetSizes<$Characters extends Record<string, Character<Lang>>> = {
319
324
  [Character in keyof $Characters]?: {
@@ -551,6 +556,21 @@ type TypeEssentials<$Lang extends Lang, $State extends State, $Data extends Data
551
556
  readonly d: $Data | null;
552
557
  readonly c: $Characters | null;
553
558
  };
559
+ type DialogOverviewEntry = {
560
+ /**
561
+ * Link to character voice
562
+ */
563
+ voice: string | undefined;
564
+ /**
565
+ * Character name
566
+ */
567
+ name: string;
568
+ /**
569
+ * Text that character says
570
+ */
571
+ text: string;
572
+ };
573
+ type DialogOverview = DialogOverviewEntry[];
554
574
 
555
575
  type Name<$Lang extends Lang> = string | Record<$Lang, string>;
556
576
  type Emotions<Emotion extends string = string> = Record<Emotion, string | NovelyAsset | (string | NovelyAsset)[]>;
@@ -563,7 +583,7 @@ type Character<$Lang extends Lang = string> = {
563
583
  type ValidAction = ['choice', string | undefined, ...[string, unknown[], (() => boolean)?, (() => boolean)?, string?][]] | ['clear', Set<keyof DefaultActionProxy>?, Set<string>?, {
564
584
  music: Set<string>;
565
585
  sounds: Set<string>;
566
- }?] | ['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[];
586
+ }?] | ['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[];
567
587
  type Story = Record<string, ValidAction[]>;
568
588
  type TextContent<L extends string, S extends State> = string | ((state: S) => string) | Record<L, string | ((state: S) => string)>;
569
589
  type FunctionableValue<T> = T | (() => T);
@@ -657,7 +677,7 @@ type CustomHandlerInfo = CustomHandlerCalling & {
657
677
  /**
658
678
  * Assets (pictures, audio files) used by action
659
679
  */
660
- assets?: string[];
680
+ assets?: (NovelyAsset | string)[];
661
681
  /**
662
682
  * When true interacting with it will be saved in history
663
683
  */
@@ -885,7 +905,7 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
885
905
  * @example
886
906
  * ```ts
887
907
  * import type { ConditionParams, StateFunction } from '@novely/core';
888
- *
908
+ *
889
909
  * const conditionCheck = (state: StateFunction<ConditionParams<typeof engine.typeEssintials>>) => {
890
910
  * return state.age >= 18;
891
911
  * }