Fix some persistence issues

This commit is contained in:
thepaperpilot 2023-05-13 17:09:32 -05:00
parent 10dbd88623
commit 2b660579a5
3 changed files with 16 additions and 2 deletions

View file

@ -160,6 +160,9 @@ export function createAchievement<T extends AchievementOptions>(
achievement.earned = earned;
achievement.complete = function () {
if (earned.value) {
return;
}
earned.value = true;
const genericAchievement = achievement as GenericAchievement;
genericAchievement.onComplete?.();

View file

@ -1,8 +1,9 @@
import type { OptionsFunc, Replace } from "features/feature";
import { getUniqueID } from "features/feature";
import { globalBus } from "game/events";
import Formula from "game/formulas/formulas";
import type { BaseLayer } from "game/layers";
import type { NonPersistent, Persistent } from "game/persistence";
import { NonPersistent, Persistent, SkipPersistence } from "game/persistence";
import { DefaultValue, persistent } from "game/persistence";
import type { Unsubscribe } from "nanoevents";
import Decimal from "util/bignum";
@ -61,7 +62,15 @@ export function createReset<T extends ResetOptions>(
reset.reset = function () {
const handleObject = (obj: unknown) => {
if (obj != null && typeof obj === "object") {
if (
obj != null &&
typeof obj === "object" &&
!(obj instanceof Decimal) &&
!(obj instanceof Formula)
) {
if (SkipPersistence in obj && obj[SkipPersistence] === true) {
return;
}
if (DefaultValue in obj) {
const persistent = obj as NonPersistent;
persistent.value = persistent[DefaultValue];

View file

@ -9,6 +9,7 @@ import type { Ref, WritableComputedRef } from "vue";
import { computed, isReactive, isRef, ref } from "vue";
import player from "./player";
import state from "./state";
import Formula from "./formulas/formulas";
/**
* A symbol used in {@link Persistent} objects.
@ -325,6 +326,7 @@ globalBus.on("addLayer", (layer: GenericLayer, saveData: Record<string, unknown>
}
} else if (
!(value instanceof Decimal) &&
!(value instanceof Formula) &&
!isRef(value) &&
// eslint-disable-next-line @typescript-eslint/no-explicit-any
!features.includes(value as { type: typeof Symbol })