diff --git a/src/features/conversion.ts b/src/features/conversion.ts index d2a47d0..91636c1 100644 --- a/src/features/conversion.ts +++ b/src/features/conversion.ts @@ -66,7 +66,7 @@ export interface ConversionOptions { * The function that spends the {@link baseResource} as part of the conversion. * Defaults to setting the {@link baseResource} amount to 0. */ - spend?: (amountGained: DecimalSource) => void; + spend?: (amountGained: DecimalSource, amountSpent: DecimalSource) => void; /** * A callback that happens after a conversion has been completed. * Receives the amount gained via conversion. @@ -108,7 +108,9 @@ export type Conversion = Replace< currentAt: GetComputableTypeWithDefault>; nextAt: GetComputableTypeWithDefault>; buyMax: GetComputableTypeWithDefault; - spend: undefined extends T["spend"] ? (amountGained: DecimalSource) => void : T["spend"]; + spend: undefined extends T["spend"] + ? (amountGained: DecimalSource, amountSpent: DecimalSource) => void + : T["spend"]; roundUpCost: GetComputableTypeWithDefault; } >; @@ -122,7 +124,7 @@ export type GenericConversion = Replace< currentAt: ProcessedComputable; nextAt: ProcessedComputable; buyMax: ProcessedComputable; - spend: (amountGained: DecimalSource) => void; + spend: (amountGained: DecimalSource, amountSpent: DecimalSource) => void; roundUpCost: ProcessedComputable; } >; @@ -176,11 +178,12 @@ export function createConversion( if (conversion.convert == null) { conversion.convert = function () { const amountGained = unref((conversion as GenericConversion).currentGain); + const amountSpent = unref((conversion as GenericConversion).currentAt); conversion.gainResource.value = Decimal.add( conversion.gainResource.value, amountGained ); - (conversion as GenericConversion).spend(amountGained); + (conversion as GenericConversion).spend(amountGained, amountSpent); conversion.onConvert?.(amountGained); }; } @@ -423,12 +426,13 @@ export function createIndependentConversion( } setDefault(conversion, "convert", function () { const amountGained = unref((conversion as GenericConversion).actualGain); + const amountSpent = unref((conversion as GenericConversion).currentAt); conversion.gainResource.value = conversion.gainModifier ? conversion.gainModifier.apply( unref((conversion as GenericConversion).currentGain) ) : unref((conversion as GenericConversion).currentGain); - (conversion as GenericConversion).spend(amountGained); + (conversion as GenericConversion).spend(amountGained, amountSpent); conversion.onConvert?.(amountGained); });