Skip to content

Commit

Permalink
fix: incrementing starting from 1 in amount screens not having an int…
Browse files Browse the repository at this point in the history
…ended off-by-one

If we start from 1 and increment by 10 we want 10, not 11.
  • Loading branch information
raoulvdberge committed Mar 11, 2024
1 parent 7a185eb commit 092047f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Fixed losing energy when using Wrench dismantling on the Portable Grid and the Controller.
- Fixed changing side buttons not working on Forge.
- Fixed External Storage not displaying empty allowlist warning.
- Fixed incrementing starting from 1 in amount screens not having an intended off-by-one.

## [2.0.0-milestone.3.3] - 2024-02-17

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,24 @@ private void changeAmount(final int delta) {
return;
}
getAndValidateAmount().ifPresent(oldAmount -> {
final int correctedDelta = correctDelta(oldAmount, delta);
final N newAmount = amountOperations.changeAmount(
oldAmount,
delta,
correctedDelta,
configuration.getMinAmount(),
configuration.getMaxAmount()
);
amountField.setValue(amountOperations.format(newAmount));
});
}

private int correctDelta(final N oldAmount, final int delta) {
if (oldAmount.intValue() == 1 && delta > 0) {
return delta - 1;
}
return delta;
}

@Override
public boolean mouseScrolled(final double x, final double y, final double z, final double delta) {
if (delta > 0) {
Expand Down

0 comments on commit 092047f

Please sign in to comment.