forked from profectus/Profectus
Merge pull request #4 from murapix/main
Fix independent gain, add current cost
This commit is contained in:
commit
d09126e84c
2 changed files with 38 additions and 7 deletions
|
@ -80,7 +80,7 @@ export function createResetButton<T extends ClickableOptions & ResetButtonOption
|
|||
<b>
|
||||
{displayResource(
|
||||
resetButton.conversion.gainResource,
|
||||
unref(resetButton.conversion.currentGain)
|
||||
unref(resetButton.conversion.actualGain)
|
||||
)}
|
||||
</b>{" "}
|
||||
{resetButton.conversion.gainResource.displayName}
|
||||
|
@ -99,7 +99,7 @@ export function createResetButton<T extends ClickableOptions & ResetButtonOption
|
|||
|
||||
if (resetButton.canClick == null) {
|
||||
resetButton.canClick = computed(() =>
|
||||
Decimal.gt(unref(resetButton.conversion.currentGain), 0)
|
||||
Decimal.gt(unref(resetButton.conversion.actualGain), 0)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ import { Resource } from "./resources/resource";
|
|||
export interface ConversionOptions {
|
||||
scaling: ScalingFunction;
|
||||
currentGain?: Computable<DecimalSource>;
|
||||
actualGain?: Computable<DecimalSource>;
|
||||
currentAt?: Computable<DecimalSource>;
|
||||
nextAt?: Computable<DecimalSource>;
|
||||
baseResource: Resource;
|
||||
gainResource: Resource;
|
||||
|
@ -34,6 +36,8 @@ export type Conversion<T extends ConversionOptions> = Replace<
|
|||
T & BaseConversion,
|
||||
{
|
||||
currentGain: GetComputableTypeWithDefault<T["currentGain"], Ref<DecimalSource>>;
|
||||
actualGain: GetComputableTypeWithDefault<T["actualGain"], Ref<DecimalSource>>;
|
||||
currentAt: GetComputableTypeWithDefault<T["currentAt"], Ref<DecimalSource>>;
|
||||
nextAt: GetComputableTypeWithDefault<T["nextAt"], Ref<DecimalSource>>;
|
||||
buyMax: GetComputableTypeWithDefault<T["buyMax"], true>;
|
||||
roundUpCost: GetComputableTypeWithDefault<T["roundUpCost"], true>;
|
||||
|
@ -44,6 +48,8 @@ export type GenericConversion = Replace<
|
|||
Conversion<ConversionOptions>,
|
||||
{
|
||||
currentGain: ProcessedComputable<DecimalSource>;
|
||||
actualGain: ProcessedComputable<DecimalSource>;
|
||||
currentAt: ProcessedComputable<DecimalSource>;
|
||||
nextAt: ProcessedComputable<DecimalSource>;
|
||||
buyMax: ProcessedComputable<boolean>;
|
||||
roundUpCost: ProcessedComputable<boolean>;
|
||||
|
@ -76,6 +82,16 @@ export function createConversion<T extends ConversionOptions>(
|
|||
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<T extends ConversionOptions>(
|
|||
}
|
||||
|
||||
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<T extends ConversionOptions>(
|
|||
|
||||
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<S extends ConversionOptions>(
|
|||
|
||||
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 () {
|
||||
|
|
Loading…
Reference in a new issue