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
This commit is contained in:
parent
d4ff653937
commit
92319b0e31
15
Options.py
15
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):
|
||||
|
|
Loading…
Reference in New Issue