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>
|
<b>
|
||||||
{displayResource(
|
{displayResource(
|
||||||
resetButton.conversion.gainResource,
|
resetButton.conversion.gainResource,
|
||||||
unref(resetButton.conversion.currentGain)
|
unref(resetButton.conversion.actualGain)
|
||||||
)}
|
)}
|
||||||
</b>{" "}
|
</b>{" "}
|
||||||
{resetButton.conversion.gainResource.displayName}
|
{resetButton.conversion.gainResource.displayName}
|
||||||
|
@ -99,7 +99,7 @@ export function createResetButton<T extends ClickableOptions & ResetButtonOption
|
||||||
|
|
||||||
if (resetButton.canClick == null) {
|
if (resetButton.canClick == null) {
|
||||||
resetButton.canClick = computed(() =>
|
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 {
|
export interface ConversionOptions {
|
||||||
scaling: ScalingFunction;
|
scaling: ScalingFunction;
|
||||||
currentGain?: Computable<DecimalSource>;
|
currentGain?: Computable<DecimalSource>;
|
||||||
|
actualGain?: Computable<DecimalSource>;
|
||||||
|
currentAt?: Computable<DecimalSource>;
|
||||||
nextAt?: Computable<DecimalSource>;
|
nextAt?: Computable<DecimalSource>;
|
||||||
baseResource: Resource;
|
baseResource: Resource;
|
||||||
gainResource: Resource;
|
gainResource: Resource;
|
||||||
|
@ -34,6 +36,8 @@ export type Conversion<T extends ConversionOptions> = Replace<
|
||||||
T & BaseConversion,
|
T & BaseConversion,
|
||||||
{
|
{
|
||||||
currentGain: GetComputableTypeWithDefault<T["currentGain"], Ref<DecimalSource>>;
|
currentGain: GetComputableTypeWithDefault<T["currentGain"], Ref<DecimalSource>>;
|
||||||
|
actualGain: GetComputableTypeWithDefault<T["actualGain"], 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>;
|
||||||
roundUpCost: GetComputableTypeWithDefault<T["roundUpCost"], true>;
|
roundUpCost: GetComputableTypeWithDefault<T["roundUpCost"], true>;
|
||||||
|
@ -44,6 +48,8 @@ export type GenericConversion = Replace<
|
||||||
Conversion<ConversionOptions>,
|
Conversion<ConversionOptions>,
|
||||||
{
|
{
|
||||||
currentGain: ProcessedComputable<DecimalSource>;
|
currentGain: ProcessedComputable<DecimalSource>;
|
||||||
|
actualGain: ProcessedComputable<DecimalSource>;
|
||||||
|
currentAt: ProcessedComputable<DecimalSource>;
|
||||||
nextAt: ProcessedComputable<DecimalSource>;
|
nextAt: ProcessedComputable<DecimalSource>;
|
||||||
buyMax: ProcessedComputable<boolean>;
|
buyMax: ProcessedComputable<boolean>;
|
||||||
roundUpCost: ProcessedComputable<boolean>;
|
roundUpCost: ProcessedComputable<boolean>;
|
||||||
|
@ -76,6 +82,16 @@ export function createConversion<T extends ConversionOptions>(
|
||||||
return gain;
|
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) {
|
if (conversion.nextAt == null) {
|
||||||
conversion.nextAt = computed(() => {
|
conversion.nextAt = computed(() => {
|
||||||
let next = conversion.scaling.nextAt(conversion as GenericConversion);
|
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, "currentGain");
|
||||||
|
processComputable(conversion as T, "actualGain");
|
||||||
|
processComputable(conversion as T, "currentAt");
|
||||||
processComputable(conversion as T, "nextAt");
|
processComputable(conversion as T, "nextAt");
|
||||||
processComputable(conversion as T, "buyMax");
|
processComputable(conversion as T, "buyMax");
|
||||||
setDefault(conversion, "buyMax", true);
|
setDefault(conversion, "buyMax", true);
|
||||||
|
@ -108,6 +126,7 @@ export function createConversion<T extends ConversionOptions>(
|
||||||
|
|
||||||
export type ScalingFunction = {
|
export type ScalingFunction = {
|
||||||
currentGain: (conversion: GenericConversion) => DecimalSource;
|
currentGain: (conversion: GenericConversion) => DecimalSource;
|
||||||
|
currentAt: (conversion: GenericConversion) => DecimalSource;
|
||||||
nextAt: (conversion: GenericConversion) => DecimalSource;
|
nextAt: (conversion: GenericConversion) => DecimalSource;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -128,6 +147,13 @@ export function createLinearScaling(
|
||||||
.times(unref(coefficient))
|
.times(unref(coefficient))
|
||||||
.add(1);
|
.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) {
|
nextAt(conversion) {
|
||||||
let next: DecimalSource = Decimal.add(unref(conversion.currentGain), 1);
|
let next: DecimalSource = Decimal.add(unref(conversion.currentGain), 1);
|
||||||
if (conversion.gainModifier) {
|
if (conversion.gainModifier) {
|
||||||
|
@ -155,6 +181,13 @@ export function createPolynomialScaling(
|
||||||
}
|
}
|
||||||
return gain;
|
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) {
|
nextAt(conversion) {
|
||||||
let next: DecimalSource = Decimal.add(unref(conversion.currentGain), 1);
|
let next: DecimalSource = Decimal.add(unref(conversion.currentGain), 1);
|
||||||
if (conversion.gainModifier) {
|
if (conversion.gainModifier) {
|
||||||
|
@ -179,14 +212,12 @@ export function createIndependentConversion<S extends ConversionOptions>(
|
||||||
|
|
||||||
setDefault(conversion, "buyMax", false);
|
setDefault(conversion, "buyMax", false);
|
||||||
|
|
||||||
if (conversion.currentGain == null) {
|
if (conversion.actualGain == null) {
|
||||||
conversion.currentGain = computed(() =>
|
conversion.actualGain = computed(() =>
|
||||||
Decimal.sub(
|
Decimal.sub(
|
||||||
conversion.scaling.currentGain(conversion as GenericConversion),
|
conversion.scaling.currentGain(conversion as GenericConversion),
|
||||||
conversion.gainResource.value
|
conversion.gainResource.value
|
||||||
)
|
).max(0)
|
||||||
.add(1)
|
|
||||||
.max(1)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
setDefault(conversion, "convert", function () {
|
setDefault(conversion, "convert", function () {
|
||||||
|
|
Loading…
Reference in a new issue