mirror of
https://github.com/thepaperpilot/Advent-Incremental.git
synced 2025-01-19 12:01:37 +00:00
Pass amount of resources to spend to conversion.spend
This commit is contained in:
parent
5f8d052c9f
commit
abd8572f71
1 changed files with 9 additions and 5 deletions
|
@ -66,7 +66,7 @@ export interface ConversionOptions {
|
||||||
* The function that spends the {@link baseResource} as part of the conversion.
|
* The function that spends the {@link baseResource} as part of the conversion.
|
||||||
* Defaults to setting the {@link baseResource} amount to 0.
|
* 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.
|
* A callback that happens after a conversion has been completed.
|
||||||
* Receives the amount gained via conversion.
|
* Receives the amount gained via conversion.
|
||||||
|
@ -108,7 +108,9 @@ export type Conversion<T extends ConversionOptions> = Replace<
|
||||||
currentAt: GetComputableTypeWithDefault<T["currentAt"], Ref<DecimalSource>>;
|
currentAt: GetComputableTypeWithDefault<T["currentAt"], Ref<DecimalSource>>;
|
||||||
nextAt: GetComputableTypeWithDefault<T["nextAt"], Ref<DecimalSource>>;
|
nextAt: GetComputableTypeWithDefault<T["nextAt"], Ref<DecimalSource>>;
|
||||||
buyMax: GetComputableTypeWithDefault<T["buyMax"], true>;
|
buyMax: GetComputableTypeWithDefault<T["buyMax"], true>;
|
||||||
spend: undefined extends T["spend"] ? (amountGained: DecimalSource) => void : T["spend"];
|
spend: undefined extends T["spend"]
|
||||||
|
? (amountGained: DecimalSource, amountSpent: DecimalSource) => void
|
||||||
|
: T["spend"];
|
||||||
roundUpCost: GetComputableTypeWithDefault<T["roundUpCost"], true>;
|
roundUpCost: GetComputableTypeWithDefault<T["roundUpCost"], true>;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
@ -122,7 +124,7 @@ export type GenericConversion = Replace<
|
||||||
currentAt: ProcessedComputable<DecimalSource>;
|
currentAt: ProcessedComputable<DecimalSource>;
|
||||||
nextAt: ProcessedComputable<DecimalSource>;
|
nextAt: ProcessedComputable<DecimalSource>;
|
||||||
buyMax: ProcessedComputable<boolean>;
|
buyMax: ProcessedComputable<boolean>;
|
||||||
spend: (amountGained: DecimalSource) => void;
|
spend: (amountGained: DecimalSource, amountSpent: DecimalSource) => void;
|
||||||
roundUpCost: ProcessedComputable<boolean>;
|
roundUpCost: ProcessedComputable<boolean>;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
@ -176,11 +178,12 @@ export function createConversion<T extends ConversionOptions>(
|
||||||
if (conversion.convert == null) {
|
if (conversion.convert == null) {
|
||||||
conversion.convert = function () {
|
conversion.convert = function () {
|
||||||
const amountGained = unref((conversion as GenericConversion).currentGain);
|
const amountGained = unref((conversion as GenericConversion).currentGain);
|
||||||
|
const amountSpent = unref((conversion as GenericConversion).currentAt);
|
||||||
conversion.gainResource.value = Decimal.add(
|
conversion.gainResource.value = Decimal.add(
|
||||||
conversion.gainResource.value,
|
conversion.gainResource.value,
|
||||||
amountGained
|
amountGained
|
||||||
);
|
);
|
||||||
(conversion as GenericConversion).spend(amountGained);
|
(conversion as GenericConversion).spend(amountGained, amountSpent);
|
||||||
conversion.onConvert?.(amountGained);
|
conversion.onConvert?.(amountGained);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -423,12 +426,13 @@ export function createIndependentConversion<S extends ConversionOptions>(
|
||||||
}
|
}
|
||||||
setDefault(conversion, "convert", function () {
|
setDefault(conversion, "convert", function () {
|
||||||
const amountGained = unref((conversion as GenericConversion).actualGain);
|
const amountGained = unref((conversion as GenericConversion).actualGain);
|
||||||
|
const amountSpent = unref((conversion as GenericConversion).currentAt);
|
||||||
conversion.gainResource.value = conversion.gainModifier
|
conversion.gainResource.value = conversion.gainModifier
|
||||||
? conversion.gainModifier.apply(
|
? conversion.gainModifier.apply(
|
||||||
unref((conversion as GenericConversion).currentGain)
|
unref((conversion as GenericConversion).currentGain)
|
||||||
)
|
)
|
||||||
: unref((conversion as GenericConversion).currentGain);
|
: unref((conversion as GenericConversion).currentGain);
|
||||||
(conversion as GenericConversion).spend(amountGained);
|
(conversion as GenericConversion).spend(amountGained, amountSpent);
|
||||||
conversion.onConvert?.(amountGained);
|
conversion.onConvert?.(amountGained);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue