Fixed issue with dynamically loading layers

This commit is contained in:
thepaperpilot 2022-04-03 18:41:52 -05:00
parent d09126e84c
commit bd084e51c5

View file

@ -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,6 +70,13 @@ globalBus.on("addLayer", (layer: GenericLayer, saveData: Record<string, unknown>
// Add ref to save data
persistentState[key] = (value as Persistent)[PersistentState];
// Load previously saved value
if (isReactive(persistentState)) {
if (savedValue != null) {
persistentState[key] = savedValue;
} else {
persistentState[key] = (value as Persistent)[DefaultValue];
}
} else {
if (savedValue != null) {
(persistentState[key] as Ref<unknown>).value = savedValue;
} else {
@ -77,6 +84,7 @@ globalBus.on("addLayer", (layer: GenericLayer, saveData: Record<string, unknown>
DefaultValue
];
}
}
} else if (
!(value instanceof Decimal) &&
!isRef(value) &&