@novely/core 0.36.0-beta.2 → 0.36.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.js CHANGED
@@ -965,6 +965,7 @@ var novely = ({
965
965
  const ASSETS_TO_PRELOAD = /* @__PURE__ */ new Set();
966
966
  const dataLoaded = createControlledPromise();
967
967
  let initialScreenWasShown = false;
968
+ let destroyed = false;
968
969
  const intime = (value) => {
969
970
  return times.add(value), value;
970
971
  };
@@ -994,6 +995,8 @@ var novely = ({
994
995
  }
995
996
  };
996
997
  const scriptBase = async (part) => {
998
+ if (destroyed)
999
+ return;
997
1000
  Object.assign(story, flattenStory(part));
998
1001
  let loadingIsShown = false;
999
1002
  if (!initialScreenWasShown) {
@@ -1032,9 +1035,11 @@ var novely = ({
1032
1035
  assetsToPreloadAdd(value);
1033
1036
  }
1034
1037
  }
1038
+ return;
1035
1039
  }
1036
1040
  if (isAudioAction(action2) && isString(props[0])) {
1037
1041
  assetsToPreloadAdd(props[0]);
1042
+ return;
1038
1043
  }
1039
1044
  if (action2 === "showCharacter" && isString(props[0]) && isString(props[1])) {
1040
1045
  const images = characters[props[0]].emotions[props[1]];
@@ -1045,6 +1050,12 @@ var novely = ({
1045
1050
  } else {
1046
1051
  assetsToPreloadAdd(images);
1047
1052
  }
1053
+ return;
1054
+ }
1055
+ if (action2 === "custom" && props[0].assets && props[0].assets.length > 0) {
1056
+ for (const asset of props[0].assets) {
1057
+ assetsToPreloadAdd(asset);
1058
+ }
1048
1059
  }
1049
1060
  };
1050
1061
  const action = new Proxy({}, {
@@ -1688,16 +1699,14 @@ var novely = ({
1688
1699
  next({ push }) {
1689
1700
  push();
1690
1701
  },
1691
- animateCharacter({ ctx, push }, [character, timeout, ...classes]) {
1702
+ animateCharacter({ ctx, push }, [character, className]) {
1703
+ const classes = className.split(" ");
1692
1704
  if (DEV2 && classes.length === 0) {
1693
1705
  throw new Error("Attempt to use AnimateCharacter without classes. Classes should be provided [https://novely.pages.dev/guide/actions/animateCharacter.html]");
1694
1706
  }
1695
- if (DEV2 && (timeout <= 0 || !Number.isFinite(timeout) || Number.isNaN(timeout))) {
1696
- throw new Error("Attempt to use AnimateCharacter with unacceptable timeout. It should be finite and greater than zero");
1697
- }
1698
1707
  if (ctx.meta.preview)
1699
1708
  return;
1700
- ctx.character(character).animate(timeout, classes);
1709
+ ctx.character(character).animate(classes);
1701
1710
  push();
1702
1711
  },
1703
1712
  text({ ctx, data: data2, forward }, text) {
@@ -1811,6 +1820,15 @@ var novely = ({
1811
1820
  const getCurrentStorageData = () => {
1812
1821
  return coreData.get().dataLoaded ? klona(storageData.get()) : null;
1813
1822
  };
1823
+ const setStorageData = (data2) => {
1824
+ if (destroyed) {
1825
+ if (DEV2) {
1826
+ throw new Error(`function \`setStorageData\` was called after novely instance was destroyed.`);
1827
+ }
1828
+ return;
1829
+ }
1830
+ storageData.set(data2);
1831
+ };
1814
1832
  return {
1815
1833
  /**
1816
1834
  * Function to set game script
@@ -1895,6 +1913,7 @@ var novely = ({
1895
1913
  dataLoaded.cancel();
1896
1914
  UIInstance.unmount();
1897
1915
  unsubscribeFromBrowserVisibilityChange();
1916
+ destroyed = true;
1898
1917
  },
1899
1918
  /**
1900
1919
  * Funtion to get current storage data
@@ -1904,7 +1923,24 @@ var novely = ({
1904
1923
  * const currentStorageData = engine.getCurrentStorageData();
1905
1924
  * ```
1906
1925
  */
1907
- getCurrentStorageData
1926
+ getCurrentStorageData,
1927
+ /**
1928
+ * Function to set storage data. Using this function is not recommended.
1929
+ *
1930
+ * @deprecated
1931
+ * @example
1932
+ * ```ts
1933
+ * const currentStorageData = engine.getCurrentStorageData();
1934
+ *
1935
+ * if (currentStorageData) {
1936
+ * // update music volume
1937
+ * currentStorageData.meta[2] = 1;
1938
+ *
1939
+ * setStorageData(currentStorageData)
1940
+ * }
1941
+ * ```
1942
+ */
1943
+ setStorageData
1908
1944
  };
1909
1945
  };
1910
1946