diff --git a/src/data/common.tsx b/src/data/common.tsx index 81f0e94..5fd5547 100644 --- a/src/data/common.tsx +++ b/src/data/common.tsx @@ -80,7 +80,7 @@ export function createResetButton {displayResource( resetButton.conversion.gainResource, - unref(resetButton.conversion.currentGain) + unref(resetButton.conversion.actualGain) )} {" "} {resetButton.conversion.gainResource.displayName} @@ -99,7 +99,7 @@ export function createResetButton - Decimal.gt(unref(resetButton.conversion.currentGain), 0) + Decimal.gt(unref(resetButton.conversion.actualGain), 0) ); } diff --git a/src/features/conversion.ts b/src/features/conversion.ts index 849d66d..4fdc88c 100644 --- a/src/features/conversion.ts +++ b/src/features/conversion.ts @@ -17,6 +17,8 @@ import { Resource } from "./resources/resource"; export interface ConversionOptions { scaling: ScalingFunction; currentGain?: Computable; + actualGain?: Computable; + currentAt?: Computable; nextAt?: Computable; baseResource: Resource; gainResource: Resource; @@ -34,6 +36,8 @@ export type Conversion = Replace< T & BaseConversion, { currentGain: GetComputableTypeWithDefault>; + actualGain: GetComputableTypeWithDefault>; + currentAt: GetComputableTypeWithDefault>; nextAt: GetComputableTypeWithDefault>; buyMax: GetComputableTypeWithDefault; roundUpCost: GetComputableTypeWithDefault; @@ -44,6 +48,8 @@ export type GenericConversion = Replace< Conversion, { currentGain: ProcessedComputable; + actualGain: ProcessedComputable; + currentAt: ProcessedComputable; nextAt: ProcessedComputable; buyMax: ProcessedComputable; roundUpCost: ProcessedComputable; @@ -76,6 +82,16 @@ export function createConversion( return gain; }); } + if (conversion.actualGain == null) { + conversion.actualGain = conversion.currentGain; + } + if (conversion.currentAt == null) { + conversion.currentAt = computed(() => { + let current = conversion.scaling.currentAt(conversion as GenericConversion); + if (conversion.roundUpCost) current = Decimal.ceil(current); + return current; + }); + } if (conversion.nextAt == null) { conversion.nextAt = computed(() => { let next = conversion.scaling.nextAt(conversion as GenericConversion); @@ -96,6 +112,8 @@ export function createConversion( } processComputable(conversion as T, "currentGain"); + processComputable(conversion as T, "actualGain"); + processComputable(conversion as T, "currentAt"); processComputable(conversion as T, "nextAt"); processComputable(conversion as T, "buyMax"); setDefault(conversion, "buyMax", true); @@ -108,6 +126,7 @@ export function createConversion( export type ScalingFunction = { currentGain: (conversion: GenericConversion) => DecimalSource; + currentAt: (conversion: GenericConversion) => DecimalSource; nextAt: (conversion: GenericConversion) => DecimalSource; }; @@ -128,6 +147,13 @@ export function createLinearScaling( .times(unref(coefficient)) .add(1); }, + currentAt(conversion) { + let current: DecimalSource = unref(conversion.currentGain); + if (conversion.gainModifier) { + current = conversion.gainModifier.revert(current); + } + return Decimal.times(current, unref(coefficient)).add(unref(base)); + }, nextAt(conversion) { let next: DecimalSource = Decimal.add(unref(conversion.currentGain), 1); if (conversion.gainModifier) { @@ -155,6 +181,13 @@ export function createPolynomialScaling( } return gain; }, + currentAt(conversion) { + let current: DecimalSource = unref(conversion.currentGain); + if (conversion.gainModifier) { + current = conversion.gainModifier.revert(current); + } + return Decimal.root(current, unref(exponent)).times(unref(base)); + }, nextAt(conversion) { let next: DecimalSource = Decimal.add(unref(conversion.currentGain), 1); if (conversion.gainModifier) { @@ -179,14 +212,12 @@ export function createIndependentConversion( setDefault(conversion, "buyMax", false); - if (conversion.currentGain == null) { - conversion.currentGain = computed(() => + if (conversion.actualGain == null) { + conversion.actualGain = computed(() => Decimal.sub( conversion.scaling.currentGain(conversion as GenericConversion), conversion.gainResource.value - ) - .add(1) - .max(1) + ).max(0) ); } setDefault(conversion, "convert", function () {