Webhost: Disallow empty option groups (#3369)

* move item_and_loc_options out of the meta class and into the Options module

* don't allow empty world specified option groups

* reuse option_group generation code instead of rewriting it

* delete the default group if it's empty

* indent
This commit is contained in:
Aaron Wagener
2024-05-23 17:50:40 -05:00
committed by GitHub
parent d09b214309
commit 8b992cbf00
3 changed files with 36 additions and 30 deletions

View File

@@ -10,10 +10,7 @@ from dataclasses import make_dataclass
from typing import (Any, Callable, ClassVar, Dict, FrozenSet, List, Mapping, Optional, Set, TextIO, Tuple,
TYPE_CHECKING, Type, Union)
from Options import (
ExcludeLocations, ItemLinks, LocalItems, NonLocalItems, OptionGroup, PerGameCommonOptions,
PriorityLocations, StartHints, StartInventory, StartInventoryPool, StartLocationHints
)
from Options import item_and_loc_options, OptionGroup, PerGameCommonOptions
from BaseClasses import CollectionState
if TYPE_CHECKING:
@@ -119,12 +116,11 @@ class WebWorldRegister(type):
# don't allow an option to appear in multiple groups, allow "Item & Location Options" to appear anywhere by the
# dev, putting it at the end if they don't define options in it
option_groups: List[OptionGroup] = dct.get("option_groups", [])
item_and_loc_options = [LocalItems, NonLocalItems, StartInventory, StartInventoryPool, StartHints,
StartLocationHints, ExcludeLocations, PriorityLocations, ItemLinks]
seen_options = []
item_group_in_list = False
for group in option_groups:
assert group.name != "Game Options", "Game Options is a pre-determined group and can not be defined."
assert group.options, "A custom defined Option Group must contain at least one Option."
if group.name == "Item & Location Options":
group.options.extend(item_and_loc_options)
item_group_in_list = True