From e32fac24260ae8bf9d1a7639d68f6da89a6682f1 Mon Sep 17 00:00:00 2001 From: Jacorb90 <39597610+Jacorb90@users.noreply.github.com> Date: Sat, 3 Dec 2022 21:29:06 -0500 Subject: [PATCH] TS shenanigans + coal/ash gain displays --- src/data/layers/coal.tsx | 37 +++++++++++++++++++++++++++++------- src/data/layers/workshop.tsx | 15 ++++++++++++--- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/data/layers/coal.tsx b/src/data/layers/coal.tsx index c2aa1c8..686ea3d 100644 --- a/src/data/layers/coal.tsx +++ b/src/data/layers/coal.tsx @@ -12,8 +12,8 @@ import { main } from "data/projEntry"; import { createBar } from "features/bars/bar"; import { createBuyable, GenericBuyable } from "features/buyable"; import { createClickable } from "features/clickables/clickable"; -import { jsx, showIf } from "features/feature"; -import { createResource, trackTotal } from "features/resources/resource"; +import { jsx, JSXFunction, showIf, StyleValue, Visibility } from "features/feature"; +import { createResource, Resource, trackTotal } from "features/resources/resource"; import { globalBus } from "game/events"; import { BaseLayer, createLayer } from "game/layers"; import { persistent } from "game/persistence"; @@ -23,10 +23,28 @@ import { render, renderRow } from "util/vue"; import { computed, ref, unref, watch, watchEffect } from "vue"; import trees from "./trees"; import { createAdditiveModifier, createExponentialModifier, createMultiplicativeModifier, createSequentialModifier } from "game/modifiers"; -import { createUpgrade } from "features/upgrades/upgrade"; +import { createUpgrade, Upgrade, UpgradeOptions } from "features/upgrades/upgrade"; import player from "game/player"; import elves from "./elves"; +interface BetterFertilizerUpgOptions { + canAfford: () => boolean, + onPurchase: VoidFunction, + display: JSXFunction, + style: StyleValue, + visibility: () => Visibility +} +interface UnlockKilnUpgOptions { + resource: Resource, + cost: DecimalSource, + display: { + title: string, + description: string + }, + style: StyleValue, + visibility: () => Visibility +} + const id = "coal"; const day = 3; const layer = createLayer(id, function (this: BaseLayer) { @@ -282,7 +300,7 @@ const layer = createLayer(id, function (this: BaseLayer) { style: { color: colorText }, visibility: () => showIf(unlockBonfire.bought.value) })); - const betterFertilizer = createUpgrade(() => ({ + const betterFertilizer: Upgrade = createUpgrade(() => ({ canAfford() { return Decimal.gte(trees.logs.value, 1e5) && Decimal.gte(ash.value, 1e5); @@ -301,7 +319,8 @@ const layer = createLayer(id, function (this: BaseLayer) { style: { color: colorText }, visibility: () => showIf(unlockBonfire.bought.value) })); - const unlockKiln = createUpgrade(() => ({ + + const unlockKiln: Upgrade = createUpgrade(() => ({ resource: trees.logs, cost: 1e7, display: { @@ -587,7 +606,9 @@ const layer = createLayer(id, function (this: BaseLayer) { color={colorCoal} style="margin-bottom: 0" effectDisplay={ - undefined + Decimal.gt(computedCoalGain.value, 0) + ? `+${format(computedCoalGain.value)}/s` + : undefined } /> @@ -596,7 +617,9 @@ const layer = createLayer(id, function (this: BaseLayer) { color={colorAsh} style="margin-bottom: 0" effectDisplay={ - undefined + Decimal.gt(computedAshGain.value, 0) + ? `+${format(computedAshGain.value)}/s` + : undefined } /> diff --git a/src/data/layers/workshop.tsx b/src/data/layers/workshop.tsx index 0d309d9..d0d6c6c 100644 --- a/src/data/layers/workshop.tsx +++ b/src/data/layers/workshop.tsx @@ -6,10 +6,10 @@ import Spacer from "components/layout/Spacer.vue"; import { main } from "data/projEntry"; import { createBar } from "features/bars/bar"; import { createClickable } from "features/clickables/clickable"; -import { createIndependentConversion, createPolynomialScaling } from "features/conversion"; +import { Conversion, ConversionOptions, createIndependentConversion, createPolynomialScaling, ScalingFunction } from "features/conversion"; import { jsx, showIf } from "features/feature"; import { createMilestone } from "features/milestones/milestone"; -import { createResource, displayResource } from "features/resources/resource"; +import { createResource, displayResource, Resource } from "features/resources/resource"; import { BaseLayer, createLayer } from "game/layers"; import player from "game/player"; import Decimal, { DecimalSource, formatWhole } from "util/bignum"; @@ -18,6 +18,15 @@ import { render, renderCol } from "util/vue"; import { unref, watchEffect } from "vue"; import trees from "./trees"; +interface FoundationConversionOptions { + scaling: ScalingFunction, + baseResource: Resource, + gainResource: Resource, + roundUpCost: boolean, + buyMax: boolean, + spend: (gain: DecimalSource, spent: DecimalSource) => void +} + const id = "workshop"; const day = 2; const layer = createLayer(id, function (this: BaseLayer) { @@ -27,7 +36,7 @@ const layer = createLayer(id, function (this: BaseLayer) { const foundationProgress = createResource(0, "foundation progress"); - const foundationConversion = createIndependentConversion(() => ({ + const foundationConversion: Conversion = createIndependentConversion(() => ({ scaling: createPolynomialScaling(250, 1.5), baseResource: trees.logs, gainResource: foundationProgress,