-
Notifications
You must be signed in to change notification settings - Fork 704
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: Allow Option References and Math in YAML Option Values #4049
base: main
Are you sure you want to change the base?
Conversation
…weights so that it can pass unittests
…option so that it can pass unittests
…ted functionality.
BinOp = Literal["+", "-", "*", "/"] | ||
|
||
|
||
_bops: Mapping[BinOp, Callable[[Union[float, int], Union[float,int]], Union[float, int]]] = { | ||
"+": lambda a, b: a + b, |
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.
The PR author is already aware of this, but this is a note to other reviewers.
This isn't a good place for this math parsing code, but it's not a lot worse than any other place that's available.
It would be good to put it in its own module as a sub-module to Utils
#4032
Re-wrote breaking changes to not break, reverted lufia2ac test change, allowed for float math in binops while correcting data type before it is used by from_any.
use a `name_resolver` function
Generate.py
Outdated
return operand_stack[0] | ||
|
||
|
||
def get_choice(option, root, value=None, sub_group=None, record: ChoiceRecord = ChoiceRecord(None, None, None)) -> Any: |
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.
This is a mutable default argument for record
https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments
I recommend you use ruff with the "B" rules enabled. It will point out issues like this to you.
Generate.py
Outdated
if len(val_str.split(".")) > 1: | ||
val = float(val_str) | ||
else: | ||
val = int(val_str) |
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.
if len(val_str.split(".")) > 1: | |
val = float(val_str) | |
else: | |
val = int(val_str) | |
val = float(val_str) |
can simplify this since it will be turned into int
at the end if needed
Also removes if-else from parse_tokens that was no longer necessary as floats are converted to int later on if needed.
Two references to root changed to choice_group, and added if-else to ensure sub_group does not write back to root.
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.
I'm not going to review this.
Added functionality to handle math/option references in yamls through additional functions + new class.
What is this fixing or adding?
Adds the ability to reference other option values and perform mathematical operations in yamls by enclosing the option value
with $(...). For example:
option1: random-range-4-15
option2: $(option1 * 2)
option2 will be assigned the value of double whatever option1 rolls.
This does not support random(-range) inside the operation, only by referencing an option using it.
References can stack (option1 points to option2 which points to option3...) so long as no reference loops are created (option1 points to option2 which points to option1) There is no PRACTICAL limit to how many references are made
How was this tested?
Each operator was tested with multiple values, positive and negative.
Option value resolution was tested with multiple references in a single operation ($(option1 * (option2 + option3)) for example)
Testing was performed on various random(-range-) values, and with OoT and Factorio specifically to ensure their special calls still worked.
If this makes graphical changes, please attach screenshots.
No graphical changes