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

Core: Added new roll_triggers functionality and created two helper functions to support it. #3539

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

Vertraic
Copy link

@Vertraic Vertraic commented Jun 15, 2024

What is this fixing or adding?

Keeps the current trigger functionality, while adding the ability to use comparators (<, >) for numerical values, and to and/or multiple conditions together for more complex triggers. This required adding random-range-min-max resolution to roll_triggers. random/random-range-low/high are not included in this resolution.
If the new option "option_advanced" is not included, triggers will work exactly as before, with the exception of resolving random-range-min-max.
For multiple option comparison, And takes priority, so if you look for options: A & B & C | B & D | A & E & F it will logically group them as: (A & B & C) | (B & D) | (A & E & F)

Format is as follows in the trigger options, replace list dots with - :
option_advanced:

  • ['option name1', (optional comparator), {trigger value}]
  • &/0 or |/1
  • ['option name2', (optional comparator), {trigger value}]
  • ...
  • ['option nameN', (optional comparator), {trigger value}]

the comparator accepts '<', '=', '!=', '>' and defaults to '=' if only two entries are given.
&/0/and/And/AND all represent an AND operation, while |/1/or/Or/OR both represent and OR operation.

option_name/option_result are un-needed when option_advanced is present.

Example:
triggers:

  • option_category: 'A Link to the Past'
    option_advanced:
    • ['crystals_needed_for_gt', '>', 2]
    • 0
    • ['crystals_needed_for_gt', '<', 6]
    • '&'
    • ['crystals_needed_for_ganon', '=', 4]
    • '|'
    • ['goal', 'triforce_hunt]
    • '&'
    • ['triforce_pieces_mode', '=', 'percentage']]
      options:
      A Link to the Past:
      swordless: true

This says that if crystals needed for gt is more than 2 and less than 6, and crystals needed for ganon is 4 OR if goal is triforce hunt and triforce pieces mode is set to percentage, then swordless will be set to true.

How was this tested?

Unit tests were run to see if anything outside triggers had broken, and I tried old trigger styles to ensure they still worked, and then tried each new feature separately, and in multiple combinations while checking that the resulting settings were as expected, including making sure random-range-min-max permanently resolved to a constant value for that game's generation.
Finally, I ran a generation with every supported game that A: Does not require you to possess a copy of, or B: That I possess a copy of. including both old and new triggers in two of them.
The generation was successful with no errors, and all the game's settings were as expected, including merged values for start_inventory.

If this makes graphical changes, please attach screenshots.

No graphical changes were made.

and to decide based off of multiple options through And/Or conditions,
and can resolve random-range-min-max options.
Current style triggers old functionality remains the same, except
they can now resolve random-range-min-max options.
@github-actions github-actions bot added affects: core Issues/PRs that touch core and may need additional validation. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. labels Jun 15, 2024
Vertraic added 3 commits June 15, 2024 01:26
and to decide based off of multiple options through And/Or conditions,
and can resolve random-range-min-max options.
Current style triggers old functionality remains the same, except
they can now resolve random-range-min-max options.
…st],

added more recognized forms for and/or (AND, And, and, OR, Or, or).
Retested, it works.
@Exempt-Medic
Copy link
Member

Since you're updating these, you should also update the triggers guide to include examples of all of these new functions

Generate.py Outdated
comparator: str):
if comparator == "=":
return yaml_value == trigger_value
elif comparator == "!=":
Copy link
Member

@Exempt-Medic Exempt-Medic Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a return, so this can be an if
Edit: There are other instances of this.

Suggested change
elif comparator == "!=":
if comparator == "!=":

Generate.py Outdated
return yaml_value == trigger_value
elif comparator == "!=":
return yaml_value != trigger_value
if type(yaml_value) is int and type(trigger_value) is int:
Copy link
Member

@Exempt-Medic Exempt-Medic Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use isinstance(yaml_value, int) and not type()
Edit: There are other instances of this.

@Exempt-Medic Exempt-Medic added the is: enhancement Issues requesting new features or pull requests implementing new features. label Jun 15, 2024
Vertraic added 10 commits June 15, 2024 22:42
…able, type)

comparisons, and changed elifs after returns to ifs as suggested.
Also added changes to Trigger guide to explain the new options.
…options.

This defaults to "=" to maintain previous functionality.

Also updated the trigger guide to show this extra functionality, and to
clarify the function/use of advanced triggers.
…ues,

and str numbers, such as 4 == '4', as well as bool/string such as false vs 'false'
… exist.

Changed to consider such a comparison False, as is the current response.
@Vertraic Vertraic changed the title Core: Added new role_triggers functionality and created two helper functions to support it. Core: Added new roll_triggers functionality and created two helper functions to support it. Jul 26, 2024
Vertraic added 3 commits July 25, 2024 22:03
…ional,

and added handling for entries NOT contained in type_hints (less likely to
be used now that and/or and comparators are present.)
@benny-dreamly
Copy link
Contributor

would 100% use this as a sync host.

@benny-dreamly
Copy link
Contributor

benny-dreamly commented Nov 26, 2024

just an observation from #ap-core-dev, maybe splitting this PR into multiple PRs would be better in the long run and make it less complicated? I think the math comparison operations might be better suited for a separate PR from the multi-condition functionality. Obviously this is only a suggestion, and feel free to ignore me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: core Issues/PRs that touch core and may need additional validation. is: enhancement Issues requesting new features or pull requests implementing new features. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants