From 5fa2e521b2d64371cab80a3c6bebe7236fb61298 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Tue, 6 Dec 2022 07:09:21 -0600 Subject: [PATCH] Fixed resets --- src/features/reset.ts | 11 +++++------ src/game/persistence.ts | 6 ++++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/features/reset.ts b/src/features/reset.ts index eaa3631..0b8153a 100644 --- a/src/features/reset.ts +++ b/src/features/reset.ts @@ -2,14 +2,14 @@ import type { OptionsFunc, Replace } from "features/feature"; import { getUniqueID } from "features/feature"; import { globalBus } from "game/events"; import type { BaseLayer } from "game/layers"; -import type { Persistent } from "game/persistence"; +import type { Persistent, State } from "game/persistence"; import { DefaultValue, persistent, PersistentState } from "game/persistence"; import type { Unsubscribe } from "nanoevents"; import Decimal from "util/bignum"; import type { Computable, GetComputableType } from "util/computed"; import { processComputable } from "util/computed"; import { createLazyProxy } from "util/proxies"; -import { isRef, unref } from "vue"; +import { isRef, unref, WritableComputedRef } from "vue"; export const ResetType = Symbol("Reset"); @@ -44,10 +44,9 @@ export function createReset( reset.reset = function () { const handleObject = (obj: unknown) => { if (obj && typeof obj === "object") { - if (PersistentState in obj) { - (obj as Persistent)[PersistentState].value = (obj as Persistent)[ - DefaultValue - ]; + if (DefaultValue in obj) { + const persistent = obj as WritableComputedRef & { [DefaultValue]: T }; + persistent.value = persistent[DefaultValue]; } else if (!(obj instanceof Decimal) && !isRef(obj)) { Object.values(obj).forEach(obj => handleObject(obj as Record) diff --git a/src/game/persistence.ts b/src/game/persistence.ts index b063e2c..795a130 100644 --- a/src/game/persistence.ts +++ b/src/game/persistence.ts @@ -71,7 +71,7 @@ export type Persistent = Ref & { /** * A non-persistent ref that just reads and writes ot the persistent ref. Used for passing to other features without duplicating the persistent ref in the constructed save data object. */ - [NonPersistent]: WritableComputedRef; + [NonPersistent]: WritableComputedRef & { [DefaultValue]: T }; /** * The path this persistent appears in within the save data object. Predominantly used to ensure it's only placed in there one time. */ @@ -102,7 +102,7 @@ export function persistent(defaultValue: T | Ref): Persisten persistent[DefaultValue] = isRef(defaultValue) ? defaultValue.value : defaultValue; persistent[StackTrace] = getStackTrace(); persistent[Deleted] = false; - persistent[NonPersistent] = computed({ + const nonPersistent: WritableComputedRef & Partial<{ [DefaultValue]: T }> = computed({ get() { return persistent.value; }, @@ -110,6 +110,8 @@ export function persistent(defaultValue: T | Ref): Persisten persistent.value = value; } }); + nonPersistent[DefaultValue] = persistent[DefaultValue]; + persistent[NonPersistent] = nonPersistent as WritableComputedRef & { [DefaultValue]: T }; persistent[SaveDataPath] = undefined; if (addingLayers.length === 0) {