@novely/core 0.38.2 → 0.39.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 +57 -14
- package/dist/index.global.js +559 -140
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +310 -166
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as micro_memoize from 'micro-memoize';
|
|
2
|
+
|
|
1
3
|
interface LocalStorageStorageSettings {
|
|
2
4
|
key: string;
|
|
3
5
|
}
|
|
@@ -99,7 +101,7 @@ type Context = {
|
|
|
99
101
|
get root(): HTMLElement;
|
|
100
102
|
set root(value: HTMLElement);
|
|
101
103
|
character: (character: string) => CharacterHandle;
|
|
102
|
-
background: (background: string
|
|
104
|
+
background: (background: Record<string, string>) => void;
|
|
103
105
|
dialog: (content: string, name: string, character: string | undefined, emotion: string | undefined, resolve: () => void) => void;
|
|
104
106
|
choices: (question: string, choices: [name: string, active: boolean][], resolve: (selected: number) => void) => void;
|
|
105
107
|
input: (question: string, onInput: (meta: ActionInputOnInputMeta<Lang, State>) => void, setup: ActionInputSetup, resolve: () => void) => void;
|
|
@@ -205,7 +207,7 @@ type RendererInitPreviewReturn = {
|
|
|
205
207
|
assets: string[];
|
|
206
208
|
};
|
|
207
209
|
type RendererInit<$Language extends Lang, $Characters extends Record<string, Character<$Language>>> = {
|
|
208
|
-
characters:
|
|
210
|
+
characters: CharactersData<$Characters>;
|
|
209
211
|
characterAssetSizes: CharacterAssetSizes<$Characters>;
|
|
210
212
|
set: (save: Save<State>) => Promise<void>;
|
|
211
213
|
restore: (save?: Save<State>) => Promise<void>;
|
|
@@ -235,11 +237,17 @@ type RendererInit<$Language extends Lang, $Characters extends Record<string, Cha
|
|
|
235
237
|
getStateFunction: (context: string) => StateFunction<State>;
|
|
236
238
|
clearCustomAction: (ctx: Context, customAction: CustomHandler) => void;
|
|
237
239
|
getLanguageDisplayName: (lang: Lang) => string;
|
|
240
|
+
getCharacterColor: (character: string) => string;
|
|
241
|
+
getCharacterAssets: (character: string, emotion: string) => string[];
|
|
238
242
|
getResourseType: (url: string) => Promise<"image" | "audio" | "other">;
|
|
239
243
|
};
|
|
240
244
|
|
|
241
245
|
declare const getLanguage: (languages: string[]) => string;
|
|
242
246
|
|
|
247
|
+
type NovelyAsset = {
|
|
248
|
+
readonly source: string;
|
|
249
|
+
readonly type: "audio" | "image";
|
|
250
|
+
};
|
|
243
251
|
type Thenable<T> = T | Promise<T>;
|
|
244
252
|
type PathItem = [null, number | string] | ['jump', string] | ['choice', number] | ['choice:exit'] | ['condition', string] | ['condition:exit'] | ['exit'] | ['block', string] | ['block:exit'];
|
|
245
253
|
type Path = PathItem[];
|
|
@@ -315,6 +323,12 @@ type CharacterAssetSizes<$Characters extends Record<string, Character<Lang>>> =
|
|
|
315
323
|
height: number;
|
|
316
324
|
};
|
|
317
325
|
};
|
|
326
|
+
type CharactersData<$Characters extends Record<string, Character<Lang>>> = {
|
|
327
|
+
[Character in keyof $Characters]: {
|
|
328
|
+
name: $Characters[Character]['name'];
|
|
329
|
+
emotions: Array<keyof $Characters[Character]['emotions']>;
|
|
330
|
+
};
|
|
331
|
+
};
|
|
318
332
|
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>> {
|
|
319
333
|
/**
|
|
320
334
|
* An object containing the characters in the game.
|
|
@@ -535,7 +549,7 @@ type TypeEssentials<$Lang extends Lang, $State extends State, $Data extends Data
|
|
|
535
549
|
};
|
|
536
550
|
|
|
537
551
|
type Name<$Lang extends Lang> = string | Record<$Lang, string>;
|
|
538
|
-
type Emotions<Emotion extends string = string> = Record<Emotion, string | string[]>;
|
|
552
|
+
type Emotions<Emotion extends string = string> = Record<Emotion, string | NovelyAsset | (string | NovelyAsset)[]>;
|
|
539
553
|
type Character<$Lang extends Lang = string> = {
|
|
540
554
|
name: Name<$Lang>;
|
|
541
555
|
color: string;
|
|
@@ -545,7 +559,7 @@ type Character<$Lang extends Lang = string> = {
|
|
|
545
559
|
type ValidAction = ['choice', number] | ['clear', Set<keyof DefaultActionProxy>?, Set<string>?, {
|
|
546
560
|
music: Set<string>;
|
|
547
561
|
sounds: Set<string>;
|
|
548
|
-
}?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['say', string, TextContent<string, State>] | ['end'] | ['showBackground', string |
|
|
562
|
+
}?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['say', string, TextContent<string, State>] | ['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[];
|
|
549
563
|
type Story = Record<string, ValidAction[]>;
|
|
550
564
|
type TextContent<L extends string, S extends State> = string | ((state: S) => string) | Record<L, string | ((state: S) => string)>;
|
|
551
565
|
type FunctionableValue<T> = T | (() => T);
|
|
@@ -707,8 +721,8 @@ type ConditionCheckFunction<S extends State, R extends string | true | false> =
|
|
|
707
721
|
type FunctionAction<L extends string, S extends State> = (props: FunctionActionProps<L, S>) => Thenable<void>;
|
|
708
722
|
type ActionInputSetupCleanup = () => void;
|
|
709
723
|
type ActionInputSetup = (input: HTMLInputElement) => ActionInputSetupCleanup | void;
|
|
710
|
-
type BackgroundImage =
|
|
711
|
-
type VoiceAction<L extends Lang> = (params: string | Partial<Record<L, string>>) => ValidAction;
|
|
724
|
+
type BackgroundImage = Record<string, string | NovelyAsset>;
|
|
725
|
+
type VoiceAction<L extends Lang> = (params: string | NovelyAsset | Partial<Record<L, string | NovelyAsset>>) => ValidAction;
|
|
712
726
|
type ActionProxy<Characters extends Record<string, Character>, Languages extends Lang, S extends State> = {
|
|
713
727
|
choice: {
|
|
714
728
|
(...choices: [name: TextContent<Languages, S>, actions: ValidAction[], active?: ChoiceCheckFunction<Languages, S>][]): ValidAction;
|
|
@@ -727,13 +741,16 @@ type ActionProxy<Characters extends Record<string, Character>, Languages extends
|
|
|
727
741
|
};
|
|
728
742
|
say: (character: keyof Characters, content: TextContent<Languages, S>) => ValidAction;
|
|
729
743
|
end: () => ValidAction;
|
|
730
|
-
showBackground:
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
744
|
+
showBackground: {
|
|
745
|
+
(background: string | NovelyAsset): ValidAction;
|
|
746
|
+
<T extends Record<string, string | NovelyAsset>>(background: NonEmptyRecord<T>): ValidAction;
|
|
747
|
+
};
|
|
748
|
+
playMusic: (audio: string | NovelyAsset) => ValidAction;
|
|
749
|
+
pauseMusic: (audio: string | NovelyAsset) => ValidAction;
|
|
750
|
+
stopMusic: (audio: string | NovelyAsset) => ValidAction;
|
|
751
|
+
playSound: (audio: string | NovelyAsset, loop?: boolean) => ValidAction;
|
|
752
|
+
pauseSound: (audio: string | NovelyAsset) => ValidAction;
|
|
753
|
+
stopSound: (audio: string | NovelyAsset) => ValidAction;
|
|
737
754
|
/**
|
|
738
755
|
* Plays voice
|
|
739
756
|
*
|
|
@@ -896,4 +913,30 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
|
|
|
896
913
|
*/
|
|
897
914
|
declare const extendAction: <Part0 extends Record<string, (...args: any[]) => ValidAction>, Part1 extends Record<string, (...args: any[]) => ValidAction>>(base: Part0, extension: Part1) => Readonly<Assign<Part0, Part1>>;
|
|
898
915
|
|
|
899
|
-
|
|
916
|
+
/**
|
|
917
|
+
* Memoizes and returns an asset selection object based on provided file variants.
|
|
918
|
+
* The selected asset depends on the client's support for various formats.
|
|
919
|
+
*
|
|
920
|
+
* @param {...string} variants - A variable number of strings, each representing a potential asset file URL.
|
|
921
|
+
* @returns {NovelyAsset} An object representing the selected asset with `source` and `type` properties.
|
|
922
|
+
*
|
|
923
|
+
* @throws {Error} If in DEV mode and no arguments are provided.
|
|
924
|
+
* @example
|
|
925
|
+
* ```
|
|
926
|
+
* import { asset } from 'novely';
|
|
927
|
+
*
|
|
928
|
+
* // Passed first have higher priority
|
|
929
|
+
* const classroom = asset(
|
|
930
|
+
* 'classroom.avif',
|
|
931
|
+
* 'classroom.webp',
|
|
932
|
+
* 'classroom.jpeg'
|
|
933
|
+
* );
|
|
934
|
+
*
|
|
935
|
+
* setTimeout(() => {
|
|
936
|
+
* console.log(classroom.source);
|
|
937
|
+
* }, 100);
|
|
938
|
+
* ```
|
|
939
|
+
*/
|
|
940
|
+
declare const asset: micro_memoize.Memoized<(...variants: string[]) => NovelyAsset>;
|
|
941
|
+
|
|
942
|
+
export { 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 ChoiceParams, type ConditionParams, type Context, type CoreData, type CustomActionHandle, type CustomHandler, type CustomHandlerFunctionGetFn, type CustomHandlerFunctionParameters, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type Data, type DeepPartial, type DefaultActionProxy, EN, type Emotions, type FunctionParams, type FunctionableValue, type GetActionParameters, type InputHandler, JP, KK, type Lang, type NovelyInit, type NovelyScreen, type Path, type PluralType, type Pluralization, RU, type Renderer, type RendererInit, type RendererInitPreviewReturn, 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 TypeEssentials, type TypewriterSpeed, type ValidAction, asset, extendAction, localStorageStorage, novely };
|