Add initialValue to Buyables

This commit is contained in:
thepaperpilot 2022-11-29 08:12:46 -06:00
parent 505bb2a4bc
commit 753ce5f8de

View file

@ -2,7 +2,7 @@ import ClickableComponent from "features/clickables/Clickable.vue";
import type { CoercableComponent, OptionsFunc, Replace, StyleValue } from "features/feature"; import type { CoercableComponent, OptionsFunc, Replace, StyleValue } from "features/feature";
import { Component, GatherProps, getUniqueID, jsx, setDefault, Visibility } from "features/feature"; import { Component, GatherProps, getUniqueID, jsx, setDefault, Visibility } from "features/feature";
import type { Resource } from "features/resources/resource"; import type { Resource } from "features/resources/resource";
import type { Persistent } from "game/persistence"; import { DefaultValue, Persistent } from "game/persistence";
import { persistent } from "game/persistence"; import { persistent } from "game/persistence";
import type { DecimalSource } from "util/bignum"; import type { DecimalSource } from "util/bignum";
import Decimal, { format, formatWhole } from "util/bignum"; import Decimal, { format, formatWhole } from "util/bignum";
@ -35,6 +35,7 @@ export interface BuyableOptions {
resource?: Resource; resource?: Resource;
canPurchase?: Computable<boolean>; canPurchase?: Computable<boolean>;
purchaseLimit?: Computable<DecimalSource>; purchaseLimit?: Computable<DecimalSource>;
initialValue?: DecimalSource;
classes?: Computable<Record<string, boolean>>; classes?: Computable<Record<string, boolean>>;
style?: Computable<StyleValue>; style?: Computable<StyleValue>;
mark?: Computable<boolean | string>; mark?: Computable<boolean | string>;
@ -101,6 +102,7 @@ export function createBuyable<T extends BuyableOptions>(
buyable[Component] = ClickableComponent; buyable[Component] = ClickableComponent;
buyable.amount = amount; buyable.amount = amount;
buyable.amount[DefaultValue] = buyable.initialValue ?? 0;
buyable.canAfford = computed(() => { buyable.canAfford = computed(() => {
const genericBuyable = buyable as GenericBuyable; const genericBuyable = buyable as GenericBuyable;
const cost = unref(genericBuyable.cost); const cost = unref(genericBuyable.cost);