Skip to content

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