mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
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:
15
Options.py
15
Options.py
@@ -265,8 +265,9 @@ class Range(Option, int):
|
|||||||
class VerifyKeys:
|
class VerifyKeys:
|
||||||
valid_keys = frozenset()
|
valid_keys = frozenset()
|
||||||
valid_keys_casefold: bool = False
|
valid_keys_casefold: bool = False
|
||||||
verify_item_name = False
|
convert_name_groups: bool = False
|
||||||
verify_location_name = False
|
verify_item_name: bool = False
|
||||||
|
verify_location_name: bool = False
|
||||||
value: typing.Any
|
value: typing.Any
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -280,6 +281,11 @@ class VerifyKeys:
|
|||||||
f"Allowed keys: {cls.valid_keys}.")
|
f"Allowed keys: {cls.valid_keys}.")
|
||||||
|
|
||||||
def verify(self, world):
|
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:
|
if self.verify_item_name:
|
||||||
for item_name in self.value:
|
for item_name in self.value:
|
||||||
if item_name not in world.item_names:
|
if item_name not in world.item_names:
|
||||||
@@ -287,7 +293,7 @@ class VerifyKeys:
|
|||||||
f"is not a valid item name from {world.game}")
|
f"is not a valid item name from {world.game}")
|
||||||
elif self.verify_location_name:
|
elif self.verify_location_name:
|
||||||
for location_name in self.value:
|
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} "
|
raise Exception(f"Location {location_name} from option {self} "
|
||||||
f"is not a valid location name from {world.game}")
|
f"is not a valid location name from {world.game}")
|
||||||
|
|
||||||
@@ -316,7 +322,6 @@ class OptionDict(Option, VerifyKeys):
|
|||||||
|
|
||||||
|
|
||||||
class ItemDict(OptionDict):
|
class ItemDict(OptionDict):
|
||||||
# implemented by Generate
|
|
||||||
verify_item_name = True
|
verify_item_name = True
|
||||||
|
|
||||||
def __init__(self, value: typing.Dict[str, int]):
|
def __init__(self, value: typing.Dict[str, int]):
|
||||||
@@ -410,8 +415,8 @@ common_options = {
|
|||||||
|
|
||||||
|
|
||||||
class ItemSet(OptionSet):
|
class ItemSet(OptionSet):
|
||||||
# implemented by Generate
|
|
||||||
verify_item_name = True
|
verify_item_name = True
|
||||||
|
convert_name_groups = True
|
||||||
|
|
||||||
|
|
||||||
class LocalItems(ItemSet):
|
class LocalItems(ItemSet):
|
||||||
|
Reference in New Issue
Block a user