Skip to content
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: Add toggles_as_bools to options.as_dict #3770

Merged
merged 6 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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]:
Exempt-Medic marked this conversation as resolved.
Show resolved Hide resolved
"""
Returns a dictionary of [str, Option.value]

Expand All @@ -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):
Exempt-Medic marked this conversation as resolved.
Show resolved Hide resolved
value = bool(value)
option_results[display_name] = value
else:
raise ValueError(f"{option_name} not found in {tuple(type(self).type_hints)}")
Expand Down
Loading