WebHost: Massive overhaul of options pages (#2614)

* Implement support for option groups. WebHost options pages still need to be updated.

* Remove debug output

* In-progress conversion of player-options to Jinja rendering

* Support "Randomize" button without JS, transpile SCSS to CSS, include map file for later editors

* Un-alphabetize options, add default group name for item/location Option classes, implement more option types

* Re-flow UI generation to avoid printing rows with unsupported or invalid option types, add support for TextChoice options

* Support all remaining option types

* Rendering improvements and CSS fixes for prettiness

* Wrap options in a form, update button styles, fix labels, disable inputs where the default is random, nuke the JS

* Minor CSS tweaks, as recommended by the designer

* Hide JS-required elements in noscript tag. Add JS reactivity to range, named-range, and randomize buttons.

* Fix labels, add JS handling for TextChoice

* Make option groups collapsable

* PEP8 current option_groups progress (#2604)

* Make the python more PEP8 and remove unneeded imports

* remove LocationSet from `Item & Location Options` group

* It's ugly, but YAML generation is working

* Stop generating JSON files for player-options pages

* Do not include ItemDict entries whose values are zero

* Properly format yaml output

* Save options when form is submitted, load options on page load

* Fix options being omitted from the page if a group has an even number of options

* Implement generate-game, escape option descriptions

* Fix "randomize" checkboxes not properly setting YAML options to "random"

* Add a separator between item/location groups and items/locations in their respective lists

* Implement option presets

* Fix docs to detail what actually ended up happening

* implement option groups on webworld to allow dev sorting (#2616)

* Force extremely long item/location/option names with no spaces to text-wrap

* Fix "randomize" button being too wide in single-column display, change page header to include game name

* Update preset select to read "custom" when updating form inputs. Show error message if the user doesn't input a name

* Un-break weighted-options, add option group names to weighted options

* Nuke weighted-options. Set up framework to rebuild it in Jinja.

* Generate styles with scss, remove styles which will be replaced, add placeholders for worlds

* Support Toggle, DefaultOnToggle, and Choice options in weighted-options

* Implement expand/collapse without JS for worlds and option groups

* Properly style set options

* Implement Range and NamedRange. Also, CSS is hard.

* Add support for remaining option types. JS and backend still forthcoming.

* Add JS functionality for collapsing game divs, populating span values on range updates. Add <noscript> tag to warn users with JS disabled.

* Support showing/hiding game divs based on range value for game

* Add support for adding/deleting range rows

* Save settings to localStorage on form submission

* Save deleted options on form submission

* Break weighted-options into a per-game page.

- Break weighted-options into a per-game page
- Add "advanced options" links to supported games page
- Use details/summary tags on supported games, player-options, and weighted-options
- Fix bug preventing previously deleted rows from being removed on page load if JS is enabled
- Move route handling for options pages to options.py
- Remove world handling from weighted-options

* Implement loading previous settings from localStorage on page load if JS is enabled

* Weighted options can now generate YAML files and single-player games

* options pages now respect option visibility settings for simple and complex pages

* Remove `/weighted-settings` redirect, fix weighted-options link on player-options page

* Fix instance of AutoWorld not having access to proper `random`

* Catch instances of frozenset along with set

* Restore word-wrap in tooltips

* Fix word wrap in player-options labels

* Add `dedent` filter to help with formatting tooltips in player-options

* Do not change the ordering of keys when printing yaml files

* Move necessary import out of conditional statement

* Expand only the first option group by default on both options pages

* Respect option visibility when generating yaml template files

* Swap to double quotes

* Replace instances of `/weighted-settings` with `/weighted-options`, swap out incomplete links

* Strip newlines and spaces after applying dedent filter

* Fix documentation for option groups

* Update site map

* Update various docs

* Sort OptionSet lists alphabetically

* Minor style tweak

* Fix extremely long text overflowing tooltips

* Convert player-options to use CSS grid instead of tables

* Do not display link to weighted-options page on supported games if the options page is an external link

* Update worlds/AutoWorld.py

Bugfix by @alwaysintreble

Co-authored-by: Aaron Wagener <mmmcheese158@gmail.com>

* Fix NamedRange options not being properly set if a preset it loaded

* Move option-presets route into options.py

* Include preset name in YAML if not "default" and not "custom"

* Removed macros for PlandoBosses and DefaultOnToggle, as they were handled by their parent classes

* Fix not disabling custom inputs when the randomize button is clicked

* Only sort OptionList and OptionSet valid_keys if they are unordered

* Quick style fixes for player-settings to give `select` elements `text-overflow: ellipsis` and increase base size of left-column

* Prevent showing a horizontal scroll bar on player-options if the browser width was beneath a certain threshold

* Fix a bug in weighted-options which prevented inputting a negative value for new range inputs

---------

Co-authored-by: Aaron Wagener <mmmcheese158@gmail.com>
This commit is contained in:
Chris Wilson
2024-05-18 00:11:57 -04:00
committed by GitHub
parent 5fb0126754
commit 5e3c5dedf3
40 changed files with 2822 additions and 2662 deletions

View File

@@ -1,62 +0,0 @@
{% extends 'pageWrapper.html' %}
{% block head %}
<title>{{ game }} Options</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/markdown.css") }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/player-options.css") }}" />
<script type="application/ecmascript" src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script type="application/ecmascript" src="{{ url_for('static', filename="assets/md5.min.js") }}"></script>
<script type="application/ecmascript" src="{{ url_for('static', filename="assets/js-yaml.min.js") }}"></script>
<script type="application/ecmascript" src="{{ url_for('static', filename="assets/player-options.js") }}"></script>
{% endblock %}
{% block body %}
{% include 'header/'+theme+'Header.html' %}
<div id="player-options" class="markdown" data-game="{{ game }}">
<div id="user-message"></div>
<h1><span id="game-name">Player</span> Options</h1>
<p>Choose the options you would like to play with! You may generate a single-player game from this page,
or download an options file you can use to participate in a MultiWorld.</p>
<p>
A more advanced options configuration for all games can be found on the
<a href="/weighted-options">Weighted options</a> page.
<br />
A list of all games you have generated can be found on the <a href="/user-content">User Content Page</a>.
<br />
You may also download the
<a href="/static/generated/configs/{{ game }}.yaml">template file for this game</a>.
</p>
<div id="meta-options">
<div>
<label for="player-name">
Player Name: <span class="interactive" data-tooltip="This is the name you use to connect with your game. This is also known as your 'slot name'.">(?)</span>
</label>
<input id="player-name" placeholder="Player" data-key="name" maxlength="16" />
</div>
<div>
<label for="game-options-preset">
Options Preset: <span class="interactive" data-tooltip="Select from a list of developer-curated presets (if any) or reset all options to their defaults.">(?)</span>
</label>
<select id="game-options-preset">
<option value="__default">Defaults</option>
<option value="__custom" hidden>Custom</option>
</select>
</div>
</div>
<h2>Game Options</h2>
<div id="game-options">
<div id="game-options-left" class="left"></div>
<div id="game-options-right" class="right"></div>
</div>
<div id="player-options-button-row">
<button id="export-options">Export Options</button>
<button id="generate-game">Generate Game</button>
<button id="generate-race">Generate Race</button>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,210 @@
{% macro Toggle(option_name, option) %}
{{ OptionTitle(option_name, option) }}
<div class="select-container">
<select id="{{ option_name }}" name="{{ option_name }}" {{ "disabled" if option.default == "random" }}>
{% if option.default == 1 %}
<option value="false">No</option>
<option value="true" selected>Yes</option>
{% else %}
<option value="false" selected>No</option>
<option value="true">Yes</option>
{% endif %}
</select>
{{ RandomizeButton(option_name, option) }}
</div>
{% endmacro %}
{% macro Choice(option_name, option) %}
{{ OptionTitle(option_name, option) }}
<div class="select-container">
<select id="{{ option_name }}" name="{{ option_name }}" {{ "disabled" if option.default == "random" }}>
{% for id, name in option.name_lookup.items() %}
{% if name != "random" %}
{% if option.default == id %}
<option value="{{ name }}" selected>{{ option.get_option_name(id) }}</option>
{% else %}
<option value="{{ name }}">{{ option.get_option_name(id) }}</option>
{% endif %}
{% endif %}
{% endfor %}
</select>
{{ RandomizeButton(option_name, option) }}
</div>
{% endmacro %}
{% macro Range(option_name, option) %}
{{ OptionTitle(option_name, option) }}
<div class="range-container">
<input
type="range"
id="{{ option_name }}"
name="{{ option_name }}"
min="{{ option.range_start }}"
max="{{ option.range_end }}"
value="{{ option.default | default(option.range_start) if option.default != "random" else option.range_start }}"
{{ "disabled" if option.default == "random" }}
/>
<span id="{{ option_name }}-value" class="range-value js-required">
{{ option.default | default(option.range_start) if option.default != "random" else option.range_start }}
</span>
{{ RandomizeButton(option_name, option) }}
</div>
{% endmacro %}
{% macro NamedRange(option_name, option) %}
{{ OptionTitle(option_name, option) }}
<div class="named-range-container">
<select id="{{ option_name }}-select" data-option-name="{{ option_name }}" {{ "disabled" if option.default == "random" }}>
{% for key, val in option.special_range_names.items() %}
{% if option.default == val %}
<option value="{{ val }}" selected>{{ key }} ({{ val }})</option>
{% else %}
<option value="{{ val }}">{{ key }} ({{ val }})</option>
{% endif %}
{% endfor %}
<option value="custom" hidden>Custom</option>
</select>
<div class="named-range-wrapper">
<input
type="range"
id="{{ option_name }}"
name="{{ option_name }}"
min="{{ option.range_start }}"
max="{{ option.range_end }}"
value="{{ option.default | default(option.range_start) if option.default != "random" else option.range_start }}"
{{ "disabled" if option.default == "random" }}
/>
<span id="{{ option_name }}-value" class="range-value js-required">
{{ option.default | default(option.range_start) if option.default != "random" else option.range_start }}
</span>
{{ RandomizeButton(option_name, option) }}
</div>
</div>
{% endmacro %}
{% macro FreeText(option_name, option) %}
{{ OptionTitle(option_name, option) }}
<div class="free-text-container">
<input type="text" id="{{ option_name }}" name="{{ option_name }}" value="{{ option.default }}" />
</div>
{% endmacro %}
{% macro TextChoice(option_name, option) %}
{{ OptionTitle(option_name, option) }}
<div class="text-choice-container">
<div class="text-choice-wrapper">
<select id="{{ option_name }}" name="{{ option_name }}" {{ "disabled" if option.default == "random" }}>
{% for id, name in option.name_lookup.items()|sort %}
{% if name != "random" %}
{% if option.default == id %}
<option value="{{ name }}" selected>{{ option.get_option_name(id) }}</option>
{% else %}
<option value="{{ name }}">{{ option.get_option_name(id) }}</option>
{% endif %}
{% endif %}
{% endfor %}
<option value="custom" hidden>Custom</option>
</select>
{{ RandomizeButton(option_name, option) }}
</div>
<input type="text" id="{{ option_name }}-custom" name="{{ option_name }}-custom" data-option-name="{{ option_name }}" placeholder="Custom value..." />
</div>
{% endmacro %}
{% macro ItemDict(option_name, option, world) %}
{{ OptionTitle(option_name, option) }}
<div class="option-container">
{% for item_name in world.item_names|sort %}
<div class="option-entry">
<label for="{{ option_name }}-{{ item_name }}-qty">{{ item_name }}</label>
<input type="number" id="{{ option_name }}-{{ item_name }}-qty" name="{{ option_name }}||{{ item_name }}||qty" value="{{ option.default[item_name]|default("0") }}" data-option-name="{{ option_name }}" data-item-name="{{ item_name }}" />
</div>
{% endfor %}
</div>
{% endmacro %}
{% macro OptionList(option_name, option) %}
{{ OptionTitle(option_name, option) }}
<div class="option-container">
{% for key in (option.valid_keys if option.valid_keys is ordered else option.valid_keys|sort) %}
<div class="option-entry">
<input type="checkbox" id="{{ option_name }}-{{ key }}" name="{{ option_name }}" value="{{ key }}" {{ "checked" if key in option.default }} />
<label for="{{ option_name }}-{{ key }}">{{ key }}</label>
</div>
{% endfor %}
</div>
{% endmacro %}
{% macro LocationSet(option_name, option, world) %}
{{ OptionTitle(option_name, option) }}
<div class="option-container">
{% for group_name in world.location_name_groups.keys()|sort %}
{% if group_name != "Everywhere" %}
<div class="option-entry">
<input type="checkbox" id="{{ option_name }}-{{ group_name }}" name="{{ option_name }}" value="{{ group_name }}" {{ "checked" if grop_name in option.default }} />
<label for="{{ option_name }}-{{ group_name }}">{{ group_name }}</label>
</div>
{% endif %}
{% endfor %}
{% if world.location_name_groups.keys()|length > 1 %}
<div class="option-divider">&nbsp;</div>
{% endif %}
{% for location_name in world.location_names|sort %}
<div class="option-entry">
<input type="checkbox" id="{{ option_name }}-{{ location_name }}" name="{{ option_name }}" value="{{ location_name }}" {{ "checked" if location_name in option.default }} />
<label for="{{ option_name }}-{{ location_name }}">{{ location_name }}</label>
</div>
{% endfor %}
</div>
{% endmacro %}
{% macro ItemSet(option_name, option, world) %}
{{ OptionTitle(option_name, option) }}
<div class="option-container">
{% for group_name in world.item_name_groups.keys()|sort %}
{% if group_name != "Everything" %}
<div class="option-entry">
<input type="checkbox" id="{{ option_name }}-{{ group_name }}" name="{{ option_name }}" value="{{ group_name }}" {{ "checked" if group_name in option.default }} />
<label for="{{ option_name }}-{{ group_name }}">{{ group_name }}</label>
</div>
{% endif %}
{% endfor %}
{% if world.item_name_groups.keys()|length > 1 %}
<div class="option-divider">&nbsp;</div>
{% endif %}
{% for item_name in world.item_names|sort %}
<div class="option-entry">
<input type="checkbox" id="{{ option_name }}-{{ item_name }}" name="{{ option_name }}" value="{{ item_name }}" {{ "checked" if item_name in option.default }} />
<label for="{{ option_name }}-{{ item_name }}">{{ item_name }}</label>
</div>
{% endfor %}
</div>
{% endmacro %}
{% macro OptionSet(option_name, option) %}
{{ OptionTitle(option_name, option) }}
<div class="option-container">
{% for key in (option.valid_keys if option.valid_keys is ordered else option.valid_keys|sort) %}
<div class="option-entry">
<input type="checkbox" id="{{ option_name }}-{{ key }}" name="{{ option_name }}" value="{{ key }}" {{ "checked" if key in option.default }} />
<label for="{{ option_name }}-{{ key }}">{{ key }}</label>
</div>
{% endfor %}
</div>
{% endmacro %}
{% macro OptionTitle(option_name, option) %}
<label for="{{ option_name }}">
{{ option.display_name|default(option_name) }}:
<span class="interactive" data-tooltip="{% filter dedent %}{{(option.__doc__ | default("Please document me!"))|escape }}{% endfilter %}">(?)</span>
</label>
{% endmacro %}
{% macro RandomizeButton(option_name, option) %}
<div class="randomize-button" data-tooltip="Toggle randomization for this option!">
<label for="random-{{ option_name }}">
<input type="checkbox" id="random-{{ option_name }}" name="random-{{ option_name }}" class="randomize-checkbox" data-option-name="{{ option_name }}" {{ "checked" if option.default == "random" }} />
🎲
</label>
</div>
{% endmacro %}

