From 0991ef08651caa041d2463e1f0dddd42cbc877be Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sat, 13 May 2023 17:09:32 -0500 Subject: [PATCH] Fix some persistence issues --- src/features/achievements/achievement.tsx | 3 +++ src/features/reset.ts | 13 +++++++++++-- src/game/persistence.ts | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/features/achievements/achievement.tsx b/src/features/achievements/achievement.tsx index 007dd0c..9bf454f 100644 --- a/src/features/achievements/achievement.tsx +++ b/src/features/achievements/achievement.tsx @@ -160,6 +160,9 @@ export function createAchievement( achievement.earned = earned; achievement.complete = function () { + if (earned.value) { + return; + } earned.value = true; const genericAchievement = achievement as GenericAchievement; genericAchievement.onComplete?.(); diff --git a/src/features/reset.ts b/src/features/reset.ts index 2811ba8..2b31e64 100644 --- a/src/features/reset.ts +++ b/src/features/reset.ts @@ -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( 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]; diff --git a/src/game/persistence.ts b/src/game/persistence.ts index 712f989..a61d9cf 100644 --- a/src/game/persistence.ts +++ b/src/game/persistence.ts @@ -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 } } 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 })