Fix mastery issues

This commit is contained in:
thepaperpilot 2022-12-25 09:10:57 -06:00
parent 457a3ea1ac
commit 2628541bfe
5 changed files with 13 additions and 9 deletions

View file

@ -1333,7 +1333,7 @@ const layer = createLayer(id, function (this: BaseLayer) {
},
packingElf: {
buyProgress: persistent<DecimalSource>(0),
amountOftimesDone: persistent<number>(0),
amountOfTimesDone: persistent<number>(0),
bought: persistent<boolean>(false)
}
},

View file

@ -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<string, any>, layer: Record<string, any>) {
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]);

View file

@ -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<T extends LayerOptions>(
id: string,
optionsFunc: OptionsFunc<T, BaseLayer>
): Layer<T> {
): Layer<T> & { [ProxyState]: Layer<T> } {
return createLazyProxy(() => {
const layer = {} as T & Partial<BaseLayer>;
const emitter = (layer.emitter = createNanoEvents<LayerEvents>());

View file

@ -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[]) {

View file

@ -21,7 +21,7 @@ export type ProxiedWithState<T> = NonNullable<T> extends Record<PropertyKey, any
export function createLazyProxy<T extends object, S extends T>(
objectFunc: (baseObject: S) => T & S,
baseObject: S = {} as S
): T {
): T & { [ProxyState]: T } {
const obj: S & Partial<T> = baseObject;
let calculated = false;
function calculateObj(): T {
@ -66,5 +66,5 @@ export function createLazyProxy<T extends object, S extends T>(
}
return Object.getOwnPropertyDescriptor(target, key);
}
}) as S & T;
}) as S & T & { [ProxyState]: T };
}