Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhost: Allow Option Groups to specify whether they start collapsed #3370

Merged
merged 8 commits into from
May 24, 2024
2 changes: 2 additions & 0 deletions Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,8 @@ class OptionGroup(typing.NamedTuple):
"""Name of the group to categorize these options in for display on the WebHost and in generated YAMLS."""
options: typing.List[typing.Type[Option[typing.Any]]]
"""Options to be in the defined group."""
start_collapsed: bool = False
"""Whether the group will start collapsed on the WebHost options pages."""


def generate_yaml_templates(target_folder: typing.Union[str, "pathlib.Path"], generate_hidden: bool = True):
Expand Down
5 changes: 5 additions & 0 deletions WebHostLib/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ def render_options_page(template: str, world_name: str, is_complex: bool = False
if visibility_flag in option.visibility:
grouped_options[option_groups.get(option, "Game Options")][option_name] = option

group_visibility = {"Game Options": False}
for group in world.web.option_groups:
group_visibility[group.name] = group.start_collapsed

return render_template(
template,
world_name=world_name,
world=world,
option_groups=grouped_options,
group_visibility=group_visibility,
issubclass=issubclass,
Options=Options,
theme=get_world_theme(world_name),
Expand Down
2 changes: 1 addition & 1 deletion WebHostLib/templates/playerOptions/playerOptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h1>Player Options</h1>

<div id="option-groups">
{% for group_name, group_options in option_groups.items() %}
<details class="group-container" {% if loop.index == 1 %}open{% endif %}>
<details class="group-container" {% if not group_visibility[group_name] %}open{% endif %}>
<summary class="h2">{{ group_name }}</summary>
<div class="game-options">
<div class="left">
Expand Down
2 changes: 1 addition & 1 deletion WebHostLib/templates/weightedOptions/weightedOptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h1>Weighted Options</h1>

<div id="{{ world_name }}-container">
{% for group_name, group_options in option_groups.items() %}
<details {% if loop.index == 1 %}open{% endif %}>
<details {% if not group_visibility[group_name] %}open{% endif %}>
<summary class="h2">{{ group_name }}</summary>
{% for option_name, option in group_options.items() %}
<div class="option-wrapper">
Expand Down
11 changes: 9 additions & 2 deletions worlds/AutoWorld.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,18 @@ def __new__(mcs, name: str, bases: Tuple[type, ...], dct: Dict[str, Any]) -> Web
option_groups: List[OptionGroup] = dct.get("option_groups", [])
item_and_loc_options = [LocalItems, NonLocalItems, StartInventory, StartInventoryPool, StartHints,
StartLocationHints, ExcludeLocations, PriorityLocations, ItemLinks]
prebuilt_options = ["Game Options", "Item & Location Options"]
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."
# catch incorrectly titled versions of the prebuilt groups so they don't create extra groups
title_name = group.name.title()
if title_name in prebuilt_options:
group.name = title_name

if group.name == "Item & Location Options":
assert not [option for option in item_and_loc_options if option in group.options], \
f"Item and Location Options cannot be specified multiple times"
group.options.extend(item_and_loc_options)
item_group_in_list = True
else:
Expand All @@ -143,7 +150,7 @@ def __new__(mcs, name: str, bases: Tuple[type, ...], dct: Dict[str, Any]) -> Web
assert option not in seen_options, f"{option} found in two option groups"
seen_options.append(option)
if not item_group_in_list:
option_groups.append(OptionGroup("Item & Location Options", item_and_loc_options))
option_groups.append(OptionGroup("Item & Location Options", item_and_loc_options, True))
return super().__new__(mcs, name, bases, dct)


Expand Down
Loading