@novely/core 0.36.0-beta.1 → 0.36.0-beta.3
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 +28 -7
- package/dist/index.global.js +49 -9
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +49 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -72,7 +72,7 @@ interface CharacterHandle {
|
|
|
72
72
|
emotion: (emotion: string, render: boolean) => void;
|
|
73
73
|
append: (className?: string, style?: string, restoring?: boolean) => void;
|
|
74
74
|
remove: (className?: string, style?: string, duration?: number, restoring?: boolean) => Promise<void>;
|
|
75
|
-
animate: (
|
|
75
|
+
animate: (classes: string[]) => void;
|
|
76
76
|
emotions: Record<string, HTMLImageElement[]>;
|
|
77
77
|
}
|
|
78
78
|
type CustomActionHandle = {
|
|
@@ -510,7 +510,7 @@ type ValidAction = ['choice', number] | ['clear', Set<keyof DefaultActionProxy>?
|
|
|
510
510
|
type Story = Record<string, ValidAction[]>;
|
|
511
511
|
type TextContent<L extends string, S extends State> = string | ((state: S) => string) | Record<L, string | ((state: S) => string)>;
|
|
512
512
|
type FunctionableValue<T> = T | (() => T);
|
|
513
|
-
type CustomHandlerGetResultDataFunction =
|
|
513
|
+
type CustomHandlerGetResultDataFunction = <T = Record<string, unknown>>(data?: T) => T;
|
|
514
514
|
type CustomHandlerGetResult<I extends boolean> = {
|
|
515
515
|
/**
|
|
516
516
|
* Element for the custom action to be rendered into
|
|
@@ -587,6 +587,10 @@ type CustomHandlerCalling = {
|
|
|
587
587
|
skipOnRestore?: (getNext: () => Exclude<ValidAction, ValidAction[]>[]) => boolean;
|
|
588
588
|
};
|
|
589
589
|
type CustomHandlerInfo = CustomHandlerCalling & {
|
|
590
|
+
/**
|
|
591
|
+
* Assets (pictures, audio files) used by action
|
|
592
|
+
*/
|
|
593
|
+
assets?: string[];
|
|
590
594
|
/**
|
|
591
595
|
* When true interacting with it will be saved in history
|
|
592
596
|
*/
|
|
@@ -597,10 +601,8 @@ type CustomHandlerInfo = CustomHandlerCalling & {
|
|
|
597
601
|
skipClearOnGoingBack?: boolean;
|
|
598
602
|
/**
|
|
599
603
|
* Id by which we will determine what action is which
|
|
600
|
-
*
|
|
601
|
-
* It IS recommended to pass this property as it will speed up that check and make it more reliable
|
|
602
604
|
*/
|
|
603
|
-
id
|
|
605
|
+
id: string | symbol;
|
|
604
606
|
/**
|
|
605
607
|
* Key by which we will save the data in the `get` function provided to custom action.
|
|
606
608
|
*
|
|
@@ -714,7 +716,7 @@ type ActionProxy<Characters extends Record<string, Character>, Languages extends
|
|
|
714
716
|
jump: (scene: string) => ValidAction;
|
|
715
717
|
showCharacter: <C extends keyof Characters>(character: C, emotion?: keyof Characters[C]['emotions'], className?: string, style?: string) => ValidAction;
|
|
716
718
|
hideCharacter: (character: keyof Characters, className?: string, style?: string, duration?: number) => ValidAction;
|
|
717
|
-
animateCharacter: (character: keyof Characters,
|
|
719
|
+
animateCharacter: (character: keyof Characters, classes: string) => ValidAction;
|
|
718
720
|
wait: (time: number | ((state: State) => number)) => ValidAction;
|
|
719
721
|
function: (fn: FunctionAction<Languages, S>) => ValidAction;
|
|
720
722
|
input: (question: TextContent<Languages, S>, onInput: (meta: ActionInputOnInputMeta<Languages, S>) => void, setup?: ActionInputSetup) => ValidAction;
|
|
@@ -729,6 +731,8 @@ type DefaultActionProxy = ActionProxy<Record<string, Character>, Lang, State>;
|
|
|
729
731
|
type GetActionParameters<T extends Capitalize<keyof DefaultActionProxy>> = Parameters<DefaultActionProxy[Uncapitalize<T>]>;
|
|
730
732
|
|
|
731
733
|
type ConditionParams<T> = T extends TypeEssentials<any, infer $State, any, any> ? $State : never;
|
|
734
|
+
type ChoiceParams<T> = T extends TypeEssentials<infer $Lang, infer $State, any, any> ? ChoiceCheckFunctionProps<$Lang, $State> : never;
|
|
735
|
+
type FunctionParams<T> = T extends TypeEssentials<infer $Lang, infer $State, any, any> ? FunctionActionProps<$Lang, $State> : never;
|
|
732
736
|
type InputHandler<T> = T extends TypeEssentials<infer $Lang, infer $State, any, any> ? ActionInputOnInputMeta<$Lang, $State> : never;
|
|
733
737
|
|
|
734
738
|
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, defaultEmotions, storage, storageDelay, renderer: createRenderer, initialScreen, translation, state: defaultState, data: defaultData, autosaves, migrations, throttleTimeout, getLanguage, overrideLanguage, askBeforeExit, preloadAssets, parallelAssetsDownloadLimit, fetch: request, saveOnUnload, startKey }: NovelyInit<$Language, $Characters, $State, $Data, $Actions>) => {
|
|
@@ -819,6 +823,23 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
|
|
|
819
823
|
* ```
|
|
820
824
|
*/
|
|
821
825
|
getCurrentStorageData: () => StorageData<$Language, $Data> | null;
|
|
826
|
+
/**
|
|
827
|
+
* Function to set storage data. Using this function is not recommended.
|
|
828
|
+
*
|
|
829
|
+
* @deprecated
|
|
830
|
+
* @example
|
|
831
|
+
* ```ts
|
|
832
|
+
* const currentStorageData = engine.getCurrentStorageData();
|
|
833
|
+
*
|
|
834
|
+
* if (currentStorageData) {
|
|
835
|
+
* // update music volume
|
|
836
|
+
* currentStorageData.meta[2] = 1;
|
|
837
|
+
*
|
|
838
|
+
* setStorageData(currentStorageData)
|
|
839
|
+
* }
|
|
840
|
+
* ```
|
|
841
|
+
*/
|
|
842
|
+
setStorageData: (data: StorageData<$Language, $Data>) => void;
|
|
822
843
|
};
|
|
823
844
|
|
|
824
845
|
/**
|
|
@@ -836,4 +857,4 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
|
|
|
836
857
|
*/
|
|
837
858
|
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>>;
|
|
838
859
|
|
|
839
|
-
export { type ActionInputOnInputMeta, type ActionInputSetup, type ActionInputSetupCleanup, type ActionProxy, type AllowedContent, type AudioHandle, type BackgroundImage, type BaseTranslationStrings, type Character, type CharacterHandle, 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 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 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, extendAction, localStorageStorage, novely };
|
|
860
|
+
export { type ActionInputOnInputMeta, type ActionInputSetup, type ActionInputSetupCleanup, type ActionProxy, type AllowedContent, type AudioHandle, type BackgroundImage, type BaseTranslationStrings, type Character, type CharacterHandle, 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 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, extendAction, localStorageStorage, novely };
|
package/dist/index.global.js
CHANGED
|
@@ -1156,6 +1156,7 @@ var Novely = (() => {
|
|
|
1156
1156
|
const ASSETS_TO_PRELOAD = /* @__PURE__ */ new Set();
|
|
1157
1157
|
const dataLoaded = createControlledPromise();
|
|
1158
1158
|
let initialScreenWasShown = false;
|
|
1159
|
+
let destroyed = false;
|
|
1159
1160
|
const intime = (value) => {
|
|
1160
1161
|
return times.add(value), value;
|
|
1161
1162
|
};
|
|
@@ -1185,6 +1186,8 @@ var Novely = (() => {
|
|
|
1185
1186
|
}
|
|
1186
1187
|
};
|
|
1187
1188
|
const scriptBase = async (part) => {
|
|
1189
|
+
if (destroyed)
|
|
1190
|
+
return;
|
|
1188
1191
|
Object.assign(story, flattenStory(part));
|
|
1189
1192
|
let loadingIsShown = false;
|
|
1190
1193
|
if (!initialScreenWasShown) {
|
|
@@ -1223,9 +1226,11 @@ var Novely = (() => {
|
|
|
1223
1226
|
assetsToPreloadAdd(value);
|
|
1224
1227
|
}
|
|
1225
1228
|
}
|
|
1229
|
+
return;
|
|
1226
1230
|
}
|
|
1227
1231
|
if (isAudioAction(action2) && isString(props[0])) {
|
|
1228
1232
|
assetsToPreloadAdd(props[0]);
|
|
1233
|
+
return;
|
|
1229
1234
|
}
|
|
1230
1235
|
if (action2 === "showCharacter" && isString(props[0]) && isString(props[1])) {
|
|
1231
1236
|
const images = characters[props[0]].emotions[props[1]];
|
|
@@ -1236,6 +1241,12 @@ var Novely = (() => {
|
|
|
1236
1241
|
} else {
|
|
1237
1242
|
assetsToPreloadAdd(images);
|
|
1238
1243
|
}
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
if (action2 === "custom" && props[0].assets && props[0].assets.length > 0) {
|
|
1247
|
+
for (const asset of props[0].assets) {
|
|
1248
|
+
assetsToPreloadAdd(asset);
|
|
1249
|
+
}
|
|
1239
1250
|
}
|
|
1240
1251
|
};
|
|
1241
1252
|
const action = new Proxy({}, {
|
|
@@ -1616,17 +1627,21 @@ var Novely = (() => {
|
|
|
1616
1627
|
for (const [action3, ...props2] of collection) {
|
|
1617
1628
|
checkAndAddToPreloadingList(action3, props2);
|
|
1618
1629
|
}
|
|
1619
|
-
const { preloadAudioBlocking,
|
|
1630
|
+
const { preloadAudioBlocking, preloadImageBlocking } = renderer.misc;
|
|
1620
1631
|
ASSETS_TO_PRELOAD.forEach(async (asset) => {
|
|
1621
1632
|
ASSETS_TO_PRELOAD.delete(asset);
|
|
1622
1633
|
const type = await getResourseType(request, asset);
|
|
1623
1634
|
switch (type) {
|
|
1624
1635
|
case "audio": {
|
|
1625
|
-
preloadAudioBlocking(asset)
|
|
1636
|
+
preloadAudioBlocking(asset).then(() => {
|
|
1637
|
+
PRELOADED_ASSETS.add(asset);
|
|
1638
|
+
});
|
|
1626
1639
|
break;
|
|
1627
1640
|
}
|
|
1628
1641
|
case "image": {
|
|
1629
|
-
|
|
1642
|
+
preloadImageBlocking(asset).then(() => {
|
|
1643
|
+
PRELOADED_ASSETS.add(asset);
|
|
1644
|
+
});
|
|
1630
1645
|
break;
|
|
1631
1646
|
}
|
|
1632
1647
|
}
|
|
@@ -1875,16 +1890,14 @@ var Novely = (() => {
|
|
|
1875
1890
|
next({ push }) {
|
|
1876
1891
|
push();
|
|
1877
1892
|
},
|
|
1878
|
-
animateCharacter({ ctx, push }, [character,
|
|
1893
|
+
animateCharacter({ ctx, push }, [character, className]) {
|
|
1894
|
+
const classes = className.split(" ");
|
|
1879
1895
|
if (DEV && classes.length === 0) {
|
|
1880
1896
|
throw new Error("Attempt to use AnimateCharacter without classes. Classes should be provided [https://novely.pages.dev/guide/actions/animateCharacter.html]");
|
|
1881
1897
|
}
|
|
1882
|
-
if (DEV && (timeout <= 0 || !Number.isFinite(timeout) || Number.isNaN(timeout))) {
|
|
1883
|
-
throw new Error("Attempt to use AnimateCharacter with unacceptable timeout. It should be finite and greater than zero");
|
|
1884
|
-
}
|
|
1885
1898
|
if (ctx.meta.preview)
|
|
1886
1899
|
return;
|
|
1887
|
-
ctx.character(character).animate(
|
|
1900
|
+
ctx.character(character).animate(classes);
|
|
1888
1901
|
push();
|
|
1889
1902
|
},
|
|
1890
1903
|
text({ ctx, data: data2, forward }, text) {
|
|
@@ -1998,6 +2011,15 @@ var Novely = (() => {
|
|
|
1998
2011
|
const getCurrentStorageData = () => {
|
|
1999
2012
|
return coreData.get().dataLoaded ? klona(storageData.get()) : null;
|
|
2000
2013
|
};
|
|
2014
|
+
const setStorageData = (data2) => {
|
|
2015
|
+
if (destroyed) {
|
|
2016
|
+
if (DEV) {
|
|
2017
|
+
throw new Error(`function \`setStorageData\` was called after novely instance was destroyed.`);
|
|
2018
|
+
}
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
storageData.set(data2);
|
|
2022
|
+
};
|
|
2001
2023
|
return {
|
|
2002
2024
|
/**
|
|
2003
2025
|
* Function to set game script
|
|
@@ -2082,6 +2104,7 @@ var Novely = (() => {
|
|
|
2082
2104
|
dataLoaded.cancel();
|
|
2083
2105
|
UIInstance.unmount();
|
|
2084
2106
|
unsubscribeFromBrowserVisibilityChange();
|
|
2107
|
+
destroyed = true;
|
|
2085
2108
|
},
|
|
2086
2109
|
/**
|
|
2087
2110
|
* Funtion to get current storage data
|
|
@@ -2091,7 +2114,24 @@ var Novely = (() => {
|
|
|
2091
2114
|
* const currentStorageData = engine.getCurrentStorageData();
|
|
2092
2115
|
* ```
|
|
2093
2116
|
*/
|
|
2094
|
-
getCurrentStorageData
|
|
2117
|
+
getCurrentStorageData,
|
|
2118
|
+
/**
|
|
2119
|
+
* Function to set storage data. Using this function is not recommended.
|
|
2120
|
+
*
|
|
2121
|
+
* @deprecated
|
|
2122
|
+
* @example
|
|
2123
|
+
* ```ts
|
|
2124
|
+
* const currentStorageData = engine.getCurrentStorageData();
|
|
2125
|
+
*
|
|
2126
|
+
* if (currentStorageData) {
|
|
2127
|
+
* // update music volume
|
|
2128
|
+
* currentStorageData.meta[2] = 1;
|
|
2129
|
+
*
|
|
2130
|
+
* setStorageData(currentStorageData)
|
|
2131
|
+
* }
|
|
2132
|
+
* ```
|
|
2133
|
+
*/
|
|
2134
|
+
setStorageData
|
|
2095
2135
|
};
|
|
2096
2136
|
};
|
|
2097
2137
|
|