View File

@@ -0,0 +1,166 @@
{% extends 'pageWrapper.html' %}
{% import 'playerOptions/macros.html' as inputs %}
{% block head %}
<title>{{ world_name }} Options</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/playerOptions/playerOptions.css") }}" />
<script type="application/ecmascript" src="{{ url_for('static', filename="assets/md5.min.js") }}"></script>
<script type="application/ecmascript" src="{{ url_for('static', filename="assets/js-yaml.min.js") }}"></script>
<script type="application/ecmascript" src="{{ url_for('static', filename="assets/playerOptions.js") }}"></script>
<noscript>
<style>
.js-required{
display: none;
}
</style>
</noscript>
{% endblock %}
{% block body %}
{% include 'header/'+theme+'Header.html' %}
<div id="player-options" class="markdown" data-game="{{ world_name }}" data-presets="{{ presets }}">
<noscript>
<div class="js-warning-banner">
This page has reduced functionality without JavaScript.
</div>
</noscript>
<div id="user-message">{{ message }}</div>
<div id="player-options-header">
<h1>{{ world_name }}</h1>
<h1>Player Options</h1>
</div>
<p>Choose the options you would like to play with! You may generate a single-player game from this page,
or download an options file you can use to participate in a MultiWorld.</p>
<p>
A more advanced options configuration for all games can be found on the
<a href="weighted-options">Weighted options</a> page.
<br />
A list of all games you have generated can be found on the <a href="/user-content">User Content Page</a>.
<br />
You may also download the
<a href="/static/generated/configs/{{ world_name }}.yaml">template file for this game</a>.
</p>
<form id="options-form" method="post" enctype="application/x-www-form-urlencoded" action="generate-yaml">
<div id="meta-options">
<div>
<label for="player-name">
Player Name: <span class="interactive" data-tooltip="This is the name you use to connect with your game. This is also known as your 'slot name'.">(?)</span>
</label>
<input id="player-name" placeholder="Player" name="name" maxlength="16" />
</div>
<div class="js-required">
<label for="game-options-preset">
Options Preset: <span class="interactive" data-tooltip="Select from a list of developer-curated presets (if any) or reset all options to their defaults.">(?)</span>
</label>
<select id="game-options-preset" name="game-options-preset" disabled>
<option value="default">Default</option>
{% for preset_name in world.web.options_presets %}
<option value="{{ preset_name }}">{{ preset_name }}</option>
{% endfor %}
<option value="custom" hidden>Custom</option>
</select>
</div>
</div>
<div id="option-groups">
{% for group_name, group_options in option_groups.items() %}
<details class="group-container" {% if loop.index == 1 %}open{% endif %}>
<summary class="h2">{{ group_name }}</summary>
<div class="game-options">
<div class="left">
{% for option_name, option in group_options.items() %}
{% if loop.index <= (loop.length / 2)|round(0,"ceil") %}
{% if issubclass(option, Options.Toggle) %}
{{ inputs.Toggle(option_name, option) }}
{% elif issubclass(option, Options.TextChoice) %}
{{ inputs.TextChoice(option_name, option) }}
{% elif issubclass(option, Options.Choice) %}
{{ inputs.Choice(option_name, option) }}
{% elif issubclass(option, Options.NamedRange) %}
{{ inputs.NamedRange(option_name, option) }}
{% elif issubclass(option, Options.Range) %}
{{ inputs.Range(option_name, option) }}
{% elif issubclass(option, Options.FreeText) %}
{{ inputs.FreeText(option_name, option) }}
{% elif issubclass(option, Options.ItemDict) and option.verify_item_name %}
{{ inputs.ItemDict(option_name, option, world) }}
{% elif issubclass(option, Options.OptionList) and option.valid_keys %}
{{ inputs.OptionList(option_name, option) }}
{% elif issubclass(option, Options.LocationSet) and option.verify_location_name %}
{{ inputs.LocationSet(option_name, option, world) }}
{% elif issubclass(option, Options.ItemSet) and option.verify_item_name %}
{{ inputs.ItemSet(option_name, option, world) }}
{% elif issubclass(option, Options.OptionSet) and option.valid_keys %}
{{ inputs.OptionSet(option_name, option) }}
{% endif %}
{% endif %}
{% endfor %}
</div>
<div class="right">
{% for option_name, option in group_options.items() %}
{% if loop.index > (loop.length / 2)|round(0,"ceil") %}
{% if issubclass(option, Options.Toggle) %}
{{ inputs.Toggle(option_name, option) }}
{% elif issubclass(option, Options.TextChoice) %}
{{ inputs.TextChoice(option_name, option) }}
{% elif issubclass(option, Options.Choice) %}
{{ inputs.Choice(option_name, option) }}
{% elif issubclass(option, Options.NamedRange) %}
{{ inputs.NamedRange(option_name, option) }}
{% elif issubclass(option, Options.Range) %}
{{ inputs.Range(option_name, option) }}
{% elif issubclass(option, Options.FreeText) %}
{{ inputs.FreeText(option_name, option) }}
{% elif issubclass(option, Options.ItemDict) and option.verify_item_name %}
{{ inputs.ItemDict(option_name, option, world) }}
{% elif issubclass(option, Options.OptionList) and option.valid_keys %}
{{ inputs.OptionList(option_name, option) }}
{% elif issubclass(option, Options.LocationSet) and option.verify_location_name %}
{{ inputs.LocationSet(option_name, option, world) }}
{% elif issubclass(option, Options.ItemSet) and option.verify_item_name %}
{{ inputs.ItemSet(option_name, option, world) }}
{% elif issubclass(option, Options.OptionSet) and option.valid_keys %}
{{ inputs.OptionSet(option_name, option) }}
{% endif %}
{% endif %}
{% endfor %}
</div>
</div>
</details>
{% endfor %}
</div>
<div id="player-options-button-row">
<input type="submit" name="intent-export" value="Export Options" />
<input type="submit" name="intent-generate" value="Generate Single-Player Game">
</div>
</form>
</div>
{% endblock %}

View File

@@ -24,7 +24,6 @@
<li><a href="/games">Supported Games Page</a></li>
<li><a href="/tutorial">Tutorials Page</a></li>
<li><a href="/user-content">User Content</a></li>
<li><a href="/weighted-options">Weighted Options Page</a></li>
<li><a href="{{url_for('stats')}}">Game Statistics</a></li>
<li><a href="/glossary/en">Glossary</a></li>
</ul>
@@ -50,8 +49,12 @@
<ul>
{% for game in games | title_sorted %}
{% if game['has_settings'] %}
<li><a href="{{ url_for('player_options', game=game['title']) }}">{{ game['title'] }}</a></li>
{% endif %}
<li>{{ game['title'] }}</li>
<ul>
<li><a href="{{ url_for('player_options', game=game['title']) }}">Player Options</a></li>
<li><a href="{{ url_for('weighted_options', game=game['title']) }}">Weighted Options</a></li>
</ul>
{% endif %}
{% endfor %}
</ul>
</div>

View File

@@ -41,10 +41,8 @@
</div>
{% for game_name in worlds | title_sorted %}
{% set world = worlds[game_name] %}
<h2 class="collapse-toggle" data-game="{{ game_name }}">
<span class="collapse-arrow"></span>{{ game_name }}
</h2>
<p class="collapsed">
<details data-game="{{ game_name }}">
<summary class="h2">{{ game_name }}</summary>
{{ world.__doc__ | default("No description provided.", true) }}<br />
<a href="{{ url_for("game_info", game=game_name, lang="en") }}">Game Page</a>
{% if world.web.tutorials %}
@@ -53,16 +51,18 @@
{% endif %}
{% if world.web.options_page is string %}
<span class="link-spacer">|</span>
<a href="{{ world.web.options_page }}">Options Page</a>
<a href="{{ world.web.options_page }}">Options Page (External Link)</a>
{% elif world.web.options_page %}
<span class="link-spacer">|</span>
<a href="{{ url_for("player_options", game=game_name) }}">Options Page</a>
<span class="link-spacer">|</span>
<a href="{{ url_for("weighted_options", game=game_name) }}">Advanced Options</a>
{% endif %}
{% if world.web.bug_report_page %}
<span class="link-spacer">|</span>
<a href="{{ world.web.bug_report_page }}">Report a Bug</a>
{% endif %}
</p>
</details>
{% endfor %}
</div>
{% endblock %}

