mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 12:11:33 -06:00
Core: add unit tests and more documentation for numeric options (#2926)
* Core: add unit tests for the numeric options * document using a collection and the hashing quirk * add another example for the footgun --------- Co-authored-by: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com>
This commit is contained in:
@@ -132,7 +132,8 @@ or if I need a boolean object, such as in my slot_data I can access it as:
|
||||
start_with_sword = bool(self.options.starting_sword.value)
|
||||
```
|
||||
All numeric options (i.e. Toggle, Choice, Range) can be compared to integers, strings that match their attributes,
|
||||
strings that match the option attributes after "option_" is stripped, and the attributes themselves.
|
||||
strings that match the option attributes after "option_" is stripped, and the attributes themselves. The option can
|
||||
also be checked to see if it exists within a collection, but this will fail for a set of strings due to hashing.
|
||||
```python
|
||||
# options.py
|
||||
class Logic(Choice):
|
||||
@@ -144,6 +145,12 @@ class Logic(Choice):
|
||||
alias_extra_hard = 2
|
||||
crazy = 4 # won't be listed as an option and only exists as an attribute on the class
|
||||
|
||||
class Weapon(Choice):
|
||||
option_none = 0
|
||||
option_sword = 1
|
||||
option_bow = 2
|
||||
option_hammer = 3
|
||||
|
||||
# __init__.py
|
||||
from .options import Logic
|
||||
|
||||
@@ -157,6 +164,16 @@ elif self.options.logic == Logic.option_extreme:
|
||||
do_extreme_things()
|
||||
elif self.options.logic == "crazy":
|
||||
do_insane_things()
|
||||
|
||||
# check if the current option is in a collection of integers using the class attributes
|
||||
if self.options.weapon in {Weapon.option_bow, Weapon.option_sword}:
|
||||
do_stuff()
|
||||
# in order to make a set of strings work, we have to compare against current_key
|
||||
elif self.options.weapon.current_key in {"none", "hammer"}:
|
||||
do_something_else()
|
||||
# though it's usually better to just use a tuple instead
|
||||
elif self.options.weapon in ("none", "hammer"):
|
||||
do_something_else()
|
||||
```
|
||||
## Generic Option Classes
|
||||
These options are generically available to every game automatically, but can be overridden for slightly different
|
||||
|
Reference in New Issue
Block a user