mirror of
https://github.com/thepaperpilot/Advent-Incremental.git
synced 2024-11-21 16:13:57 +00:00
Fix mastery issues
This commit is contained in:
parent
457a3ea1ac
commit
2628541bfe
5 changed files with 13 additions and 9 deletions
|
@ -1333,7 +1333,7 @@ const layer = createLayer(id, function (this: BaseLayer) {
|
||||||
},
|
},
|
||||||
packingElf: {
|
packingElf: {
|
||||||
buyProgress: persistent<DecimalSource>(0),
|
buyProgress: persistent<DecimalSource>(0),
|
||||||
amountOftimesDone: persistent<number>(0),
|
amountOfTimesDone: persistent<number>(0),
|
||||||
bought: persistent<boolean>(false)
|
bought: persistent<boolean>(false)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,10 +14,10 @@ import type { PlayerData } from "game/player";
|
||||||
import player from "game/player";
|
import player from "game/player";
|
||||||
import { format, formatTime } from "util/bignum";
|
import { format, formatTime } from "util/bignum";
|
||||||
import { Computable, convertComputable, ProcessedComputable } from "util/computed";
|
import { Computable, convertComputable, ProcessedComputable } from "util/computed";
|
||||||
import { createLazyProxy } from "util/proxies";
|
import { createLazyProxy, ProxyState } from "util/proxies";
|
||||||
import { save } from "util/save";
|
import { save } from "util/save";
|
||||||
import { render, renderRow, VueFeature } from "util/vue";
|
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 "./advent.css";
|
||||||
import { credits } from "./credits";
|
import { credits } from "./credits";
|
||||||
import Day from "./Day.vue";
|
import Day from "./Day.vue";
|
||||||
|
@ -209,7 +209,7 @@ export const main = createLayer("main", function (this: BaseLayer) {
|
||||||
management,
|
management,
|
||||||
letters
|
letters
|
||||||
]) {
|
]) {
|
||||||
swapMastery(layer.mastery, layer);
|
swapMastery(layer.mastery, layer[ProxyState]);
|
||||||
}
|
}
|
||||||
|
|
||||||
swappingMastery.value = false;
|
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>) {
|
function swapMastery(mastery: Record<string, any>, layer: Record<string, any>) {
|
||||||
for (const key of Object.keys(mastery)) {
|
for (const key of Object.keys(mastery)) {
|
||||||
if (isPersistent(mastery[key])) {
|
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];
|
[mastery[key].value, layer[key].value] = [layer[key].value, mastery[key].value];
|
||||||
} else {
|
} else {
|
||||||
swapMastery(mastery[key], layer[key]);
|
swapMastery(mastery[key], layer[key]);
|
||||||
|
|
|
@ -20,7 +20,7 @@ import type {
|
||||||
ProcessedComputable
|
ProcessedComputable
|
||||||
} from "util/computed";
|
} from "util/computed";
|
||||||
import { processComputable } 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 { computed, InjectionKey, Ref } from "vue";
|
||||||
import { ref, shallowReactive, unref } from "vue";
|
import { ref, shallowReactive, unref } from "vue";
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ export const addingLayers: string[] = [];
|
||||||
export function createLayer<T extends LayerOptions>(
|
export function createLayer<T extends LayerOptions>(
|
||||||
id: string,
|
id: string,
|
||||||
optionsFunc: OptionsFunc<T, BaseLayer>
|
optionsFunc: OptionsFunc<T, BaseLayer>
|
||||||
): Layer<T> {
|
): Layer<T> & { [ProxyState]: Layer<T> } {
|
||||||
return createLazyProxy(() => {
|
return createLazyProxy(() => {
|
||||||
const layer = {} as T & Partial<BaseLayer>;
|
const layer = {} as T & Partial<BaseLayer>;
|
||||||
const emitter = (layer.emitter = createNanoEvents<LayerEvents>());
|
const emitter = (layer.emitter = createNanoEvents<LayerEvents>());
|
||||||
|
|
|
@ -217,7 +217,7 @@ export function formatGain(gain: DecimalSource) {
|
||||||
[-1]: `${format(gain)}/s`,
|
[-1]: `${format(gain)}/s`,
|
||||||
0: "",
|
0: "",
|
||||||
1: `+${format(gain)}/s`
|
1: `+${format(gain)}/s`
|
||||||
}[Decimal.compare(gain, 0)];
|
}[Decimal.compare_tolerance(gain, 0, 0.001)];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatList(list: string[]) {
|
export function formatList(list: string[]) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ export type ProxiedWithState<T> = NonNullable<T> extends Record<PropertyKey, any
|
||||||
export function createLazyProxy<T extends object, S extends T>(
|
export function createLazyProxy<T extends object, S extends T>(
|
||||||
objectFunc: (baseObject: S) => T & S,
|
objectFunc: (baseObject: S) => T & S,
|
||||||
baseObject: S = {} as S
|
baseObject: S = {} as S
|
||||||
): T {
|
): T & { [ProxyState]: T } {
|
||||||
const obj: S & Partial<T> = baseObject;
|
const obj: S & Partial<T> = baseObject;
|
||||||
let calculated = false;
|
let calculated = false;
|
||||||
function calculateObj(): T {
|
function calculateObj(): T {
|
||||||
|
@ -66,5 +66,5 @@ export function createLazyProxy<T extends object, S extends T>(
|
||||||
}
|
}
|
||||||
return Object.getOwnPropertyDescriptor(target, key);
|
return Object.getOwnPropertyDescriptor(target, key);
|
||||||
}
|
}
|
||||||
}) as S & T;
|
}) as S & T & { [ProxyState]: T };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue