Fix total resources increasing on load
This commit is contained in:
parent
36f064ebd7
commit
8e8c71224a
4 changed files with 16 additions and 1 deletions
|
@ -1,9 +1,12 @@
|
|||
import { globalBus } from "game/events";
|
||||
import { NonPersistent, Persistent, State } from "game/persistence";
|
||||
import { persistent } from "game/persistence";
|
||||
import player from "game/player";
|
||||
import settings from "game/settings";
|
||||
import type { DecimalSource } from "util/bignum";
|
||||
import Decimal, { format, formatWhole } from "util/bignum";
|
||||
import type { ProcessedComputable } from "util/computed";
|
||||
import { loadingSave } from "util/save";
|
||||
import type { ComputedRef, Ref } from "vue";
|
||||
import { computed, isRef, ref, unref, watch } from "vue";
|
||||
|
||||
|
@ -51,6 +54,9 @@ export function createResource<T extends State>(
|
|||
export function trackBest(resource: Resource): Ref<DecimalSource> {
|
||||
const best = persistent(resource.value);
|
||||
watch(resource, amount => {
|
||||
if (loadingSave.value) {
|
||||
return;
|
||||
}
|
||||
if (Decimal.gt(amount, best.value)) {
|
||||
best.value = amount;
|
||||
}
|
||||
|
@ -61,6 +67,9 @@ export function trackBest(resource: Resource): Ref<DecimalSource> {
|
|||
export function trackTotal(resource: Resource): Ref<DecimalSource> {
|
||||
const total = persistent(resource.value);
|
||||
watch(resource, (amount, prevAmount) => {
|
||||
if (loadingSave.value) {
|
||||
return;
|
||||
}
|
||||
if (Decimal.gt(amount, prevAmount)) {
|
||||
total.value = Decimal.add(total.value, Decimal.sub(amount, prevAmount));
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import projInfo from "data/projInfo.json";
|
|||
import { globalBus } from "game/events";
|
||||
import settings from "game/settings";
|
||||
import Decimal from "util/bignum";
|
||||
import { loadingSave } from "util/save";
|
||||
import type { Ref } from "vue";
|
||||
import { watch } from "vue";
|
||||
import player from "./player";
|
||||
|
@ -39,6 +40,8 @@ function update() {
|
|||
return;
|
||||
}
|
||||
|
||||
loadingSave.value = false;
|
||||
|
||||
// Add offline time if any
|
||||
if (player.offlineTime != undefined) {
|
||||
if (Decimal.gt(player.offlineTime, projInfo.offlineLimit * 3600)) {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { identifier } from "@babel/types";
|
||||
import { isArray } from "@vue/shared";
|
||||
import { globalBus } from "game/events";
|
||||
import type { GenericLayer } from "game/layers";
|
||||
|
|
|
@ -5,6 +5,7 @@ import player, { stringifySave } from "game/player";
|
|||
import settings, { loadSettings } from "game/settings";
|
||||
import LZString from "lz-string";
|
||||
import { ProxyState } from "util/proxies";
|
||||
import { ref } from "vue";
|
||||
|
||||
export function setupInitialStore(player: Partial<PlayerData> = {}): Player {
|
||||
return Object.assign(
|
||||
|
@ -88,8 +89,11 @@ export function getUniqueID(): string {
|
|||
return id;
|
||||
}
|
||||
|
||||
export const loadingSave = ref(false);
|
||||
|
||||
export async function loadSave(playerObj: Partial<PlayerData>): Promise<void> {
|
||||
console.info("Loading save", playerObj);
|
||||
loadingSave.value = true;
|
||||
const { layers, removeLayer, addLayer } = await import("game/layers");
|
||||
const { fixOldSave, getInitialLayers } = await import("data/projEntry");
|
||||
|
||||
|
|
Loading…
Reference in a new issue