View File

@@ -1,48 +0,0 @@
{% extends 'pageWrapper.html' %}
{% block head %}
<title>{{ game }} Options</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/markdown.css") }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/weighted-options.css") }}" />
<script type="application/ecmascript" src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script type="application/ecmascript" src="{{ url_for('static', filename="assets/md5.min.js") }}"></script>
<script type="application/ecmascript" src="{{ url_for('static', filename="assets/js-yaml.min.js") }}"></script>
<script type="application/ecmascript" src="{{ url_for('static', filename="assets/weighted-options.js") }}"></script>
{% endblock %}
{% block body %}
{% include 'header/grassHeader.html' %}
<div id="weighted-settings" class="markdown" data-game="{{ game }}">
<div id="user-message"></div>
<h1>Weighted Options</h1>
<p>Weighted options allow you to choose how likely a particular option is to be used in game generation.
The higher an option is weighted, the more likely the option will be chosen. Think of them like
entries in a raffle.</p>
<p>Choose the games and options you would like to play with! You may generate a single-player game from
this page, or download an options file you can use to participate in a MultiWorld.</p>
<p>A list of all games you have generated can be found on the <a href="/user-content">User Content</a>
page.</p>
<p><label for="player-name">Please enter your player name. This will appear in-game as you send and receive
items if you are playing in a MultiWorld.</label><br />
<input id="player-name" placeholder="Player Name" data-key="name" maxlength="16" />
</p>
<div id="game-choice">
<!-- User chooses games by weight -->
</div>
<!-- To be generated and populated per-game with weight > 0 -->
<div id="games-wrapper">
</div>
<div id="weighted-settings-button-row">
<button id="export-options">Export Options</button>
<button id="generate-game">Generate Game</button>
<button id="generate-race">Generate Race</button>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,249 @@
{% macro Toggle(option_name, option) %}
<table>
<tbody>
{{ RangeRow(option_name, option, "No", "false") }}
{{ RangeRow(option_name, option, "Yes", "true") }}
{{ RandomRows(option_name, option) }}
</tbody>
</table>
{% endmacro %}
{% macro DefaultOnToggle(option_name, option) %}
<!-- Toggle handles defaults properly, so we just reuse that -->
{{ Toggle(option_name, option) }}
{% endmacro %}
{% macro Choice(option_name, option) %}
<table>
<tbody>
{% for id, name in option.name_lookup.items() %}
{% if name != 'random' %}
{{ RangeRow(option_name, option, option.get_option_name(id), name) }}
{% endif %}
{% endfor %}
{{ RandomRows(option_name, option) }}
</tbody>
</table>
{% endmacro %}
{% macro Range(option_name, option) %}
<div class="hint-text js-required">
This is a range option.
<br /><br />
Accepted values:<br />
Normal range: {{ option.range_start }} - {{ option.range_end }}
{% if option.special_range_names %}
<br /><br />
The following values has special meaning, and may fall outside the normal range.
<ul>
{% for name, value in option.special_range_names.items() %}
<li>{{ value }}: {{ name }}</li>
{% endfor %}
</ul>
{% endif %}
<div class="add-option-div">
<input type="number" class="range-option-value" data-option="{{ option_name }}" />
<button class="add-range-option-button" data-option="{{ option_name }}">Add</button>
</div>
</div>
<table class="range-rows" data-option="{{ option_name }}">
<tbody>
{{ RangeRow(option_name, option, option.range_start, option.range_start, True) }}
{% if option.range_start < option.default < option.range_end %}
{{ RangeRow(option_name, option, option.default, option.default, True) }}
{% endif %}
{{ RangeRow(option_name, option, option.range_end, option.range_end, True) }}
{{ RandomRows(option_name, option) }}
</tbody>
</table>
{% endmacro %}
{% macro NamedRange(option_name, option) %}
<!-- Range is able to properly handle NamedDRange options -->
{{ Range(option_name, option) }}
{% endmacro %}
{% macro FreeText(option_name, option) %}
<div class="hint-text">
This option allows custom values only. Please enter your desired values below.
<div class="custom-value-wrapper">
<input class="custom-value" data-option="{{ option_name }}" placeholder="Custom Value" />
<button data-option="{{ option_name }}">Add</button>
</div>
<table>
<tbody>
<!-- This table to be filled by JS -->
</tbody>
</table>
</div>
{% endmacro %}
{% macro TextChoice(option_name, option) %}
<div class="hint-text">
Custom values are also allowed for this option. To create one, enter it into the input box below.
<div class="custom-value-wrapper">
<input class="custom-value" data-option="{{ option_name }}" placeholder="Custom Value" />
<button data-option="{{ option_name }}">Add</button>
</div>
</div>
<table>
<tbody>
{% for id, name in option.name_lookup.items() %}
{% if name != 'random' %}
{{ RangeRow(option_name, option, option.get_option_name(id), name) }}
{% endif %}
{% endfor %}
{{ RandomRows(option_name, option) }}
</tbody>
</table>
{% endmacro %}
{% macro PlandoBosses(option_name, option) %}
<!-- PlandoBosses is handled by its parent, TextChoice -->
{{ TextChoice(option_name, option) }}
{% endmacro %}
{% macro ItemDict(option_name, option, world) %}
<div class="dict-container">
{% for item_name in world.item_names|sort %}
<div class="dict-entry">
<label for="{{ option_name }}-{{ item_name }}-qty">{{ item_name }}</label>
<input
type="number"
id="{{ option_name }}-{{ item_name }}-qty"
name="{{ option_name }}||{{ item_name }}"
value="0"
/>
</div>
{% endfor %}
</div>
{% endmacro %}
{% macro OptionList(option_name, option) %}
<div class="list-container">
{% for key in option.valid_keys|sort %}
<div class="list-entry">
<input
type="checkbox"
id="{{ option_name }}-{{ key }}"
name="{{ option_name }}||{{ key }}"
value="1"
/>
<label for="{{ option_name }}-{{ key }}">
{{ key }}
</label>
</div>
{% endfor %}
</div>
{% endmacro %}
{% macro LocationSet(option_name, option, world) %}
<div class="set-container">
{% for group_name in world.location_name_groups.keys()|sort %}
{% if group_name != "Everywhere" %}
<div class="set-entry">
<input type="checkbox" id="{{ option_name }}-{{ group_name }}" name="{{ option_name }}||{{ group_name }}" value="1" {{ "checked" if grop_name in option.default }} />
<label for="{{ option_name }}-{{ group_name }}">{{ group_name }}</label>
</div>
{% endif %}
{% endfor %}
{% if world.location_name_groups.keys()|length > 1 %}
<div class="divider">&nbsp;</div>
{% endif %}
{% for location_name in world.location_names|sort %}
<div class="set-entry">
<input type="checkbox" id="{{ option_name }}-{{ location_name }}" name="{{ option_name }}||{{ location_name }}" value="1" {{ "checked" if location_name in option.default }} />
<label for="{{ option_name }}-{{ location_name }}">{{ location_name }}</label>
</div>
{% endfor %}
</div>
{% endmacro %}
{% macro ItemSet(option_name, option, world) %}
<div class="set-container">
{% for group_name in world.item_name_groups.keys()|sort %}
{% if group_name != "Everything" %}
<div class="set-entry">
<input type="checkbox" id="{{ option_name }}-{{ group_name }}" name="{{ option_name }}||{{ group_name }}" value="1" {{ "checked" if group_name in option.default }} />
<label for="{{ option_name }}-{{ group_name }}">{{ group_name }}</label>
</div>
{% endif %}
{% endfor %}
{% if world.item_name_groups.keys()|length > 1 %}
<div class="set-divider">&nbsp;</div>
{% endif %}
{% for item_name in world.item_names|sort %}
<div class="set-entry">
<input type="checkbox" id="{{ option_name }}-{{ item_name }}" name="{{ option_name }}||{{ item_name }}" value="1" {{ "checked" if item_name in option.default }} />
<label for="{{ option_name }}-{{ item_name }}">{{ item_name }}</label>
</div>
{% endfor %}
</div>
{% endmacro %}
{% macro OptionSet(option_name, option) %}
<div class="set-container">
{% for key in option.valid_keys|sort %}
<div class="set-entry">
<input type="checkbox" id="{{ option_name }}-{{ key }}" name="{{ option_name }}||{{ key }}" value="1" {{ "checked" if key in option.default }} />
<label for="{{ option_name }}-{{ key }}">{{ key }}</label>
</div>
{% endfor %}
</div>
{% endmacro %}
{% macro OptionTitleTd(option_name, value) %}
<td class="td-left">
<label for="{{ option_name }}||{{ value }}">
{{ option.display_name|default(option_name) }}
</label>
</td>
{% endmacro %}
{% macro RandomRows(option_name, option, extra_column=False) %}
{% for key, value in {"Random": "random", "Random (Low)": "random-low", "Random (Middle)": "random-middle", "Random (High)": "random-high"}.items() %}
{{ RangeRow(option_name, option, key, value) }}
{% endfor %}
{% endmacro %}
{% macro RangeRow(option_name, option, display_value, value, can_delete=False) %}
<tr data-row="{{ option_name }}-{{ value }}-row" data-option-name="{{ option_name }}" data-value="{{ value }}">
<td class="td-left">
<label for="{{ option_name }}||{{ value }}">
{{ display_value }}
</label>
</td>
<td class="td-middle">
<input
type="range"
id="{{ option_name }}||{{ value }}"
name="{{ option_name }}||{{ value }}"
min="0"
max="50"
{% if option.default == value %}
value="25"
{% else %}
value="0"
{% endif %}
/>
</td>
<td class="td-right">
<span id="{{ option_name }}||{{ value }}-value">
{% if option.default == value %}
25
{% else %}
0
{% endif %}
</span>
</td>
{% if can_delete %}
<td>
<span class="range-option-delete js-required" data-target="{{ option_name }}-{{ value }}-row">
</span>
</td>
{% else %}
<td><!-- This td empty on purpose --></td>
{% endif %}
</tr>
{% endmacro %}

