@novely/core 0.31.2 → 0.32.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 +22 -2
- package/dist/index.global.js +32 -6
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +32 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -483,7 +483,7 @@ type Character<$Lang extends Lang = string> = {
|
|
|
483
483
|
type ValidAction = ['choice', number] | ['clear', Set<keyof DefaultActionProxy>?, Set<string>?, {
|
|
484
484
|
music: Set<string>;
|
|
485
485
|
sounds: Set<string>;
|
|
486
|
-
}?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['say', string, TextContent<string, State>] | ['end'] | ['showBackground', string | NonEmptyRecord<BackgroundImage>] | ['playMusic', string] | ['stopMusic', string] | ['pauseMusic', string] | ['playSound', audio: string, loop?: boolean] | ['pauseSound', string] | ['stopSound', string] | ['voice', string] | ['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[];
|
|
486
|
+
}?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['say', string, TextContent<string, State>] | ['end'] | ['showBackground', string | NonEmptyRecord<BackgroundImage>] | ['playMusic', string] | ['stopMusic', string] | ['pauseMusic', string] | ['playSound', audio: string, loop?: boolean] | ['pauseSound', string] | ['stopSound', string] | ['voice', string | Record<string, string>] | ['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[];
|
|
487
487
|
type Story = Record<string, ValidAction[]>;
|
|
488
488
|
type TextContent<L extends string, S extends State> = string | ((state: S) => string) | Record<L, string | ((state: S) => string)>;
|
|
489
489
|
type FunctionableValue<T> = T | (() => T);
|
|
@@ -587,6 +587,7 @@ type ConditionCheckFunction<S extends State, R extends string | true | false> =
|
|
|
587
587
|
type FunctionAction<L extends string, S extends State> = (props: FunctionActionProps<L, S>) => Thenable<void>;
|
|
588
588
|
type ActionInputSetup = (input: HTMLInputElement, cleanup: (cb: () => void) => void) => void;
|
|
589
589
|
type BackgroundImage = Partial<Record<'portrait' | 'landscape' | 'all', string>> & Record<string, string>;
|
|
590
|
+
type VoiceAction<L extends Lang> = (params: string | Partial<Record<L, string>>) => ValidAction;
|
|
590
591
|
type ActionProxy<Characters extends Record<string, Character>, Languages extends Lang, S extends State> = {
|
|
591
592
|
choice: {
|
|
592
593
|
(...choices: [name: TextContent<Languages, S>, actions: ValidAction[], active?: ChoiceCheckFunction<Languages, S>][]): ValidAction;
|
|
@@ -614,8 +615,18 @@ type ActionProxy<Characters extends Record<string, Character>, Languages extends
|
|
|
614
615
|
stopSound: (audio: string) => ValidAction;
|
|
615
616
|
/**
|
|
616
617
|
* Plays voice
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```
|
|
621
|
+
* engine.script({
|
|
622
|
+
* start: [
|
|
623
|
+
* engine.action.voice('./rick-astley-never-gonna-give-you-up.mp3'),
|
|
624
|
+
* engine.action.say('Rick', 'Never gonna give you up'),
|
|
625
|
+
* ]
|
|
626
|
+
* })
|
|
627
|
+
* ```
|
|
617
628
|
*/
|
|
618
|
-
voice:
|
|
629
|
+
voice: VoiceAction<Languages>;
|
|
619
630
|
/**
|
|
620
631
|
* Stops currently playing voice
|
|
621
632
|
*/
|
|
@@ -718,6 +729,15 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
|
|
|
718
729
|
* Data updates still will work in case Novely already was loaded
|
|
719
730
|
*/
|
|
720
731
|
destroy(): void;
|
|
732
|
+
/**
|
|
733
|
+
* Funtion to get current storage data
|
|
734
|
+
*
|
|
735
|
+
* @example
|
|
736
|
+
* ```ts
|
|
737
|
+
* const currentStorageData = engine.getCurrentStorageData();
|
|
738
|
+
* ```
|
|
739
|
+
*/
|
|
740
|
+
getCurrentStorageData: () => StorageData<$Language, $Data> | null;
|
|
721
741
|
};
|
|
722
742
|
|
|
723
743
|
export { type ActionInputOnInputMeta, type ActionInputSetup, type ActionProxy, type AllowedContent, type AudioHandle, type BackgroundImage, type BaseTranslationStrings, type Character, type CharacterHandle, type ConditionParams, type Context, type CoreData, type CustomHandler, type CustomHandlerFunctionGetFn, type CustomHandlerFunctionParameters, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type Data, type DeepPartial, type DefaultActionProxy, EN, type Emotions, type FunctionableValue, type GetActionParameters, JP, KK, type Lang, type NovelyInit, type NovelyScreen, type Path, type PluralType, type Pluralization, RU, type Renderer, type RendererInit, 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 TypewriterSpeed, type ValidAction, localStorageStorage, novely };
|
package/dist/index.global.js
CHANGED
|
@@ -1054,6 +1054,9 @@ var Novely = (() => {
|
|
|
1054
1054
|
let stored = await storage.get();
|
|
1055
1055
|
for (const migration of migrations) {
|
|
1056
1056
|
stored = migration(stored);
|
|
1057
|
+
if (DEV && !stored) {
|
|
1058
|
+
throw new Error("Migrations should return a value.");
|
|
1059
|
+
}
|
|
1057
1060
|
}
|
|
1058
1061
|
if (overrideLanguage || !stored.meta[0]) {
|
|
1059
1062
|
stored.meta[0] = getLanguageWithoutParameters();
|
|
@@ -1214,16 +1217,21 @@ var Novely = (() => {
|
|
|
1214
1217
|
return current;
|
|
1215
1218
|
};
|
|
1216
1219
|
const exit = (force = false, saving = true) => {
|
|
1217
|
-
|
|
1220
|
+
const ctx = renderer.getContext(MAIN_CONTEXT_KEY);
|
|
1221
|
+
const stack = useStack(ctx);
|
|
1222
|
+
const current = stack.value;
|
|
1223
|
+
const isSaved = () => {
|
|
1224
|
+
const { saves } = storageData.get();
|
|
1225
|
+
const [currentPath, currentData] = stack.value;
|
|
1226
|
+
return saves.some(([path, data2, [date, type2]]) => type2 === "manual" && times.has(date) && dequal(path, currentPath) && dequal(data2, currentData));
|
|
1227
|
+
};
|
|
1228
|
+
if (interacted > 1 && !force && askBeforeExit && !isSaved()) {
|
|
1218
1229
|
renderer.ui.showExitPrompt();
|
|
1219
1230
|
return;
|
|
1220
1231
|
}
|
|
1221
|
-
const ctx = renderer.getContext(MAIN_CONTEXT_KEY);
|
|
1222
1232
|
if (interacted > 0 && saving) {
|
|
1223
1233
|
save("auto");
|
|
1224
1234
|
}
|
|
1225
|
-
const stack = useStack(ctx);
|
|
1226
|
-
const current = stack.value;
|
|
1227
1235
|
stack.clear();
|
|
1228
1236
|
ctx.clear(EMPTY_SET, EMPTY_SET, { music: EMPTY_SET, sounds: EMPTY_SET }, noop);
|
|
1229
1237
|
renderer.ui.showScreen("mainmenu");
|
|
@@ -1397,7 +1405,13 @@ var Novely = (() => {
|
|
|
1397
1405
|
push();
|
|
1398
1406
|
},
|
|
1399
1407
|
voice({ ctx, push }, [source]) {
|
|
1400
|
-
|
|
1408
|
+
const [lang] = storageData.get().meta;
|
|
1409
|
+
const audioSource = isString(source) ? source : source[lang];
|
|
1410
|
+
if (!audioSource) {
|
|
1411
|
+
push();
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
ctx.audio.voice(audioSource);
|
|
1401
1415
|
push();
|
|
1402
1416
|
},
|
|
1403
1417
|
stopVoice({ ctx, push }) {
|
|
@@ -1721,6 +1735,9 @@ var Novely = (() => {
|
|
|
1721
1735
|
d: null,
|
|
1722
1736
|
c: null
|
|
1723
1737
|
};
|
|
1738
|
+
const getCurrentStorageData = () => {
|
|
1739
|
+
return coreData.get().dataLoaded ? klona(storageData.get()) : null;
|
|
1740
|
+
};
|
|
1724
1741
|
return {
|
|
1725
1742
|
/**
|
|
1726
1743
|
* Function to set game script
|
|
@@ -1805,7 +1822,16 @@ var Novely = (() => {
|
|
|
1805
1822
|
dataLoaded.cancel();
|
|
1806
1823
|
UIInstance.unmount();
|
|
1807
1824
|
unsubscribeFromBrowserVisibilityChange();
|
|
1808
|
-
}
|
|
1825
|
+
},
|
|
1826
|
+
/**
|
|
1827
|
+
* Funtion to get current storage data
|
|
1828
|
+
*
|
|
1829
|
+
* @example
|
|
1830
|
+
* ```ts
|
|
1831
|
+
* const currentStorageData = engine.getCurrentStorageData();
|
|
1832
|
+
* ```
|
|
1833
|
+
*/
|
|
1834
|
+
getCurrentStorageData
|
|
1809
1835
|
};
|
|
1810
1836
|
};
|
|
1811
1837
|
|