From 6537155a7c01282337b45bd66c989c455484fff4 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 29 Dec 2023 20:29:56 -0500 Subject: [PATCH] Support Toggle, DefaultOnToggle, and Choice options in weighted-options --- WebHostLib/misc.py | 10 ++ .../weightedOptions/weightedOptions.css | 66 +++---- .../weightedOptions/weightedOptions.css.map | 2 +- .../weightedOptions/weightedOptions.scss | 12 +- .../templates/weightedOptions/macros.html | 161 ++++++++++++++++-- .../weightedOptions/weightedOptions.html | 64 ++++++- 6 files changed, 255 insertions(+), 60 deletions(-) diff --git a/WebHostLib/misc.py b/WebHostLib/misc.py index df343c6e22d8..5f464777a114 100644 --- a/WebHostLib/misc.py +++ b/WebHostLib/misc.py @@ -52,9 +52,19 @@ def weighted_settings(): @app.route("/weighted-options") @cache.cached() def weighted_options(): + option_groups_by_world = {} + for world_name, world in AutoWorldRegister.world_types.items(): + world_options = world.options_dataclass.type_hints + option_groups = {option: option_group.name + for option_group in world.web.option_groups + for option in option_group.options} + for option_name, option in world_options.items(): + option_groups_by_world.setdefault(world_name, {}).setdefault(option_groups.get(option, "Game Options"), {})[option_name] = option + return render_template( "weightedOptions/weightedOptions.html", worlds=AutoWorldRegister.world_types, + option_groups_by_world=option_groups_by_world, issubclass=issubclass, Options=Options, ) diff --git a/WebHostLib/static/styles/weightedOptions/weightedOptions.css b/WebHostLib/static/styles/weightedOptions/weightedOptions.css index 31cef5a3e948..36a86864ad8d 100644 --- a/WebHostLib/static/styles/weightedOptions/weightedOptions.css +++ b/WebHostLib/static/styles/weightedOptions/weightedOptions.css @@ -5,7 +5,7 @@ html { scroll-padding-top: 90px; } -#weighted-settings { +#weighted-options { max-width: 1000px; margin-left: auto; margin-right: auto; @@ -14,27 +14,27 @@ html { padding: 1rem; color: #eeffeb; } -#weighted-settings h3 { +#weighted-options h3 { cursor: unset; } -#weighted-settings h3.option-group-header { +#weighted-options h3.option-group-header { margin-top: 0.75rem; font-weight: bold; } -#weighted-settings #games-wrapper { +#weighted-options #games-wrapper { width: 100%; } -#weighted-settings .setting-wrapper { +#weighted-options .option-wrapper { width: 100%; margin-bottom: 2rem; } -#weighted-settings .setting-wrapper .add-option-div { +#weighted-options .option-wrapper .add-option-div { display: flex; flex-direction: row; justify-content: flex-start; margin-bottom: 1rem; } -#weighted-settings .setting-wrapper .add-option-div button { +#weighted-options .option-wrapper .add-option-div button { width: auto; height: auto; margin: 0 0 0 0.15rem; @@ -42,66 +42,68 @@ html { border-radius: 4px; cursor: default; } -#weighted-settings .setting-wrapper .add-option-div button:active { +#weighted-options .option-wrapper .add-option-div button:active { margin-bottom: 1px; } -#weighted-settings p.setting-description { +#weighted-options p.option-description { margin: 0 0 1rem; } -#weighted-settings p.hint-text { +#weighted-options p.hint-text { margin: 0 0 1rem; font-style: italic; } -#weighted-settings .jump-link { +#weighted-options .jump-link { color: #ffef00; cursor: pointer; text-decoration: underline; } -#weighted-settings table { +#weighted-options table { width: 100%; + margin-top: 0.5rem; + margin-bottom: 1.5rem; } -#weighted-settings table th, #weighted-settings table td { +#weighted-options table th, #weighted-options table td { border: none; } -#weighted-settings table td { +#weighted-options table td { padding: 5px; } -#weighted-settings table .td-left { +#weighted-options table .td-left { font-family: LexendDeca-Regular, sans-serif; padding-right: 1rem; width: 200px; } -#weighted-settings table .td-middle { +#weighted-options table .td-middle { display: flex; flex-direction: column; justify-content: space-evenly; padding-right: 1rem; } -#weighted-settings table .td-right { +#weighted-options table .td-right { width: 4rem; text-align: right; } -#weighted-settings table .td-delete { +#weighted-options table .td-delete { width: 50px; text-align: right; } -#weighted-settings table .range-option-delete { +#weighted-options table .range-option-delete { cursor: pointer; } -#weighted-settings #weighted-settings-button-row { +#weighted-options #weighted-options-button-row { display: flex; flex-direction: row; justify-content: space-between; margin-top: 15px; } -#weighted-settings code { +#weighted-options code { background-color: #d9cd8e; border-radius: 4px; padding-left: 0.25rem; padding-right: 0.25rem; color: #000000; } -#weighted-settings #user-message { +#weighted-options #user-message { display: none; width: calc(100% - 8px); background-color: #ffe86b; @@ -110,11 +112,11 @@ html { padding: 4px; text-align: center; } -#weighted-settings #user-message.visible { +#weighted-options #user-message.visible { display: block; cursor: pointer; } -#weighted-settings h1 { +#weighted-options h1 { font-size: 2.5rem; font-weight: normal; border-bottom: 1px solid #ffffff; @@ -123,7 +125,7 @@ html { color: #ffffff; text-shadow: 1px 1px 4px #000000; } -#weighted-settings h2 { +#weighted-options h2 { font-size: 2rem; font-weight: normal; border-bottom: 1px solid #ffffff; @@ -133,37 +135,37 @@ html { text-transform: none; text-shadow: 1px 1px 2px #000000; } -#weighted-settings h3, #weighted-settings h4, #weighted-settings h5, #weighted-settings h6 { +#weighted-options h3, #weighted-options h4, #weighted-options h5, #weighted-options h6 { color: #ffffff; text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5); text-transform: none; } -#weighted-settings a { +#weighted-options a { color: #ffef00; cursor: pointer; } -#weighted-settings input:not([type]) { +#weighted-options input:not([type]) { border: 1px solid #000000; padding: 3px; border-radius: 3px; min-width: 150px; } -#weighted-settings input:not([type]):focus { +#weighted-options input:not([type]):focus { border: 1px solid #ffffff; } -#weighted-settings select { +#weighted-options select { border: 1px solid #000000; padding: 3px; border-radius: 3px; min-width: 150px; background-color: #ffffff; } -#weighted-settings .invisible { +#weighted-options .invisible { display: none; } @media all and (max-width: 1000px), all and (orientation: portrait) { - #weighted-settings .game-options { + #weighted-options .game-options { justify-content: flex-start; flex-wrap: wrap; } diff --git a/WebHostLib/static/styles/weightedOptions/weightedOptions.css.map b/WebHostLib/static/styles/weightedOptions/weightedOptions.css.map index 86b4e406522e..debf13ecac20 100644 --- a/WebHostLib/static/styles/weightedOptions/weightedOptions.css.map +++ b/WebHostLib/static/styles/weightedOptions/weightedOptions.css.map @@ -1 +1 @@ -{"version":3,"sourceRoot":"","sources":["weightedOptions.scss"],"names":[],"mappings":"AAAA;EACI;EACA;EACA;EACA;;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACI;;AAEA;EACI;EACA;;AAIR;EACI;;AAGJ;EACI;EACA;;AAEA;EACI;EACA;EACA;EACA;;AAEA;EACI;EACA;EACA;EACA;EACA;EACA;;AAEA;EACI;;AAOZ;EACI;;AAGJ;EACI;EACA;;AAIR;EACI;EACA;EACA;;AAGJ;EACI;;AAEA;EACI;;AAGJ;EACI;;AAGJ;EACI;EACA;EACA;;AAGJ;EACI;EACA;EACA;EACA;;AAGJ;EACI;EACA;;AAGJ;EACI;EACA;;AAGJ;EACI;;AAIR;EACI;EACA;EACA;EACA;;AAGJ;EACI;EACA;EACA;EACA;EACA;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACI;EACA;;AAIR;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAGJ;EACI;EACA;EACA;;AAGJ;EACI;EACA;;AAGJ;EACI;EACA;EACA;EACA;;AAEA;EACI;;AAIR;EACI;EACA;EACA;EACA;EACA;;AAGJ;EACI;;;AAIR;EACI;IACI;IACA;;EAGJ;IACI;IACA","file":"weightedOptions.css"} \ No newline at end of file +{"version":3,"sourceRoot":"","sources":["weightedOptions.scss"],"names":[],"mappings":"AAAA;EACI;EACA;EACA;EACA;;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACI;;AAEA;EACI;EACA;;AAIR;EACI;;AAGJ;EACI;EACA;;AAEA;EACI;EACA;EACA;EACA;;AAEA;EACI;EACA;EACA;EACA;EACA;EACA;;AAEA;EACI;;AAOZ;EACI;;AAGJ;EACI;EACA;;AAIR;EACI;EACA;EACA;;AAGJ;EACI;EACA;EACA;;AAEA;EACI;;AAGJ;EACI;;AAGJ;EACI;EACA;EACA;;AAGJ;EACI;EACA;EACA;EACA;;AAGJ;EACI;EACA;;AAGJ;EACI;EACA;;AAGJ;EACI;;AAIR;EACI;EACA;EACA;EACA;;AAGJ;EACI;EACA;EACA;EACA;EACA;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACI;EACA;;AAIR;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAGJ;EACI;EACA;EACA;;AAGJ;EACI;EACA;;AAGJ;EACI;EACA;EACA;EACA;;AAEA;EACI;;AAIR;EACI;EACA;EACA;EACA;EACA;;AAGJ;EACI;;;AAIR;EACI;IACI;IACA;;EAGJ;IACI;IACA","file":"weightedOptions.css"} \ No newline at end of file diff --git a/WebHostLib/static/styles/weightedOptions/weightedOptions.scss b/WebHostLib/static/styles/weightedOptions/weightedOptions.scss index a3845cfc14de..136de7f4377c 100644 --- a/WebHostLib/static/styles/weightedOptions/weightedOptions.scss +++ b/WebHostLib/static/styles/weightedOptions/weightedOptions.scss @@ -5,7 +5,7 @@ html{ scroll-padding-top: 90px; } -#weighted-settings{ +#weighted-options{ max-width: 1000px; margin-left: auto; margin-right: auto; @@ -27,7 +27,7 @@ html{ width: 100%; } - .setting-wrapper{ + .option-wrapper{ width: 100%; margin-bottom: 2rem; @@ -53,7 +53,7 @@ html{ } p{ - &.setting-description{ + &.option-description{ margin: 0 0 1rem; } @@ -71,6 +71,8 @@ html{ table{ width: 100%; + margin-top: 0.5rem; + margin-bottom: 1.5rem; th, td{ border: none; @@ -108,7 +110,7 @@ html{ } } - #weighted-settings-button-row{ + #weighted-options-button-row{ display: flex; flex-direction: row; justify-content: space-between; @@ -195,7 +197,7 @@ html{ } @media all and (max-width: 1000px), all and (orientation: portrait){ - #weighted-settings .game-options{ + #weighted-options .game-options{ justify-content: flex-start; flex-wrap: wrap; } diff --git a/WebHostLib/templates/weightedOptions/macros.html b/WebHostLib/templates/weightedOptions/macros.html index 8f2a1f71c8ff..9109ba326447 100644 --- a/WebHostLib/templates/weightedOptions/macros.html +++ b/WebHostLib/templates/weightedOptions/macros.html @@ -1,46 +1,134 @@ -{% macro Toggle(option_name, option) %} - +{% macro Toggle(world_name, option_name, option) %} + + + + + + + + + + + + + {{ RandomRow(world_name, option_name, option) }} + +
+ + + {% if option.default == 0 %} + 25 + {% else %} + 0 + {% endif %} +
+ + + {% if option.default == 1 %} + 25 + {% else %} + 0 + {% endif %} +
{% endmacro %} -{% macro DefaultOnToggle(option_name, option) %} +{% macro DefaultOnToggle(world_name, option_name, option) %} - {{ Toggle(option_name, option) }} + {{ Toggle(world_name, option_name, option) }} {% endmacro %} -{% macro Choice(option_name, option) %} - +{% macro Choice(world_name, option_name, option) %} + + + {% for id, name in option.name_lookup.items() %} + {% if name != 'random' %} + + + + + + {% endif %} + {% endfor %} + {{ RandomRow(world_name, option_name, option) }} + +
+ + + + + {% if option.default == id %} + 25 + {% else %} + 0 + {% endif %} +
{% endmacro %} -{% macro Range(option_name, option) %} +{% macro Range(world_name, option_name, option) %} {% endmacro %} -{% macro NamedRange(option_name, option) %} +{% macro NamedRange(world_name, option_name, option) %} {% endmacro %} -{% macro FreeText(option_name, option) %} +{% macro FreeText(world_name, option_name, option) %} {% endmacro %} -{% macro TextChoice(option_name, option) %} +{% macro TextChoice(world_name, option_name, option) %} {% endmacro %} -{% macro PlandoBosses(option_name, option) %} +{% macro PlandoBosses(world_name, option_name, option) %} - {{ TextChoice(option_name, option) }} + {{ TextChoice(world_name, option_name, option) }} {% endmacro %} -{% macro ItemDict(option_name, option, world) %} +{% macro ItemDict(world_name, option_name, option, world) %} {% endmacro %} -{% macro OptionList(option_name, option) %} +{% macro OptionList(world_name, option_name, option) %} {% endmacro %} -{% macro LocationSet(option_name, option, world) %} +{% macro LocationSet(world_name, option_name, option, world) %}
{% for group_name in world.location_name_groups.keys()|sort %} {% if group_name != "Everywhere" %} @@ -62,7 +150,7 @@
{% endmacro %} -{% macro ItemSet(option_name, option, world) %} +{% macro ItemSet(world_name, option_name, option, world) %}
{% for group_name in world.item_name_groups.keys()|sort %} {% if group_name != "Everything" %} @@ -84,7 +172,7 @@
{% endmacro %} -{% macro OptionSet(option_name, option) %} +{% macro OptionSet(world_name, option_name, option) %}
{% for key in option.valid_keys %}
@@ -94,3 +182,42 @@ {% endfor %}
{% endmacro %} + +{% macro OptionTitleTd(world_name, option_name, value) %} + + + +{% endmacro %} + +{% macro RandomRow(world_name, option_name, option) %} + + + + + + + + + {% if option.default == 'random' %} + 25 + {% else %} + 0 + {% endif %} + + +{% endmacro %} diff --git a/WebHostLib/templates/weightedOptions/weightedOptions.html b/WebHostLib/templates/weightedOptions/weightedOptions.html index 9acf5a1dd009..4e47378d7a7a 100644 --- a/WebHostLib/templates/weightedOptions/weightedOptions.html +++ b/WebHostLib/templates/weightedOptions/weightedOptions.html @@ -10,7 +10,7 @@ {% block body %} {% include 'header/grassHeader.html' %} -
+

