-
Notifications
You must be signed in to change notification settings - Fork 717
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: Simple Trigger Update To Allow Inequalities. #4253
Open
Vertraic
wants to merge
7
commits into
ArchipelagoMW:main
Choose a base branch
from
Vertraic:APTriggerUpdateSimple
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a63e9fa
Adds option_compare to ovalid options for triggers, allowing for ineq…
Vertraic a101144
Merge branch 'main' into APTriggerUpdateSimple
Vertraic 5259a17
Fixed isinstance Union handling and error handling in trigger compari…
Vertraic 38723fb
Merge branch 'APTriggerUpdateSimple' of https://github.com/Vertraic/A…
Vertraic 8ee3fe9
Union switched to tuple
Vertraic f8a9ee3
Merge branch 'main' into APTriggerUpdateSimple
Vertraic 881736a
Merge branch 'main' into APTriggerUpdateSimple
Vertraic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -378,13 +378,44 @@ def roll_linked_options(weights: dict) -> dict: | |
return weights | ||
|
||
|
||
def compare_results( | ||
yaml_value: Union[str, int, bool, dict, list], | ||
trigger_value: Union[str, int, bool, dict, list], | ||
comparator: str): | ||
if yaml_value is None: | ||
return False | ||
if isinstance(yaml_value, str|bool|int) and isinstance(trigger_value, str|bool|int): | ||
yaml_value = str(yaml_value).lower() | ||
trigger_value = str(trigger_value).lower() | ||
if comparator == "=": | ||
return yaml_value == trigger_value | ||
if comparator == "!=": | ||
return yaml_value != trigger_value | ||
try: | ||
yaml_value = int(yaml_value) | ||
trigger_value = int(trigger_value) | ||
except ValueError: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't catch TypeErrors from lists and dictionaries. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed to include TypeError |
||
raise Exception("Value of option_name and option_result must be integers if comparison is not = or !=") | ||
if comparator == "<": | ||
return yaml_value < trigger_value | ||
if comparator == "<=": | ||
return yaml_value <= trigger_value | ||
if comparator == ">": | ||
return yaml_value > trigger_value | ||
if comparator == ">=": | ||
return yaml_value >= trigger_value | ||
raise ValueError(f"option_compare must be one of [=,<,<=,>=,>,!=]") | ||
|
||
|
||
def roll_triggers(weights: dict, triggers: list, valid_keys: set) -> dict: | ||
weights = copy.deepcopy(weights) # make sure we don't write back to other weights sets in same_settings | ||
weights["_Generator_Version"] = Utils.__version__ | ||
for i, option_set in enumerate(triggers): | ||
try: | ||
currently_targeted_weights = weights | ||
category = option_set.get("option_category", None) | ||
if "option_compare" not in option_set: | ||
option_set["option_compare"] = "=" | ||
if category: | ||
currently_targeted_weights = currently_targeted_weights[category] | ||
key = get_choice("option_name", option_set) | ||
|
@@ -394,8 +425,10 @@ def roll_triggers(weights: dict, triggers: list, valid_keys: set) -> dict: | |
f'This is probably in error.') | ||
trigger_result = get_choice("option_result", option_set) | ||
result = get_choice(key, currently_targeted_weights) | ||
compare = get_choice("option_compare", option_set) | ||
currently_targeted_weights[key] = result | ||
if result == trigger_result and roll_percentage(get_choice("percentage", option_set, 100)): | ||
if (compare_results(result, trigger_result, compare) and | ||
roll_percentage(get_choice("percentage", option_set, 100))): | ||
for category_name, category_options in option_set["options"].items(): | ||
currently_targeted_weights = weights | ||
if category_name: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Union types in
isinstance
are only available starting in Python 3.10There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you used a Union, which isn't supported. Use a tuple like my suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it this time. Sorry about that.