@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.d.ts CHANGED
@@ -718,6 +718,15 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
718
718
  * Data updates still will work in case Novely already was loaded
719
719
  */
720
720
  destroy(): void;
721
+ /**
722
+ * Funtion to get current storage data
723
+ *
724
+ * @example
725
+ * ```ts
726
+ * const currentStorageData = engine.getCurrentStorageData();
727
+ * ```
728
+ */
729
+ getCurrentStorageData: () => StorageData<$Language, $Data> | null;
721
730
  };
722
731
 
723
732
  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 };
@@ -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
- if (interacted > 1 && !force && askBeforeExit) {
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");
@@ -1721,6 +1729,9 @@ var Novely = (() => {
1721
1729
  d: null,
1722
1730
  c: null
1723
1731
  };
1732
+ const getCurrentStorageData = () => {
1733
+ return coreData.get().dataLoaded ? klona(storageData.get()) : null;
1734
+ };
1724
1735
  return {
1725
1736
  /**
1726
1737
  * Function to set game script
@@ -1805,7 +1816,16 @@ var Novely = (() => {
1805
1816
  dataLoaded.cancel();
1806
1817
  UIInstance.unmount();
1807
1818
  unsubscribeFromBrowserVisibilityChange();
1808
- }
1819
+ },
1820
+ /**
1821
+ * Funtion to get current storage data
1822
+ *
1823
+ * @example
1824
+ * ```ts
1825
+ * const currentStorageData = engine.getCurrentStorageData();
1826
+ * ```
1827
+ */
1828
+ getCurrentStorageData
1809
1829
  };
1810
1830
  };
1811
1831