View File

@@ -0,0 +1,119 @@
{% extends 'pageWrapper.html' %}
{% import 'weightedOptions/macros.html' as inputs %}
{% block head %}
<title>{{ world_name }} Weighted Options</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/markdown.css") }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/weightedOptions/weightedOptions.css") }}" />
<script type="application/ecmascript" src="{{ url_for('static', filename="assets/weightedOptions.js") }}"></script>
<noscript>
<style>
.js-required{
display: none;
}
</style>
</noscript>
{% endblock %}
{% block body %}
{% include 'header/'+theme+'Header.html' %}
<div id="weighted-options" class="markdown" data-game="{{ world_name }}">
<noscript>
<div class="js-warning-banner">
This page has reduced functionality without JavaScript.
</div>
</noscript>
<div id="user-message"></div>
<div id="weighted-options-header">
<h1>{{ world_name }}</h1>
<h1>Weighted Options</h1>
</div>
<form id="weighted-options-form" method="post" enctype="application/x-www-form-urlencoded" action="generate-weighted-yaml">
<p>Weighted options allow you to choose how likely a particular option&apos;s value is to be used in game
generation. The higher a value is weighted, the more likely the option will be chosen. Think of them like
entries in a raffle.</p>
<p>Choose the options you would like to play with! You may generate a single-player game from
this page, or download an options file you can use to participate in a MultiWorld.</p>
<p>A list of all games you have generated can be found on the <a href="/user-content">User Content</a>
page.</p>
<p><label for="player-name">Please enter your player name. This will appear in-game as you send and receive
items if you are playing in a MultiWorld.</label><br />
<input id="player-name" placeholder="Player Name" name="name" maxlength="16" />
</p>
<div id="{{ world_name }}-container">
{% for group_name, group_options in option_groups.items() %}
<details {% if loop.index == 1 %}open{% endif %}>
<summary class="h2">{{ group_name }}</summary>
{% for option_name, option in group_options.items() %}
<div class="option-wrapper">
<h4>{{ option.display_name|default(option_name) }}</h4>
<div class="option-description">
{{ option.__doc__ }}
</div>
{% if issubclass(option, Options.Toggle) %}
{{ inputs.Toggle(option_name, option) }}
{% elif issubclass(option, Options.DefaultOnToggle) %}
{{ inputs.DefaultOnToggle(option_name, option) }}
{% elif issubclass(option, Options.PlandoBosses) %}
{{ inputs.PlandoBosses(option_name, option) }}
{% elif issubclass(option, Options.TextChoice) %}
{{ inputs.TextChoice(option_name, option) }}
{% elif issubclass(option, Options.Choice) %}
{{ inputs.Choice(option_name, option) }}
{% elif issubclass(option, Options.NamedRange) %}
{{ inputs.NamedRange(option_name, option) }}
{% elif issubclass(option, Options.Range) %}
{{ inputs.Range(option_name, option) }}
{% elif issubclass(option, Options.FreeText) %}
{{ inputs.FreeText(option_name, option) }}
{% elif issubclass(option, Options.ItemDict) and option.verify_item_name %}
{{ inputs.ItemDict(option_name, option, world) }}
{% elif issubclass(option, Options.OptionList) and option.valid_keys %}
{{ inputs.OptionList(option_name, option) }}
{% elif issubclass(option, Options.LocationSet) and option.verify_location_name %}
{{ inputs.LocationSet(option_name, option, world) }}
{% elif issubclass(option, Options.ItemSet) and option.verify_item_name %}
{{ inputs.ItemSet(option_name, option, world) }}
{% elif issubclass(option, Options.OptionSet) and option.valid_keys %}
{{ inputs.OptionSet(option_name, option) }}
{% else %}
<div class="unsupported-option">
This option is not supported. Please edit your .yaml file manually.
</div>
{% endif %}
</div>
{% endfor %}
</details>
{% endfor %}
</div>
<div id="weighted-options-button-row">
<input type="submit" name="intent-export" value="Export Options" />
<input type="submit" name="intent-generate" value="Generate Single-Player Game">
</div>
</form>
</div>
{% endblock %}