diff --git a/src/data/layers/elves.tsx b/src/data/layers/elves.tsx index fd3330d..b0ebe72 100644 --- a/src/data/layers/elves.tsx +++ b/src/data/layers/elves.tsx @@ -1333,7 +1333,7 @@ const layer = createLayer(id, function (this: BaseLayer) { }, packingElf: { buyProgress: persistent(0), - amountOftimesDone: persistent(0), + amountOfTimesDone: persistent(0), bought: persistent(false) } }, diff --git a/src/data/projEntry.tsx b/src/data/projEntry.tsx index 1906342..77fa994 100644 --- a/src/data/projEntry.tsx +++ b/src/data/projEntry.tsx @@ -14,10 +14,10 @@ import type { PlayerData } from "game/player"; import player from "game/player"; import { format, formatTime } from "util/bignum"; import { Computable, convertComputable, ProcessedComputable } from "util/computed"; -import { createLazyProxy } from "util/proxies"; +import { createLazyProxy, ProxyState } from "util/proxies"; import { save } from "util/save"; import { render, renderRow, VueFeature } from "util/vue"; -import { computed, Ref, ref, unref, watchEffect } from "vue"; +import { computed, isReadonly, isRef, Ref, ref, unref, watchEffect } from "vue"; import "./advent.css"; import { credits } from "./credits"; import Day from "./Day.vue"; @@ -209,7 +209,7 @@ export const main = createLayer("main", function (this: BaseLayer) { management, letters ]) { - swapMastery(layer.mastery, layer); + swapMastery(layer.mastery, layer[ProxyState]); } swappingMastery.value = false; @@ -217,6 +217,10 @@ export const main = createLayer("main", function (this: BaseLayer) { function swapMastery(mastery: Record, layer: Record) { for (const key of Object.keys(mastery)) { if (isPersistent(mastery[key])) { + if (!isRef(layer[key]) || isReadonly(layer[key])) { + console.error("Something went wrong swapping state", key, layer, mastery); + continue; + } [mastery[key].value, layer[key].value] = [layer[key].value, mastery[key].value]; } else { swapMastery(mastery[key], layer[key]); diff --git a/src/game/layers.tsx b/src/game/layers.tsx index c689235..dbaf40e 100644 --- a/src/game/layers.tsx +++ b/src/game/layers.tsx @@ -20,7 +20,7 @@ import type { ProcessedComputable } from "util/computed"; import { processComputable } from "util/computed"; -import { createLazyProxy } from "util/proxies"; +import { createLazyProxy, ProxyState } from "util/proxies"; import { computed, InjectionKey, Ref } from "vue"; import { ref, shallowReactive, unref } from "vue"; @@ -206,7 +206,7 @@ export const addingLayers: string[] = []; export function createLayer( id: string, optionsFunc: OptionsFunc -): Layer { +): Layer & { [ProxyState]: Layer } { return createLazyProxy(() => { const layer = {} as T & Partial; const emitter = (layer.emitter = createNanoEvents()); diff --git a/src/util/break_eternity.ts b/src/util/break_eternity.ts index a8d83e3..fc76d62 100644 --- a/src/util/break_eternity.ts +++ b/src/util/break_eternity.ts @@ -217,7 +217,7 @@ export function formatGain(gain: DecimalSource) { [-1]: `${format(gain)}/s`, 0: "", 1: `+${format(gain)}/s` - }[Decimal.compare(gain, 0)]; + }[Decimal.compare_tolerance(gain, 0, 0.001)]; } export function formatList(list: string[]) { diff --git a/src/util/proxies.ts b/src/util/proxies.ts index 9dad138..19c827c 100644 --- a/src/util/proxies.ts +++ b/src/util/proxies.ts @@ -21,7 +21,7 @@ export type ProxiedWithState = NonNullable extends Record( objectFunc: (baseObject: S) => T & S, baseObject: S = {} as S -): T { +): T & { [ProxyState]: T } { const obj: S & Partial = baseObject; let calculated = false; function calculateObj(): T { @@ -66,5 +66,5 @@ export function createLazyProxy( } return Object.getOwnPropertyDescriptor(target, key); } - }) as S & T; + }) as S & T & { [ProxyState]: T }; }