@novely/core 0.27.3 → 0.28.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
@@ -191,7 +191,7 @@ type RendererInit = {
191
191
  characters: Record<string, Character<Lang>>;
192
192
  set: (save: Save<State>) => Promise<void>;
193
193
  restore: (save?: Save<State>) => Promise<void>;
194
- save: (override?: boolean, type?: Save<State>[2][1]) => void;
194
+ save: (type: Save<State>[2][1]) => void;
195
195
  newGame: () => void;
196
196
  exit: (force?: boolean) => void;
197
197
  back: () => Promise<void>;
@@ -627,6 +627,38 @@ var Novely = (() => {
627
627
  return "other";
628
628
  };
629
629
 
630
+ // ../../node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/lite/index.mjs
631
+ var has = Object.prototype.hasOwnProperty;
632
+ function dequal(foo, bar) {
633
+ var ctor, len;
634
+ if (foo === bar)
635
+ return true;
636
+ if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
637
+ if (ctor === Date)
638
+ return foo.getTime() === bar.getTime();
639
+ if (ctor === RegExp)
640
+ return foo.toString() === bar.toString();
641
+ if (ctor === Array) {
642
+ if ((len = foo.length) === bar.length) {
643
+ while (len-- && dequal(foo[len], bar[len]))
644
+ ;
645
+ }
646
+ return len === -1;
647
+ }
648
+ if (!ctor || typeof foo === "object") {
649
+ len = 0;
650
+ for (ctor in foo) {
651
+ if (has.call(foo, ctor) && ++len && !has.call(bar, ctor))
652
+ return false;
653
+ if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor]))
654
+ return false;
655
+ }
656
+ return Object.keys(bar).length === len;
657
+ }
658
+ }
659
+ return foo !== foo && bar !== bar;
660
+ }
661
+
630
662
  // src/global.ts
631
663
  var PRELOADED_ASSETS = /* @__PURE__ */ new Set();
632
664
 
@@ -1010,7 +1042,7 @@ var Novely = (() => {
1010
1042
  };
1011
1043
  addEventListener("visibilitychange", onVisibilityChange);
1012
1044
  addEventListener("beforeunload", throttledEmergencyOnStorageDataChange);
1013
- const save = (override = false, type = override ? "auto" : "manual") => {
1045
+ const save = (type) => {
1014
1046
  if (!coreData.get().dataLoaded)
1015
1047
  return;
1016
1048
  if (!autosaves && type === "auto")
@@ -1018,20 +1050,32 @@ var Novely = (() => {
1018
1050
  const stack = useStack(MAIN_CONTEXT_KEY);
1019
1051
  const current = klona(stack.value);
1020
1052
  storageData.update((prev) => {
1021
- const isLatest = findLastIndex(prev.saves, (value) => times.has(value[2][0])) === prev.saves.length - 1;
1053
+ const replace2 = () => {
1054
+ prev.saves[prev.saves.length - 1] = current;
1055
+ return prev;
1056
+ };
1057
+ const add = () => {
1058
+ prev.saves.push(current);
1059
+ return prev;
1060
+ };
1061
+ const last = prev.saves.at(-1);
1062
+ if (!last)
1063
+ return add();
1064
+ if (!times.has(last[2][0]))
1065
+ return add();
1022
1066
  current[2][0] = intime(Date.now());
1023
1067
  current[2][1] = type;
1024
- if (!override || !isLatest) {
1025
- prev.saves.push(current);
1068
+ const isIdentical = dequal(last[0], current[0]) && dequal(last[1], current[1]);
1069
+ if (last[2][1] === "auto" && type === "manual") {
1070
+ return replace2();
1071
+ }
1072
+ if (last[2][1] === "manual" && type === "auto" && isIdentical) {
1026
1073
  return prev;
1027
1074
  }
1028
- const latest = prev.saves.at(-1);
1029
- if (latest && latest[2][1] === type) {
1030
- prev.saves[prev.saves.length - 1] = current;
1031
- } else {
1032
- prev.saves.push(current);
1075
+ if (last[2][1] === "auto" && type === "auto") {
1076
+ return replace2();
1033
1077
  }
1034
- return prev;
1078
+ return add();
1035
1079
  });
1036
1080
  };
1037
1081
  const newGame = () => {
@@ -1091,12 +1135,11 @@ var Novely = (() => {
1091
1135
  ctx: context,
1092
1136
  data: latest[1]
1093
1137
  });
1094
- const lastQueueItem = queue.at(-1) || [];
1095
- const isLastQueueItemRequiresUserAction = isUserRequiredAction(lastQueueItem);
1138
+ const lastQueueItem = queue.at(-1);
1096
1139
  await processor.run((item) => {
1097
1140
  if (!latest)
1098
1141
  return;
1099
- if (isLastQueueItemRequiresUserAction && lastQueueItem === item) {
1142
+ if (lastQueueItem === item) {
1100
1143
  return;
1101
1144
  }
1102
1145
  const [action2, ...props] = item;
@@ -1140,6 +1183,7 @@ var Novely = (() => {
1140
1183
  return;
1141
1184
  }
1142
1185
  const ctx = renderer.getContext(MAIN_CONTEXT_KEY);
1186
+ enmemory(ctx);
1143
1187
  const stack = useStack(ctx);
1144
1188
  const current = stack.value;
1145
1189
  stack.clear();
@@ -1232,7 +1276,7 @@ var Novely = (() => {
1232
1276
  const current = klona(stack.value);
1233
1277
  current[2][1] = "auto";
1234
1278
  stack.push(current);
1235
- save(true, "auto");
1279
+ save("auto");
1236
1280
  };
1237
1281
  const nextPath = (path) => {
1238
1282
  const last = path.at(-1);