mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 12:11:33 -06:00
Options: Cleanup CommonOptions.as_dict (#4921)
Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com>
This commit is contained in:
21
Options.py
21
Options.py
@@ -1292,21 +1292,28 @@ class CommonOptions(metaclass=OptionsMetaProperty):
|
|||||||
progression_balancing: ProgressionBalancing
|
progression_balancing: ProgressionBalancing
|
||||||
accessibility: Accessibility
|
accessibility: Accessibility
|
||||||
|
|
||||||
def as_dict(self,
|
def as_dict(
|
||||||
|
self,
|
||||||
*option_names: str,
|
*option_names: str,
|
||||||
casing: typing.Literal["snake", "camel", "pascal", "kebab"] = "snake",
|
casing: typing.Literal["snake", "camel", "pascal", "kebab"] = "snake",
|
||||||
toggles_as_bools: bool = False) -> typing.Dict[str, typing.Any]:
|
toggles_as_bools: bool = False,
|
||||||
|
) -> 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 get the values of.
|
||||||
:param casing: case of the keys to return. Supports `snake`, `camel`, `pascal`, `kebab`
|
:param casing: Casing 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
|
:param toggles_as_bools: Whether toggle options should be returned as bools instead of ints.
|
||||||
|
|
||||||
|
:return: A dictionary of each option name to the value of its Option. If the option is an OptionSet, the value
|
||||||
|
will be returned as a sorted list.
|
||||||
"""
|
"""
|
||||||
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 = {}
|
||||||
for option_name in option_names:
|
for option_name in option_names:
|
||||||
if option_name in type(self).type_hints:
|
if option_name not in type(self).type_hints:
|
||||||
|
raise ValueError(f"{option_name} not found in {tuple(type(self).type_hints)}")
|
||||||
|
|
||||||
if casing == "snake":
|
if casing == "snake":
|
||||||
display_name = option_name
|
display_name = option_name
|
||||||
elif casing == "camel":
|
elif casing == "camel":
|
||||||
@@ -1326,8 +1333,6 @@ class CommonOptions(metaclass=OptionsMetaProperty):
|
|||||||
elif toggles_as_bools and issubclass(type(self).type_hints[option_name], Toggle):
|
elif toggles_as_bools and issubclass(type(self).type_hints[option_name], Toggle):
|
||||||
value = bool(value)
|
value = bool(value)
|
||||||
option_results[display_name] = value
|
option_results[display_name] = value
|
||||||
else:
|
|
||||||
raise ValueError(f"{option_name} not found in {tuple(type(self).type_hints)}")
|
|
||||||
return option_results
|
return option_results
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user