Merge pull request 'Fix reset button using currentAt when not yet gaining' (#25) from sethposner/profectus-template:main into main

Reviewed-on: #25
This commit is contained in:
thepaperpilot 2023-11-13 22:29:49 +00:00
commit ffc42a5745
2 changed files with 34 additions and 2 deletions

View file

@ -134,8 +134,8 @@ export function createResetButton<T extends ClickableOptions & ResetButtonOption
{unref(resetButton.conversion.buyMax) ? "Next:" : "Req:"}{" "} {unref(resetButton.conversion.buyMax) ? "Next:" : "Req:"}{" "}
{displayResource( {displayResource(
resetButton.conversion.baseResource, resetButton.conversion.baseResource,
!unref(resetButton.conversion.buyMax) || !unref(resetButton.conversion.buyMax) &&
Decimal.lt(unref(resetButton.conversion.actualGain), 1) Decimal.gte(unref(resetButton.conversion.actualGain), 1)
? unref(resetButton.conversion.currentAt) ? unref(resetButton.conversion.currentAt)
: unref(resetButton.conversion.nextAt) : unref(resetButton.conversion.nextAt)
)}{" "} )}{" "}

View file

@ -47,6 +47,10 @@ describe("Creating conversion", () => {
baseResource.value = Decimal.pow(100, 2).times(10).add(1); baseResource.value = Decimal.pow(100, 2).times(10).add(1);
expect(unref(conversion.currentGain)).compare_tolerance(100); expect(unref(conversion.currentGain)).compare_tolerance(100);
}); });
test("Zero", () => {
baseResource.value = Decimal.dZero;
expect(unref(conversion.currentGain)).compare_tolerance(0);
});
}); });
describe("Calculates actualGain correctly", () => { describe("Calculates actualGain correctly", () => {
let conversion: GenericConversion; let conversion: GenericConversion;
@ -69,6 +73,10 @@ describe("Creating conversion", () => {
baseResource.value = Decimal.pow(100, 2).times(10).add(1); baseResource.value = Decimal.pow(100, 2).times(10).add(1);
expect(unref(conversion.actualGain)).compare_tolerance(100); expect(unref(conversion.actualGain)).compare_tolerance(100);
}); });
test("Zero", () => {
baseResource.value = Decimal.dZero;
expect(unref(conversion.actualGain)).compare_tolerance(0);
});
}); });
describe("Calculates currentAt correctly", () => { describe("Calculates currentAt correctly", () => {
let conversion: GenericConversion; let conversion: GenericConversion;
@ -95,6 +103,10 @@ describe("Creating conversion", () => {
Decimal.pow(100, 2).times(10) Decimal.pow(100, 2).times(10)
); );
}); });
test("Zero", () => {
baseResource.value = Decimal.dZero;
expect(unref(conversion.currentAt)).compare_tolerance(0);
});
}); });
describe("Calculates nextAt correctly", () => { describe("Calculates nextAt correctly", () => {
let conversion: GenericConversion; let conversion: GenericConversion;
@ -117,6 +129,10 @@ describe("Creating conversion", () => {
baseResource.value = Decimal.pow(100, 2).times(10).add(1); baseResource.value = Decimal.pow(100, 2).times(10).add(1);
expect(unref(conversion.nextAt)).compare_tolerance(Decimal.pow(101, 2).times(10)); expect(unref(conversion.nextAt)).compare_tolerance(Decimal.pow(101, 2).times(10));
}); });
test("Zero", () => {
baseResource.value = Decimal.dZero;
expect(unref(conversion.nextAt)).compare_tolerance(Decimal.dTen);
});
}); });
test("Converts correctly", () => { test("Converts correctly", () => {
const conversion = createCumulativeConversion(() => ({ const conversion = createCumulativeConversion(() => ({
@ -193,6 +209,10 @@ describe("Creating conversion", () => {
baseResource.value = Decimal.pow(100, 2).times(10).add(1); baseResource.value = Decimal.pow(100, 2).times(10).add(1);
expect(unref(conversion.currentGain)).compare_tolerance(100); expect(unref(conversion.currentGain)).compare_tolerance(100);
}); });
test("Zero", () => {
baseResource.value = Decimal.dZero;
expect(unref(conversion.currentGain)).compare_tolerance(1);
});
}); });
describe("Calculates actualGain correctly", () => { describe("Calculates actualGain correctly", () => {
let conversion: GenericConversion; let conversion: GenericConversion;
@ -216,6 +236,10 @@ describe("Creating conversion", () => {
baseResource.value = Decimal.pow(100, 2).times(10).add(1); baseResource.value = Decimal.pow(100, 2).times(10).add(1);
expect(unref(conversion.actualGain)).compare_tolerance(99); expect(unref(conversion.actualGain)).compare_tolerance(99);
}); });
test("Zero", () => {
baseResource.value = Decimal.dZero;
expect(unref(conversion.actualGain)).compare_tolerance(0);
});
}); });
describe("Calculates currentAt correctly", () => { describe("Calculates currentAt correctly", () => {
let conversion: GenericConversion; let conversion: GenericConversion;
@ -243,6 +267,10 @@ describe("Creating conversion", () => {
Decimal.pow(100, 2).times(10) Decimal.pow(100, 2).times(10)
); );
}); });
test("Zero", () => {
baseResource.value = Decimal.dZero;
expect(unref(conversion.currentAt)).compare_tolerance(Decimal.pow(1, 2).times(10));
});
}); });
describe("Calculates nextAt correctly", () => { describe("Calculates nextAt correctly", () => {
let conversion: GenericConversion; let conversion: GenericConversion;
@ -266,6 +294,10 @@ describe("Creating conversion", () => {
baseResource.value = Decimal.pow(100, 2).times(10).add(1); baseResource.value = Decimal.pow(100, 2).times(10).add(1);
expect(unref(conversion.nextAt)).compare_tolerance(Decimal.pow(101, 2).times(10)); expect(unref(conversion.nextAt)).compare_tolerance(Decimal.pow(101, 2).times(10));
}); });
test("Zero", () => {
baseResource.value = Decimal.dZero;
expect(unref(conversion.nextAt)).compare_tolerance(Decimal.pow(2, 2).times(10));
});
}); });
test("Converts correctly", () => { test("Converts correctly", () => {
const conversion = createIndependentConversion(() => ({ const conversion = createIndependentConversion(() => ({