narrat 2.0.3 → 2.0.4

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/narrat.es.js CHANGED
@@ -34291,7 +34291,6 @@ ws.exports.parseJSONPointer;
34291
34291
  ws.exports.revertJSONPatch;
34292
34292
  ws.exports.setIn;
34293
34293
  ws.exports.updateIn;
34294
- const SAVE_FILE = "gameSave";
34295
34294
  const defaultConfig = {
34296
34295
  gameTitle: "Narrat Game Example",
34297
34296
  images: {
@@ -36780,16 +36779,24 @@ async function changeMusic(newMusic) {
36780
36779
  }, audioOptions.musicFadeOutTime * 1e3);
36781
36780
  }
36782
36781
  }
36782
+ let sound;
36783
+ let newId;
36784
+ if (newMusic) {
36785
+ sound = getAudio(newMusic);
36786
+ if (!sound) {
36787
+ throw new Error(`Could not find music ${newMusic}`);
36788
+ }
36789
+ sound.volume(0);
36790
+ newId = sound.play();
36791
+ sound.pause();
36792
+ audio2.setMusic(newMusic, newId);
36793
+ }
36783
36794
  if (audio2.currentMusic) {
36784
36795
  await timeout(audioOptions.musicFadeInDelay * 1e3);
36785
36796
  }
36786
- if (newMusic) {
36787
- const sound = getAudio(newMusic);
36788
- if (sound) {
36789
- const newId = sound.play();
36790
- sound.fade(0, 1, audioOptions.musicFadeInTime * 1e3, newId);
36791
- audio2.setMusic(newMusic, newId);
36792
- }
36797
+ if (sound && useAudio().musicHowlId === newId) {
36798
+ sound.play();
36799
+ sound.fade(0, 1, audioOptions.musicFadeInTime * 1e3, newId);
36793
36800
  }
36794
36801
  }
36795
36802
  function playAudio(key) {
@@ -36805,9 +36812,13 @@ function getAudio(key) {
36805
36812
  return audio[key];
36806
36813
  }
36807
36814
  function stopAudio(key) {
36808
- const sound = getAudio(key);
36809
- if (sound) {
36810
- sound.stop();
36815
+ if (key === useAudio().currentMusic) {
36816
+ useAudio().stopMusic();
36817
+ } else {
36818
+ const sound = getAudio(key);
36819
+ if (sound) {
36820
+ sound.stop();
36821
+ }
36811
36822
  }
36812
36823
  }
36813
36824
  function pauseAudio(key) {
@@ -36816,6 +36827,10 @@ function pauseAudio(key) {
36816
36827
  sound.pause();
36817
36828
  }
36818
36829
  }
36830
+ const SAVE_FILE = "gameSave";
36831
+ function saveGame(object) {
36832
+ localStorage.setItem(SAVE_FILE, JSON.stringify(object));
36833
+ }
36819
36834
  function randomId() {
36820
36835
  return `${Date.now() - Math.floor(Math.random() * 99999999)}`;
36821
36836
  }
@@ -38327,7 +38342,7 @@ const useMain = defineStore("main", {
38327
38342
  inventory: inventoryStore.generateSaveData(),
38328
38343
  quests: useQuests().generateSaveData()
38329
38344
  };
38330
- localStorage.setItem(SAVE_FILE, JSON.stringify(save));
38345
+ saveGame(save);
38331
38346
  },
38332
38347
  setLoadedData(save) {
38333
38348
  const screensStore = useScreens();
@@ -40790,7 +40805,7 @@ const stopCommand = new CommandPlugin("stop", playCommandArgs, async (cmd) => {
40790
40805
  if (stopOptions.mode === "music") {
40791
40806
  const audioStore = useAudio();
40792
40807
  if (audioStore.currentMusic) {
40793
- stopAudio(audioStore.currentMusic);
40808
+ useAudio().stopMusic();
40794
40809
  }
40795
40810
  } else if (stopOptions.mode === "sound" && stopOptions.audio) {
40796
40811
  stopAudio(stopOptions.audio);