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

feat: Floor division support in dynamic values #1695

Merged
merged 2 commits into from
May 18, 2023

Conversation

avanwinkle
Copy link
Collaborator

This PR adds floor division functionality to dynamic values, useful for rounding arbitrary numbers to clean multiples.

For example, calculating a point score based on a timer count (hurryup) or a multiplier can yield tens and ones of digits, or even floats. Many pinball games like to have a minimum score multiple of 10 (e.g. no single-digit points) or even 100, and this PR enables a dynamic value to crop to the nearest iteration using the standard syntax of floor division * divisor.

variable_player:
  jackpot_shot_hit:
    score: current_player.jackpot_value * current_player.float_multiplier // 100 * 100

The placeholder templating engine uses native python operations so it inherently understands that // means floor division, but the code module wasn't mapping the op.floordiv method for executing it. This PR simply maps the method, and it works. Tests added to verify and prevent regressions.

division is great

@sonarcloud
Copy link

sonarcloud bot commented May 17, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@toomanybrians
Copy link
Member

Awesome feature, and such a simple and powerful change to make! Thanks for the tests, and I'll add this to the docs.

@toomanybrians toomanybrians merged commit b516a97 into dev May 18, 2023
@toomanybrians toomanybrians deleted the floor-division-in-dynamic-values branch May 18, 2023 14:50
avanwinkle pushed a commit to avanwinkle/mpf that referenced this pull request May 21, 2023
…sion-in-dynamic-values

feat: Floor division support in dynamic values
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.

None yet

2 participants