Skip to content

Commit 58deb0a

Browse files
alwaysintreblesflavelle
authored andcommitted
Webhost: Allow Option Groups to specify whether they start collapsed (ArchipelagoMW#3370)
* allow option groups to specify whether they should be hidden or not * allow worlds to override whether game options starts collapsed * remove Game Options assert so the visibility of that group can be changed * if "Game Options" or "Item & Location Options" groups are specified, fix casing * don't allow item & location options to have duplicates of the auto added options * use a generator instead of a comprehension * use consistent naming
1 parent a878135 commit 58deb0a

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

Options.py

+2
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,8 @@ class OptionGroup(typing.NamedTuple):
11301130
"""Name of the group to categorize these options in for display on the WebHost and in generated YAMLS."""
11311131
options: typing.List[typing.Type[Option[typing.Any]]]
11321132
"""Options to be in the defined group."""
1133+
start_collapsed: bool = False
1134+
"""Whether the group will start collapsed on the WebHost options pages."""
11331135

11341136

11351137
item_and_loc_options = [LocalItems, NonLocalItems, StartInventory, StartInventoryPool, StartHints,

WebHostLib/options.py

+5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ def render_options_page(template: str, world_name: str, is_complex: bool = False
3232
return redirect("games")
3333
visibility_flag = Options.Visibility.complex_ui if is_complex else Options.Visibility.simple_ui
3434

35+
start_collapsed = {"Game Options": False}
36+
for group in world.web.option_groups:
37+
start_collapsed[group.name] = group.start_collapsed
38+
3539
return render_template(
3640
template,
3741
world_name=world_name,
3842
world=world,
3943
option_groups=Options.get_option_groups(world, visibility_level=visibility_flag),
44+
start_collapsed=start_collapsed,
4045
issubclass=issubclass,
4146
Options=Options,
4247
theme=get_world_theme(world_name),

WebHostLib/templates/playerOptions/playerOptions.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ <h1>Player Options</h1>
6969

7070
<div id="option-groups">
7171
{% for group_name, group_options in option_groups.items() %}
72-
<details class="group-container" {% if loop.index == 1 %}open{% endif %}>
72+
<details class="group-container" {% if not start_collapsed[group_name] %}open{% endif %}>
7373
<summary class="h2">{{ group_name }}</summary>
7474
<div class="game-options">
7575
<div class="left">

WebHostLib/templates/weightedOptions/weightedOptions.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ <h1>Weighted Options</h1>
5151

5252
<div id="{{ world_name }}-container">
5353
{% for group_name, group_options in option_groups.items() %}
54-
<details {% if loop.index == 1 %}open{% endif %}>
54+
<details {% if not start_collapsed[group_name] %}open{% endif %}>
5555
<summary class="h2">{{ group_name }}</summary>
5656
{% for option_name, option in group_options.items() %}
5757
<div class="option-wrapper">

worlds/AutoWorld.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,19 @@ def __new__(mcs, name: str, bases: Tuple[type, ...], dct: Dict[str, Any]) -> Web
116116
# don't allow an option to appear in multiple groups, allow "Item & Location Options" to appear anywhere by the
117117
# dev, putting it at the end if they don't define options in it
118118
option_groups: List[OptionGroup] = dct.get("option_groups", [])
119+
prebuilt_options = ["Game Options", "Item & Location Options"]
119120
seen_options = []
120121
item_group_in_list = False
121122
for group in option_groups:
122-
assert group.name != "Game Options", "Game Options is a pre-determined group and can not be defined."
123123
assert group.options, "A custom defined Option Group must contain at least one Option."
124+
# catch incorrectly titled versions of the prebuilt groups so they don't create extra groups
125+
title_name = group.name.title()
126+
if title_name in prebuilt_options:
127+
group.name = title_name
128+
124129
if group.name == "Item & Location Options":
130+
assert not any(option in item_and_loc_options for option in group.options), \
131+
f"Item and Location Options cannot be specified multiple times"
125132
group.options.extend(item_and_loc_options)
126133
item_group_in_list = True
127134
else:
@@ -133,7 +140,7 @@ def __new__(mcs, name: str, bases: Tuple[type, ...], dct: Dict[str, Any]) -> Web
133140
assert option not in seen_options, f"{option} found in two option groups"
134141
seen_options.append(option)
135142
if not item_group_in_list:
136-
option_groups.append(OptionGroup("Item & Location Options", item_and_loc_options))
143+
option_groups.append(OptionGroup("Item & Location Options", item_and_loc_options, True))
137144
return super().__new__(mcs, name, bases, dct)
138145

139146

0 commit comments

Comments
 (0)