From 23782e350063ee69eb93f7d4cca17e1f8a8721bc Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sat, 24 Dec 2022 09:53:50 -0600 Subject: [PATCH] Make buyables not spend readonly resources --- src/features/buyable.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/features/buyable.tsx b/src/features/buyable.tsx index c426274..7e5bb4a 100644 --- a/src/features/buyable.tsx +++ b/src/features/buyable.tsx @@ -21,7 +21,7 @@ import type { import { processComputable } from "util/computed"; import { createLazyProxy } from "util/proxies"; import { coerceComponent, isCoercableComponent } from "util/vue"; -import type { Ref } from "vue"; +import { isReadonly, Ref } from "vue"; import { computed, unref } from "vue"; export const BuyableType = Symbol("Buyable"); @@ -155,14 +155,18 @@ export function createBuyable( return; } const cost = unref(genericBuyable.cost); - if (genericBuyable.cost != null && genericBuyable.resource != null) { + if ( + genericBuyable.cost != null && + genericBuyable.resource != null && + !isReadonly(genericBuyable.resource) + ) { genericBuyable.resource.value = Decimal.sub( genericBuyable.resource.value, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion cost! ); - genericBuyable.amount.value = Decimal.add(genericBuyable.amount.value, 1); } + genericBuyable.amount.value = Decimal.add(genericBuyable.amount.value, 1); genericBuyable.onPurchase?.(cost); }; processComputable(buyable as T, "display");