From 3cc4da4af974efcab17362bb7bb7d12ca150445d Mon Sep 17 00:00:00 2001 From: Exempt-Medic Date: Sun, 11 Aug 2024 08:03:37 -0400 Subject: [PATCH 1/4] Add toggles_as_bools to options.as_dict --- Options.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Options.py b/Options.py index d040828509d1..495200c8caf9 100644 --- a/Options.py +++ b/Options.py @@ -753,7 +753,7 @@ def __init__(self, value: int) -> None: 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__} " + f"and is also not one of the supported named special values: {self.special_range_names}") - + # See docstring for key in self.special_range_names: if key != key.lower(): @@ -1160,7 +1160,7 @@ def __len__(self) -> int: class Accessibility(Choice): """ Set rules for reachability of your items/locations. - + **Full:** ensure everything can be reached and acquired. **Minimal:** ensure what is needed to reach your goal can be acquired. @@ -1178,7 +1178,7 @@ class Accessibility(Choice): class ItemsAccessibility(Accessibility): """ Set rules for reachability of your items/locations. - + **Full:** ensure everything can be reached and acquired. **Minimal:** ensure what is needed to reach your goal can be acquired. @@ -1229,7 +1229,7 @@ class CommonOptions(metaclass=OptionsMetaProperty): progression_balancing: ProgressionBalancing 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: str = "snake", toggles_as_bools: bool = False) -> typing.Dict[str, typing.Any]: """ Returns a dictionary of [str, Option.value] @@ -1255,6 +1255,8 @@ def as_dict(self, *option_names: str, casing: str = "snake") -> typing.Dict[str, value = getattr(self, option_name).value if isinstance(value, set): value = sorted(value) + if toggles_as_bools and issubclass(type(self).type_hints[option_name], Toggle): + value = bool(value) option_results[display_name] = value else: raise ValueError(f"{option_name} not found in {tuple(type(self).type_hints)}") From f36db184fa9385615d4373e74a61031a96ce4a38 Mon Sep 17 00:00:00 2001 From: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> Date: Thu, 15 Aug 2024 20:31:53 -0400 Subject: [PATCH 2/4] Update Options.py Co-authored-by: Doug Hoskisson --- Options.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Options.py b/Options.py index 495200c8caf9..76ba32387f33 100644 --- a/Options.py +++ b/Options.py @@ -1229,7 +1229,10 @@ class CommonOptions(metaclass=OptionsMetaProperty): progression_balancing: ProgressionBalancing accessibility: Accessibility - def as_dict(self, *option_names: str, casing: str = "snake", toggles_as_bools: bool = False) -> 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] From d196324ae92ea6a8206cc2855a33a315ef5bc1fb Mon Sep 17 00:00:00 2001 From: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> Date: Fri, 16 Aug 2024 07:07:08 -0400 Subject: [PATCH 3/4] Add param to docstring --- Options.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Options.py b/Options.py index ef43b5a3d8be..a649eaa71768 100644 --- a/Options.py +++ b/Options.py @@ -1238,6 +1238,7 @@ def as_dict(self, :param option_names: names of the options to return :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." option_results = {} From 48ef0dca61054ea4ec2f94e349018be42dc03d50 Mon Sep 17 00:00:00 2001 From: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:42:55 -0500 Subject: [PATCH 4/4] if -> elif --- Options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Options.py b/Options.py index a649eaa71768..2ba25908101a 100644 --- a/Options.py +++ b/Options.py @@ -1260,7 +1260,7 @@ def as_dict(self, value = getattr(self, option_name).value if isinstance(value, set): value = sorted(value) - if 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) option_results[display_name] = value else: