From 92319b0e31348de25421a2fc9bc81b269b591573 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Mon, 21 Mar 2022 20:49:54 +0100 Subject: [PATCH] Options: implement item name groups for item sets options (#325) * Options: implement item name groups for item sets options * Options: update outdated comments; verify is done by the verify mixin parent class nowadays --- Options.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Options.py b/Options.py index a1215bb7..4fa17818 100644 --- a/Options.py +++ b/Options.py @@ -265,8 +265,9 @@ class Range(Option, int): class VerifyKeys: valid_keys = frozenset() valid_keys_casefold: bool = False - verify_item_name = False - verify_location_name = False + convert_name_groups: bool = False + verify_item_name: bool = False + verify_location_name: bool = False value: typing.Any @classmethod @@ -280,6 +281,11 @@ class VerifyKeys: f"Allowed keys: {cls.valid_keys}.") def verify(self, world): + if self.convert_name_groups and self.verify_item_name: + new_value = type(self.value)() # empty container of whatever value is + for item_name in self.value: + new_value |= world.item_name_groups.get(item_name, {item_name}) + self.value = new_value if self.verify_item_name: for item_name in self.value: if item_name not in world.item_names: @@ -287,7 +293,7 @@ class VerifyKeys: f"is not a valid item name from {world.game}") elif self.verify_location_name: for location_name in self.value: - if location_name not in world.world_types[world.game].location_names: + if location_name not in world.location_names: raise Exception(f"Location {location_name} from option {self} " f"is not a valid location name from {world.game}") @@ -316,7 +322,6 @@ class OptionDict(Option, VerifyKeys): class ItemDict(OptionDict): - # implemented by Generate verify_item_name = True def __init__(self, value: typing.Dict[str, int]): @@ -410,8 +415,8 @@ common_options = { class ItemSet(OptionSet): - # implemented by Generate verify_item_name = True + convert_name_groups = True class LocalItems(ItemSet):