Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use of undefined in Decimal operations at start of game #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mcpower
Copy link

@mcpower mcpower commented Mar 26, 2022

Sometimes, at the start of the game, undefined values were being passed into Decimal methods. This implicitly converts them to be 0 in the current version of break_eternity.js, but that behaviour should not be relied on as the TypeScript types for Decimal methods state that they do not support undefined values.

As a result, this commit fixes many instances where, at the start of the game, some multipliers are set to zero due to this issue.

This commit intentionally uses ?? instead of || as the author does not know what types are used - if it's possible that the left hand side could be a number (not a Decimal) then || shouldn't be used (if the left hand side was zero). However, if old browser support is required, || should be used instead of ?? (assuming the types are correct).

This commit also uses Decimal.dOne and Decimal.dZero when needed instead of constructing new Decimal instances.

Sometimes, at the start of the game, undefined values were being passed
into Decimal methods. This implicitly converts them to be 0 in the
current version of break_eternity.js, but that behaviour should not be
relied on as the TypeScript types for Decimal methods state that they do
not support undefined values.

As a result, this commit fixes many instances where, at the start of the
game, some multipliers are set to zero due to this issue.

This commit intentionally uses ?? instead of || as the author does not
know what types are used - if it's possible that the left hand side
could be a number (not a Decimal) then || shouldn't be used (if the left
hand side was zero).  However, if [old browser support] is required, ||
should be used instead of ?? (assuming the types are correct).

This commit also uses Decimal.dOne and Decimal.dZero when needed instead
of constructing new Decimal instances.

[old browser support]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator#browser_compatibility
@mcpower
Copy link
Author

mcpower commented Mar 26, 2022

Reviewers - please double check the default values I used. I've tried my best to use either 0 or 1 in the right places, but I may have mixed some places up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant