@novely/core 0.26.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 CHANGED
@@ -160,6 +160,16 @@ type Renderer = {
160
160
  * Returns current screen
161
161
  */
162
162
  getScreen(): NovelyScreen | (string & Record<never, never>);
163
+ /**
164
+ * Shows loading
165
+ *
166
+ * Unline `showScreen('loading')` does not change screen
167
+ */
168
+ showLoading(): void;
169
+ /**
170
+ * Hides loading
171
+ */
172
+ hideLoading(): void;
163
173
  /**
164
174
  * Shows prompt to exit
165
175
  */
@@ -245,7 +255,7 @@ type Stack = {
245
255
  push(value: Save): void;
246
256
  clear(): void;
247
257
  };
248
- type NovelyScreen = 'mainmenu' | 'game' | 'saves' | 'settings' | 'loading';
258
+ type NovelyScreen = 'mainmenu' | 'game' | 'saves' | 'settings';
249
259
  /**
250
260
  * @see https://pendletonjones.com/deep-partial
251
261
  */
@@ -846,9 +846,8 @@ var Novely = (() => {
846
846
  const story = {};
847
847
  const times = /* @__PURE__ */ new Set();
848
848
  const ASSETS_TO_PRELOAD = /* @__PURE__ */ new Set();
849
- const assetsLoaded = createControlledPromise();
850
849
  const dataLoaded = createControlledPromise();
851
- let scriptCalled = false;
850
+ let initialScreenWasShown = false;
852
851
  defaultData ||= {};
853
852
  defaultState ||= {};
854
853
  const intime = (value) => {
@@ -856,8 +855,15 @@ var Novely = (() => {
856
855
  };
857
856
  const scriptBase = async (part) => {
858
857
  Object.assign(story, flattenStory(part));
858
+ let loadingIsShown = false;
859
+ if (!initialScreenWasShown) {
860
+ renderer.ui.showLoading();
861
+ loadingIsShown = true;
862
+ }
859
863
  if (preloadAssets === "blocking" && ASSETS_TO_PRELOAD.size > 0) {
860
- renderer.ui.showScreen("loading");
864
+ if (!loadingIsShown) {
865
+ renderer.ui.showLoading();
866
+ }
861
867
  const { preloadAudioBlocking, preloadImageBlocking } = renderer.misc;
862
868
  const list = mapSet(ASSETS_TO_PRELOAD, (asset) => {
863
869
  return limitAssetsDownload(async () => {
@@ -876,20 +882,17 @@ var Novely = (() => {
876
882
  });
877
883
  await Promise.allSettled(list);
878
884
  }
879
- const screen = renderer.ui.getScreen();
880
- const nextScreen = scriptCalled ? screen : initialScreen;
881
885
  ASSETS_TO_PRELOAD.clear();
882
- assetsLoaded.resolve();
883
- if (nextScreen === "game") {
884
- await assetsLoaded.promise;
885
- await dataLoaded.promise;
886
- if (!scriptCalled) {
886
+ await dataLoaded.promise;
887
+ renderer.ui.hideLoading();
888
+ if (!initialScreenWasShown) {
889
+ initialScreenWasShown = true;
890
+ if (initialScreen === "game") {
887
891
  restore();
892
+ } else {
893
+ renderer.ui.showScreen(initialScreen);
888
894
  }
889
- } else {
890
- renderer.ui.showScreen(nextScreen);
891
895
  }
892
- scriptCalled = true;
893
896
  };
894
897
  const script = (part) => {
895
898
  return limitScript(() => scriptBase(part));