Core: Add toggles_as_bools to options.as_dict (#3770)
* Add toggles_as_bools to options.as_dict * Update Options.py Co-authored-by: Doug Hoskisson <beauxq@users.noreply.github.com> * Add param to docstring * if -> elif --------- Co-authored-by: Doug Hoskisson <beauxq@users.noreply.github.com>
This commit is contained in:
parent
925fb967d3
commit
704f14ffcd
14
Options.py
14
Options.py
|
@ -754,7 +754,7 @@ class NamedRange(Range):
|
||||||
elif value > self.range_end and value not in self.special_range_names.values():
|
elif value > self.range_end and value not in self.special_range_names.values():
|
||||||
raise Exception(f"{value} is higher than maximum {self.range_end} for option {self.__class__.__name__} " +
|
raise Exception(f"{value} is higher than maximum {self.range_end} for option {self.__class__.__name__} " +
|
||||||
f"and is also not one of the supported named special values: {self.special_range_names}")
|
f"and is also not one of the supported named special values: {self.special_range_names}")
|
||||||
|
|
||||||
# See docstring
|
# See docstring
|
||||||
for key in self.special_range_names:
|
for key in self.special_range_names:
|
||||||
if key != key.lower():
|
if key != key.lower():
|
||||||
|
@ -1180,7 +1180,7 @@ class PlandoConnections(Option[typing.List[PlandoConnection]], metaclass=Connect
|
||||||
class Accessibility(Choice):
|
class Accessibility(Choice):
|
||||||
"""
|
"""
|
||||||
Set rules for reachability of your items/locations.
|
Set rules for reachability of your items/locations.
|
||||||
|
|
||||||
**Full:** ensure everything can be reached and acquired.
|
**Full:** ensure everything can be reached and acquired.
|
||||||
|
|
||||||
**Minimal:** ensure what is needed to reach your goal can be acquired.
|
**Minimal:** ensure what is needed to reach your goal can be acquired.
|
||||||
|
@ -1198,7 +1198,7 @@ class Accessibility(Choice):
|
||||||
class ItemsAccessibility(Accessibility):
|
class ItemsAccessibility(Accessibility):
|
||||||
"""
|
"""
|
||||||
Set rules for reachability of your items/locations.
|
Set rules for reachability of your items/locations.
|
||||||
|
|
||||||
**Full:** ensure everything can be reached and acquired.
|
**Full:** ensure everything can be reached and acquired.
|
||||||
|
|
||||||
**Minimal:** ensure what is needed to reach your goal can be acquired.
|
**Minimal:** ensure what is needed to reach your goal can be acquired.
|
||||||
|
@ -1249,12 +1249,16 @@ class CommonOptions(metaclass=OptionsMetaProperty):
|
||||||
progression_balancing: ProgressionBalancing
|
progression_balancing: ProgressionBalancing
|
||||||
accessibility: Accessibility
|
accessibility: Accessibility
|
||||||
|
|
||||||
def as_dict(self, *option_names: str, casing: str = "snake") -> typing.Dict[str, typing.Any]:
|
def as_dict(self,
|
||||||
|
*option_names: str,
|
||||||
|
casing: typing.Literal["snake", "camel", "pascal", "kebab"] = "snake",
|
||||||
|
toggles_as_bools: bool = False) -> typing.Dict[str, typing.Any]:
|
||||||
"""
|
"""
|
||||||
Returns a dictionary of [str, Option.value]
|
Returns a dictionary of [str, Option.value]
|
||||||
|
|
||||||
:param option_names: names of the options to return
|
:param option_names: names of the options to return
|
||||||
:param casing: case of the keys to return. Supports `snake`, `camel`, `pascal`, `kebab`
|
:param casing: case of the keys to return. Supports `snake`, `camel`, `pascal`, `kebab`
|
||||||
|
:param toggles_as_bools: whether toggle options should be output as bools instead of strings
|
||||||
"""
|
"""
|
||||||
assert option_names, "options.as_dict() was used without any option names."
|
assert option_names, "options.as_dict() was used without any option names."
|
||||||
option_results = {}
|
option_results = {}
|
||||||
|
@ -1276,6 +1280,8 @@ class CommonOptions(metaclass=OptionsMetaProperty):
|
||||||
value = getattr(self, option_name).value
|
value = getattr(self, option_name).value
|
||||||
if isinstance(value, set):
|
if isinstance(value, set):
|
||||||
value = sorted(value)
|
value = sorted(value)
|
||||||
|
elif toggles_as_bools and issubclass(type(self).type_hints[option_name], Toggle):
|
||||||
|
value = bool(value)
|
||||||
option_results[display_name] = value
|
option_results[display_name] = value
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"{option_name} not found in {tuple(type(self).type_hints)}")
|
raise ValueError(f"{option_name} not found in {tuple(type(self).type_hints)}")
|
||||||
|
|
Loading…
Reference in New Issue