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: Massive overhaul of options pages #2614

Merged
merged 96 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
05a9003
Implement support for option groups. WebHost options pages still need…
LegendaryLinux Dec 7, 2023
8dbac70
Remove debug output
LegendaryLinux Dec 7, 2023
8a5d8b1
In-progress conversion of player-options to Jinja rendering
LegendaryLinux Dec 8, 2023
c9410cf
Support "Randomize" button without JS, transpile SCSS to CSS, include…
LegendaryLinux Dec 8, 2023
2a08d4f
Un-alphabetize options, add default group name for item/location Opti…
LegendaryLinux Dec 8, 2023
9d743f3
Re-flow UI generation to avoid printing rows with unsupported or inva…
LegendaryLinux Dec 10, 2023
38ed8b4
Support all remaining option types
LegendaryLinux Dec 10, 2023
8bbb4ff
Rendering improvements and CSS fixes for prettiness
LegendaryLinux Dec 10, 2023
da8422d
Wrap options in a form, update button styles, fix labels, disable inp…
LegendaryLinux Dec 11, 2023
ecdec3a
Minor CSS tweaks, as recommended by the designer
LegendaryLinux Dec 11, 2023
31dd5ed
Hide JS-required elements in noscript tag. Add JS reactivity to range…
LegendaryLinux Dec 13, 2023
9e5bf7d
Fix labels, add JS handling for TextChoice
LegendaryLinux Dec 13, 2023
eb2fe77
Make option groups collapsable
LegendaryLinux Dec 13, 2023
50d355a
PEP8 current option_groups progress (#2604)
alwaysintreble Dec 15, 2023
12541a0
It's ugly, but YAML generation is working
LegendaryLinux Dec 16, 2023
56dcf9b
Stop generating JSON files for player-options pages
LegendaryLinux Dec 16, 2023
2a3f95e
Do not include ItemDict entries whose values are zero
LegendaryLinux Dec 16, 2023
d1221eb
Properly format yaml output
LegendaryLinux Dec 16, 2023
aee73d3
Save options when form is submitted, load options on page load
LegendaryLinux Dec 16, 2023
bb19252
Fix options being omitted from the page if a group has an even number…
LegendaryLinux Dec 16, 2023
36b47e7
Implement generate-game, escape option descriptions
LegendaryLinux Dec 17, 2023
a86ec39
Fix "randomize" checkboxes not properly setting YAML options to "random"
LegendaryLinux Dec 17, 2023
17e7edb
Merge branch 'main' into option-groups
LegendaryLinux Dec 17, 2023
80ad67e
Add a separator between item/location groups and items/locations in t…
LegendaryLinux Dec 17, 2023
0de2aee
Implement option presets
LegendaryLinux Dec 18, 2023
cfa6846
Fix docs to detail what actually ended up happening
LegendaryLinux Dec 18, 2023
051c44a
implement option groups on webworld to allow dev sorting (#2616)
alwaysintreble Dec 18, 2023
0552f0a
Force extremely long item/location/option names with no spaces to tex…
LegendaryLinux Dec 18, 2023
0d9c643
Fix "randomize" button being too wide in single-column display, chang…
LegendaryLinux Dec 18, 2023
bfa220a
Update preset select to read "custom" when updating form inputs. Show…
LegendaryLinux Dec 19, 2023
25d9512
Merge branch 'main' into option-groups
LegendaryLinux Dec 19, 2023
f89d6a6
Merge branch 'main' into option-groups
LegendaryLinux Dec 23, 2023
d0d6927
Un-break weighted-options, add option group names to weighted options
LegendaryLinux Dec 27, 2023
98a125b
Nuke weighted-options. Set up framework to rebuild it in Jinja.
LegendaryLinux Dec 28, 2023
3398c2c
Generate styles with scss, remove styles which will be replaced, add …
LegendaryLinux Dec 29, 2023
6537155
Support Toggle, DefaultOnToggle, and Choice options in weighted-options
LegendaryLinux Dec 30, 2023
f977e41
Merge branch 'main' into option-groups
LegendaryLinux Jan 2, 2024
b100c8c
Implement expand/collapse without JS for worlds and option groups
LegendaryLinux Jan 3, 2024
f72e377
Properly style set options
LegendaryLinux Jan 3, 2024
e131d32
Merge branch 'main' into option-groups
LegendaryLinux Jan 11, 2024
5101b08
Implement Range and NamedRange. Also, CSS is hard.
LegendaryLinux Jan 12, 2024
844f332
Merge branch 'main' into option-groups
LegendaryLinux Jan 23, 2024
bdd8f6e
Add support for remaining option types. JS and backend still forthcom…
LegendaryLinux Jan 31, 2024
d94d81c
Merge branch 'main' into option-groups
LegendaryLinux Jan 31, 2024
1daffb1
Merge branch 'main' into option-groups
LegendaryLinux Feb 5, 2024
d6601cc
Merge branch 'main' into option-groups
LegendaryLinux Feb 7, 2024
ebf1dbb
Add JS functionality for collapsing game divs, populating span values…
LegendaryLinux Feb 7, 2024
9c61e7b
Merge branch 'main' into option-groups
LegendaryLinux Feb 23, 2024
0dde475
Support showing/hiding game divs based on range value for game
LegendaryLinux Feb 23, 2024
b11a3c6
Merge main into option-groups
LegendaryLinux Mar 16, 2024
cdab50e
Add support for adding/deleting range rows
LegendaryLinux Mar 16, 2024
338f968
Save settings to localStorage on form submission
LegendaryLinux Mar 16, 2024
f4e5f6a
Merge branch 'main' into option-groups
LegendaryLinux Mar 22, 2024
0e367ef
Save deleted options on form submission
LegendaryLinux Mar 23, 2024
1d9f9b5
Merge branch 'main' into option-groups
LegendaryLinux Apr 2, 2024
cf3ecd2
Merge branch main into player-options
LegendaryLinux May 3, 2024
7c77d79
Break weighted-options into a per-game page.
LegendaryLinux May 3, 2024
6bad629
Implement loading previous settings from localStorage on page load if…
LegendaryLinux May 3, 2024
b06355b
Weighted options can now generate YAML files and single-player games
LegendaryLinux May 3, 2024
ef94738
options pages now respect option visibility settings for simple and c…
LegendaryLinux May 3, 2024
9f941da
Merge branch 'main' into option-groups
LegendaryLinux May 3, 2024
ca162cf
Remove `/weighted-settings` redirect, fix weighted-options link on pl…
LegendaryLinux May 3, 2024
69bd223
Fix instance of AutoWorld not having access to proper `random`
LegendaryLinux May 3, 2024
363cca2
Catch instances of frozenset along with set
LegendaryLinux May 3, 2024
da6a278
Restore word-wrap in tooltips
LegendaryLinux May 3, 2024
d3f97a9
Fix word wrap in player-options labels
LegendaryLinux May 3, 2024
bd0653b
Add `dedent` filter to help with formatting tooltips in player-options
LegendaryLinux May 3, 2024
a046f5f
Do not change the ordering of keys when printing yaml files
LegendaryLinux May 3, 2024
ed19c63
Move necessary import out of conditional statement
LegendaryLinux May 3, 2024
a83ae54
Expand only the first option group by default on both options pages
LegendaryLinux May 3, 2024
d787b8a
Merge branch 'main' into option-groups
LegendaryLinux May 3, 2024
409f304
Respect option visibility when generating yaml template files
LegendaryLinux May 3, 2024
bd585a6
Swap to double quotes
LegendaryLinux May 3, 2024
c94a22f
Replace instances of `/weighted-settings` with `/weighted-options`, s…
LegendaryLinux May 3, 2024
46bec84
Strip newlines and spaces after applying dedent filter
LegendaryLinux May 4, 2024
fddea80
Fix documentation for option groups
LegendaryLinux May 4, 2024
9b0352d
Update site map
LegendaryLinux May 9, 2024
77a06ea
Update various docs
LegendaryLinux May 9, 2024
2e94d7a
Sort OptionSet lists alphabetically
LegendaryLinux May 9, 2024
43e1f1c
Minor style tweak
LegendaryLinux May 9, 2024
23867e6
Fix extremely long text overflowing tooltips
LegendaryLinux May 9, 2024
75c3aec
Convert player-options to use CSS grid instead of tables
LegendaryLinux May 9, 2024
f9fc6d7
Do not display link to weighted-options page on supported games if th…
LegendaryLinux May 9, 2024
8771a77
Update worlds/AutoWorld.py
LegendaryLinux May 9, 2024
b02ed4c
Merge branch 'main' into option-groups
LegendaryLinux May 15, 2024
136750a
Fix NamedRange options not being properly set if a preset it loaded
LegendaryLinux May 15, 2024
19e8297
Move option-presets route into options.py
LegendaryLinux May 15, 2024
f94a216
Include preset name in YAML if not "default" and not "custom"
LegendaryLinux May 15, 2024
9ff552e
Removed macros for PlandoBosses and DefaultOnToggle, as they were han…
LegendaryLinux May 15, 2024
4b13bfd
Fix not disabling custom inputs when the randomize button is clicked
LegendaryLinux May 15, 2024
8f413b8
Only sort OptionList and OptionSet valid_keys if they are unordered
LegendaryLinux May 16, 2024
a19c6a6
Merge branch 'main' into option-groups
LegendaryLinux May 16, 2024
7228262
Merge branch 'main' into option-groups
LegendaryLinux May 17, 2024
8bf7ce1
Quick style fixes for player-settings to give `select` elements `text…
LegendaryLinux May 17, 2024
ce2a0c5
Prevent showing a horizontal scroll bar on player-options if the brow…
LegendaryLinux May 17, 2024
fc6c7c2
Fix a bug in weighted-options which prevented inputting a negative va…
LegendaryLinux May 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions BaseClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,14 @@ class Tutorial(NamedTuple):
authors: List[str]


class OptionGroup(NamedTuple):
"""Define a grouping of options"""
name: str
"""Name of the group to categorize this option in for display on the WebHost and in generated YAMLS."""
options: List[Type[Options.Option]]
"""Options to be in the defined group. """


class PlandoOptions(IntFlag):
none = 0b0000
items = 0b0001
Expand Down
19 changes: 12 additions & 7 deletions Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class OptionError(ValueError):
pass


class Visibility(enum.IntFlag):
none = 0b0000
template = 0b0001
Expand Down Expand Up @@ -984,7 +984,7 @@ class CommonOptions(metaclass=OptionsMetaProperty):
def as_dict(self, *option_names: str, casing: str = "snake") -> typing.Dict[str, typing.Any]:
"""
Returns a dictionary of [str, Option.value]

:param option_names: names of the options to return
:param casing: case of the keys to return. Supports `snake`, `camel`, `pascal`, `kebab`
"""
Expand Down Expand Up @@ -1198,15 +1198,20 @@ def dictify_range(option: Range):

for game_name, world in AutoWorldRegister.world_types.items():
if not world.hidden or generate_hidden:
all_options: typing.Dict[str, AssembleOptions] = {
option_name: option for option_name, option in world.options_dataclass.type_hints.items()
if option.visibility & Visibility.template
}

option_groups = {option: option_group.name
for option_group in world.web.option_groups
for option in option_group.options}
ordered_groups = ["Game Options"]
[ordered_groups.append(group) for group in option_groups.values() if group not in ordered_groups]
grouped_options = {group: {} for group in ordered_groups}
for option_name, option in world.options_dataclass.type_hints.items():
grouped_options[option_groups.get(option, "Game Options")][option_name] = option
LegendaryLinux marked this conversation as resolved.
Show resolved Hide resolved

with open(local_path("data", "options.yaml")) as f:
file_data = f.read()
res = Template(file_data).render(
options=all_options,
option_groups=grouped_options,
__version__=__version__, game=game_name, yaml_dump=yaml.dump,
dictify_range=dictify_range,
)
Expand Down
2 changes: 1 addition & 1 deletion WebHostLib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ def register():

from WebHostLib.customserver import run_server_process
# to trigger app routing picking up on it
from . import tracker, upload, landing, check, generate, downloads, api, stats, misc, robots
from . import tracker, upload, landing, check, generate, downloads, api, stats, misc, robots, options

app.register_blueprint(api.api_endpoints)
38 changes: 22 additions & 16 deletions WebHostLib/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import os
from typing import List, Dict, Union

import flask
import json

import jinja2.exceptions
from flask import request, redirect, url_for, render_template, Response, session, abort, send_from_directory
from pony.orm import count, commit, db_session
Expand Down Expand Up @@ -37,23 +40,26 @@ def start_playing():
return render_template(f"startPlaying.html")


# TODO for back compat. remove around 0.4.5
@app.route("/weighted-settings")
def weighted_settings():
return redirect("weighted-options", 301)


@app.route("/weighted-options")
@cache.cached()
def weighted_options():
return render_template("weighted-options.html")


# Player options pages
@app.route("/games/<string:game>/player-options")
@app.route("/games/<string:game>/option-presets", methods=["GET"])
@cache.cached()
def player_options(game: str):
return render_template("player-options.html", game=game, theme=get_world_theme(game))
def option_presets(game):
LegendaryLinux marked this conversation as resolved.
Show resolved Hide resolved
world = AutoWorldRegister.world_types[game]
presets = {}

if world.web.options_presets:
presets = presets | world.web.options_presets

class SetEncoder(json.JSONEncoder):
def default(self, obj):
from collections.abc import Set
if isinstance(obj, Set):
return list(obj)
return json.JSONEncoder.default(self, obj)

json_data = json.dumps(presets, cls=SetEncoder)
response = flask.Response(json_data)
response.headers["Content-Type"] = "application/json"
return response


# Game Info Pages
Expand Down
Loading
Loading