From bd084e51c568a7c50d719e31547d49d764d92b50 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 3 Apr 2022 18:41:52 -0500 Subject: [PATCH] Fixed issue with dynamically loading layers --- src/game/persistence.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/game/persistence.ts b/src/game/persistence.ts index 006f1ca..6be595d 100644 --- a/src/game/persistence.ts +++ b/src/game/persistence.ts @@ -2,7 +2,7 @@ import { globalBus } from "game/events"; import Decimal, { DecimalSource } from "util/bignum"; import { ProxyState } from "util/proxies"; import { isArray } from "@vue/shared"; -import { isRef, Ref, ref } from "vue"; +import { isReactive, isRef, Ref, ref } from "vue"; import { GenericLayer } from "./layers"; export const PersistentState = Symbol("PersistentState"); @@ -70,12 +70,20 @@ globalBus.on("addLayer", (layer: GenericLayer, saveData: Record // Add ref to save data persistentState[key] = (value as Persistent)[PersistentState]; // Load previously saved value - if (savedValue != null) { - (persistentState[key] as Ref).value = savedValue; + if (isReactive(persistentState)) { + if (savedValue != null) { + persistentState[key] = savedValue; + } else { + persistentState[key] = (value as Persistent)[DefaultValue]; + } } else { - (persistentState[key] as Ref).value = (value as Persistent)[ - DefaultValue - ]; + if (savedValue != null) { + (persistentState[key] as Ref).value = savedValue; + } else { + (persistentState[key] as Ref).value = (value as Persistent)[ + DefaultValue + ]; + } } } else if ( !(value instanceof Decimal) &&