@novely/core 0.25.0 → 0.27.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 +72 -63
- package/dist/index.global.js +34 -31
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +34 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -683,9 +683,8 @@ var novely = ({
|
|
|
683
683
|
const story = {};
|
|
684
684
|
const times = /* @__PURE__ */ new Set();
|
|
685
685
|
const ASSETS_TO_PRELOAD = /* @__PURE__ */ new Set();
|
|
686
|
-
const assetsLoaded = createControlledPromise();
|
|
687
686
|
const dataLoaded = createControlledPromise();
|
|
688
|
-
let
|
|
687
|
+
let initialScreenWasShown = false;
|
|
689
688
|
defaultData ||= {};
|
|
690
689
|
defaultState ||= {};
|
|
691
690
|
const intime = (value) => {
|
|
@@ -693,8 +692,15 @@ var novely = ({
|
|
|
693
692
|
};
|
|
694
693
|
const scriptBase = async (part) => {
|
|
695
694
|
Object.assign(story, flattenStory(part));
|
|
695
|
+
let loadingIsShown = false;
|
|
696
|
+
if (!initialScreenWasShown) {
|
|
697
|
+
renderer.ui.showLoading();
|
|
698
|
+
loadingIsShown = true;
|
|
699
|
+
}
|
|
696
700
|
if (preloadAssets === "blocking" && ASSETS_TO_PRELOAD.size > 0) {
|
|
697
|
-
|
|
701
|
+
if (!loadingIsShown) {
|
|
702
|
+
renderer.ui.showLoading();
|
|
703
|
+
}
|
|
698
704
|
const { preloadAudioBlocking, preloadImageBlocking } = renderer.misc;
|
|
699
705
|
const list = mapSet(ASSETS_TO_PRELOAD, (asset) => {
|
|
700
706
|
return limitAssetsDownload(async () => {
|
|
@@ -713,20 +719,17 @@ var novely = ({
|
|
|
713
719
|
});
|
|
714
720
|
await Promise.allSettled(list);
|
|
715
721
|
}
|
|
716
|
-
const screen = renderer.ui.getScreen();
|
|
717
|
-
const nextScreen = scriptCalled ? screen : initialScreen;
|
|
718
722
|
ASSETS_TO_PRELOAD.clear();
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
if (
|
|
723
|
+
await dataLoaded.promise;
|
|
724
|
+
renderer.ui.hideLoading();
|
|
725
|
+
if (!initialScreenWasShown) {
|
|
726
|
+
initialScreenWasShown = true;
|
|
727
|
+
if (initialScreen === "game") {
|
|
724
728
|
restore();
|
|
729
|
+
} else {
|
|
730
|
+
renderer.ui.showScreen(initialScreen);
|
|
725
731
|
}
|
|
726
|
-
} else {
|
|
727
|
-
renderer.ui.showScreen(nextScreen);
|
|
728
732
|
}
|
|
729
|
-
scriptCalled = true;
|
|
730
733
|
};
|
|
731
734
|
const script = (part) => {
|
|
732
735
|
return limitScript(() => scriptBase(part));
|
|
@@ -790,7 +793,7 @@ var novely = ({
|
|
|
790
793
|
data: klona(defaultData),
|
|
791
794
|
meta: [getLanguageWithoutParameters(), DEFAULT_TYPEWRITER_SPEED, 1, 1, 1]
|
|
792
795
|
};
|
|
793
|
-
const
|
|
796
|
+
const storageData = store(initialData);
|
|
794
797
|
const coreData = store({
|
|
795
798
|
dataLoaded: false
|
|
796
799
|
});
|
|
@@ -812,10 +815,10 @@ var novely = ({
|
|
|
812
815
|
const throttledOnStorageDataChange = throttle(onStorageDataChange, throttleTimeout);
|
|
813
816
|
const throttledEmergencyOnStorageDataChange = throttle(() => {
|
|
814
817
|
if (saveOnUnload === true || saveOnUnload === "prod" && !DEV2) {
|
|
815
|
-
onStorageDataChange(
|
|
818
|
+
onStorageDataChange(storageData.get());
|
|
816
819
|
}
|
|
817
820
|
}, 10);
|
|
818
|
-
|
|
821
|
+
storageData.subscribe(throttledOnStorageDataChange);
|
|
819
822
|
const getStoredData = async () => {
|
|
820
823
|
let stored = await storage.get();
|
|
821
824
|
for (const migration of migrations) {
|
|
@@ -832,7 +835,7 @@ var novely = ({
|
|
|
832
835
|
stored.data = defaultData;
|
|
833
836
|
}
|
|
834
837
|
dataLoaded.resolve();
|
|
835
|
-
|
|
838
|
+
storageData.set(stored);
|
|
836
839
|
};
|
|
837
840
|
storageDelay.then(getStoredData);
|
|
838
841
|
const initial = getDefaultSave(klona(defaultState));
|
|
@@ -850,7 +853,7 @@ var novely = ({
|
|
|
850
853
|
return;
|
|
851
854
|
const stack = useStack(MAIN_CONTEXT_KEY);
|
|
852
855
|
const current = klona(stack.value);
|
|
853
|
-
|
|
856
|
+
storageData.update((prev) => {
|
|
854
857
|
const isLatest = findLastIndex(prev.saves, (value) => times.has(value[2][0])) === prev.saves.length - 1;
|
|
855
858
|
current[2][0] = intime(Date.now());
|
|
856
859
|
current[2][1] = type;
|
|
@@ -872,7 +875,7 @@ var novely = ({
|
|
|
872
875
|
return;
|
|
873
876
|
const save2 = getDefaultSave(klona(defaultState));
|
|
874
877
|
if (autosaves) {
|
|
875
|
-
|
|
878
|
+
storageData.update((prev) => {
|
|
876
879
|
return prev.saves.push(save2), prev;
|
|
877
880
|
});
|
|
878
881
|
}
|
|
@@ -887,10 +890,10 @@ var novely = ({
|
|
|
887
890
|
const restore = async (save2) => {
|
|
888
891
|
if (!coreData.get().dataLoaded)
|
|
889
892
|
return;
|
|
890
|
-
let latest = save2 ||
|
|
893
|
+
let latest = save2 || storageData.get().saves.at(-1);
|
|
891
894
|
if (!latest) {
|
|
892
895
|
latest = klona(initial);
|
|
893
|
-
|
|
896
|
+
storageData.update((prev) => {
|
|
894
897
|
prev.saves.push(latest);
|
|
895
898
|
return prev;
|
|
896
899
|
});
|
|
@@ -974,7 +977,7 @@ var novely = ({
|
|
|
974
977
|
ctx.audio.destroy();
|
|
975
978
|
const [time, type] = current[2];
|
|
976
979
|
if (type === "auto" && interacted <= 1 && times.has(time)) {
|
|
977
|
-
|
|
980
|
+
storageData.update((prev) => {
|
|
978
981
|
prev.saves = prev.saves.filter((save2) => save2 !== current);
|
|
979
982
|
return prev;
|
|
980
983
|
});
|
|
@@ -1045,8 +1048,8 @@ var novely = ({
|
|
|
1045
1048
|
removeContext,
|
|
1046
1049
|
getStateFunction,
|
|
1047
1050
|
languages,
|
|
1048
|
-
|
|
1049
|
-
|
|
1051
|
+
storageData,
|
|
1052
|
+
coreData
|
|
1050
1053
|
});
|
|
1051
1054
|
const useStack = createUseStackFunction(renderer);
|
|
1052
1055
|
useStack(MAIN_CONTEXT_KEY).push(initial);
|
|
@@ -1140,7 +1143,7 @@ var novely = ({
|
|
|
1140
1143
|
const name = (() => {
|
|
1141
1144
|
const c = character;
|
|
1142
1145
|
const cs = characters;
|
|
1143
|
-
const [lang] =
|
|
1146
|
+
const [lang] = storageData.get().meta;
|
|
1144
1147
|
if (c && c in cs) {
|
|
1145
1148
|
const block = cs[c].name;
|
|
1146
1149
|
if (typeof block === "string") {
|
|
@@ -1172,7 +1175,7 @@ var novely = ({
|
|
|
1172
1175
|
function({ ctx, push }, [fn]) {
|
|
1173
1176
|
const { restoring, goingBack, preview: preview2 } = ctx.meta;
|
|
1174
1177
|
const result = fn({
|
|
1175
|
-
lang:
|
|
1178
|
+
lang: storageData.get().meta[0],
|
|
1176
1179
|
goingBack,
|
|
1177
1180
|
restoring,
|
|
1178
1181
|
preview: preview2,
|
|
@@ -1191,13 +1194,13 @@ var novely = ({
|
|
|
1191
1194
|
}
|
|
1192
1195
|
const transformedChoices = choices.map(([content, action2, visible]) => {
|
|
1193
1196
|
const shown = !visible || visible({
|
|
1194
|
-
lang:
|
|
1197
|
+
lang: storageData.get().meta[0],
|
|
1195
1198
|
state: getStateAtCtx(ctx)
|
|
1196
1199
|
});
|
|
1197
1200
|
if (DEV2 && action2.length === 0 && !shown) {
|
|
1198
1201
|
console.warn(`Choice children should not be empty, either add content there or make item not selectable`);
|
|
1199
1202
|
}
|
|
1200
|
-
return [templateReplace(content, data2),
|
|
1203
|
+
return [templateReplace(content, data2), shown];
|
|
1201
1204
|
});
|
|
1202
1205
|
if (DEV2 && transformedChoices.length === 0) {
|
|
1203
1206
|
throw new Error(`Running choice without variants to choose from, look at how to use Choice action properly [https://novely.pages.dev/guide/actions/choice#usage]`);
|
|
@@ -1404,7 +1407,7 @@ var novely = ({
|
|
|
1404
1407
|
const {
|
|
1405
1408
|
data: data2,
|
|
1406
1409
|
meta: [lang]
|
|
1407
|
-
} =
|
|
1410
|
+
} = storageData.get();
|
|
1408
1411
|
const obj = values || data2;
|
|
1409
1412
|
const cnt = isFunction(content) ? content(obj) : typeof content === "string" ? content : content[lang];
|
|
1410
1413
|
const str2 = flattenAllowedContent(
|
|
@@ -1422,11 +1425,11 @@ var novely = ({
|
|
|
1422
1425
|
);
|
|
1423
1426
|
};
|
|
1424
1427
|
const data = (value) => {
|
|
1425
|
-
const _data =
|
|
1428
|
+
const _data = storageData.get().data;
|
|
1426
1429
|
if (!value)
|
|
1427
1430
|
return _data;
|
|
1428
1431
|
const val = isFunction(value) ? value(_data) : deepmerge(_data, value);
|
|
1429
|
-
|
|
1432
|
+
storageData.update((prev) => {
|
|
1430
1433
|
prev.data = val;
|
|
1431
1434
|
return prev;
|
|
1432
1435
|
});
|