Weighted Options

Weighted options allow you to choose how likely a particular option's value is to be used in game @@ -30,7 +30,7 @@

Weighted Options

Game Select

-

Choose which games you may be required to play.

+

Choose which games you may be required to play.

If a game's value is greater than zero, you may click its name to jump to that section.

@@ -51,12 +51,66 @@

Game Select

{% for world_name, world in worlds|dictsort %} -

{{ world_name }}

- Options will go here. + {% if not world.hidden and world.web.options_page == True %} +

{{ world_name }}

+ {% for group_name, option_group in option_groups_by_world[world_name].items() %} +

{{ group_name }}

+
+ {% for option_name, option in option_group.items() %} +
+

{{ option.display_name|default(option_name) }}

+
+ {{ option.__doc__ }} +
+ {% if issubclass(option, Options.Toggle) %} + {{ inputs.Toggle(world_name, option_name, option) }} + + {% elif issubclass(option, Options.DefaultOnToggle) %} + {{ inputs.DefaultOnToggle(world_name, option_name, option) }} + + {% elif issubclass(option, Options.PlandoBosses) %} + {{ inputs.PlandoBosses(world_name, option_name, option) }} + + {% elif issubclass(option, Options.TextChoice) %} + {{ inputs.TextChoice(world_name, option_name, option) }} + + {% elif issubclass(option, Options.Choice) %} + {{ inputs.Choice(world_name, option_name, option) }} + + {% elif issubclass(option, Options.NamedRange) %} + {{ inputs.NamedRange(world_name, option_name, option) }} + + {% elif issubclass(option, Options.Range) %} + {{ inputs.Range(world_name, option_name, option) }} + + {% elif issubclass(option, Options.FreeText) %} + {{ inputs.FreeText(world_name, option_name, option) }} + + {% elif issubclass(option, Options.ItemDict) and option.verify_item_name %} + {{ inputs.ItemDict(world_name, option_name, option, world) }} + + {% elif issubclass(option, Options.OptionList) and option.valid_keys %} + {{ inputs.OptionList(world_name, option_name, option) }} + + {% elif issubclass(option, Options.LocationSet) and option.verify_location_name %} + {{ inputs.LocationSet(world_name, option_name, option, world) }} + + {% elif issubclass(option, Options.ItemSet) and option.verify_item_name %} + {{ inputs.ItemSet(world_name, option_name, option, world) }} + + {% elif issubclass(option, Options.OptionSet) and option.valid_keys %} + {{ inputs.OptionSet(world_name, option_name, option) }} + + {% endif %} +
+ {% endfor %} +
+ {% endfor %} + {% endif %} {% endfor %}
-
+