@novely/core 0.31.2 → 0.31.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.js CHANGED
@@ -862,6 +862,9 @@ var novely = ({
862
862
  let stored = await storage.get();
863
863
  for (const migration of migrations) {
864
864
  stored = migration(stored);
865
+ if (DEV2 && !stored) {
866
+ throw new Error("Migrations should return a value.");
867
+ }
865
868
  }
866
869
  if (overrideLanguage || !stored.meta[0]) {
867
870
  stored.meta[0] = getLanguageWithoutParameters();
@@ -1022,16 +1025,21 @@ var novely = ({
1022
1025
  return current;
1023
1026
  };
1024
1027
  const exit = (force = false, saving = true) => {
1025
- if (interacted > 1 && !force && askBeforeExit) {
1028
+ const ctx = renderer.getContext(MAIN_CONTEXT_KEY);
1029
+ const stack = useStack(ctx);
1030
+ const current = stack.value;
1031
+ const isSaved = () => {
1032
+ const { saves } = storageData.get();
1033
+ const [currentPath, currentData] = stack.value;
1034
+ return saves.some(([path, data2, [date, type2]]) => type2 === "manual" && times.has(date) && dequal(path, currentPath) && dequal(data2, currentData));
1035
+ };
1036
+ if (interacted > 1 && !force && askBeforeExit && !isSaved()) {
1026
1037
  renderer.ui.showExitPrompt();
1027
1038
  return;
1028
1039
  }
1029
- const ctx = renderer.getContext(MAIN_CONTEXT_KEY);
1030
1040
  if (interacted > 0 && saving) {
1031
1041
  save("auto");
1032
1042
  }
1033
- const stack = useStack(ctx);
1034
- const current = stack.value;
1035
1043
  stack.clear();
1036
1044
  ctx.clear(EMPTY_SET, EMPTY_SET, { music: EMPTY_SET, sounds: EMPTY_SET }, noop);
1037
1045
  renderer.ui.showScreen("mainmenu");
@@ -1529,6 +1537,9 @@ var novely = ({
1529
1537
  d: null,
1530
1538
  c: null
1531
1539
  };
1540
+ const getCurrentStorageData = () => {
1541
+ return coreData.get().dataLoaded ? klona(storageData.get()) : null;
1542
+ };
1532
1543
  return {
1533
1544
  /**
1534
1545
  * Function to set game script
@@ -1613,7 +1624,16 @@ var novely = ({
1613
1624
  dataLoaded.cancel();
1614
1625
  UIInstance.unmount();
1615
1626
  unsubscribeFromBrowserVisibilityChange();
1616
- }
1627
+ },
1628
+ /**
1629
+ * Funtion to get current storage data
1630
+ *
1631
+ * @example
1632
+ * ```ts
1633
+ * const currentStorageData = engine.getCurrentStorageData();
1634
+ * ```
1635
+ */
1636
+ getCurrentStorageData
1617
1637
  };
1618
1638
  };
1619
1639