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

Allow kwargs or player variable events, default "source" kwarg in variable_player #1620

Merged

Conversation

avanwinkle
Copy link
Collaborator

Player Var-Event Kwargs

This PR proposes the addition of kwargs to player variable changes, and implements them by default on changes triggered by variable_player: events.

INFO : Event: ==='player_score'=== 
Args={'value': 1500, 'prev_value': 500, 'change': 1000, 'player_num': 1, 'source': 'skillshot'}

Adding Kwargs and New Methods

This proposal adds two new methods to the Player class:

  • add_with_kwargs(name, value, **kwargs) will add the value to the player's name property and include kwargs
  • set_with_kwargs(name, value **kwargs) will set the player's name property to the value and include kwargs

The Player class __setattr__() method modified to include kwargs, and those are passed to _send_variable_event() and included on the posted variable change event.

Variable Player Includes Context

This proposal extends the Variable Player to automatically include the context value of its triggering events as the "source" kwarg in posted events.

Use Cases

This proposal is targeted towards multipliers and jackpots that accrue value based on other modes' scoring.

For example, a playfield multiplier may want to increase all scoring by a given multiple, but the multiplier adding to the score would itself increase the score, triggering the multiplier again, for infinite scores. By checking the "source", the multiplier mode could listen to player_score events and ignore those whose source is itself.

For another example, a jackpot may grow proportional to all points scored in a given mode. By checking the "source" kwarg, the jackpot could listen to player_score events and catch those triggered by the mode it uses to grow—while ignoring scoring from all other modes.

Each of these use cases is possible already, but requires additional player variables and workarounds. This proposal just makes it easy to do score (and other player_var) filtering with conditional events and no custom code.

@jabdoa2
Copy link
Collaborator

jabdoa2 commented Nov 29, 2021

A test would be nice. Good idea. Thanks for addressing this!

@sonarcloud
Copy link

sonarcloud bot commented Nov 29, 2021

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

@avanwinkle avanwinkle marked this pull request as ready for review November 29, 2021 03:00
@avanwinkle avanwinkle merged commit 0b889fa into missionpinball:dev Nov 29, 2021
@avanwinkle avanwinkle deleted the variable-player-event-kwargs branch December 4, 2023 23:32
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.

2 participants