Skip to content

Commit

Permalink
WebHost: weighted-options bugfixes (ArchipelagoMW#3448)
Browse files Browse the repository at this point in the history
* Fix improper css for word-break on player-options page

* Add default handling to weighted-options types

* Remove random-low/mid/high from Toggle, Choice, and TextChoice,

* Port key sorting for OptionList and OptionSet from player-options to weighted-options

* Ensure Choice and TextChoice values are set properly

* Remove debug line 🤦‍♂️
  • Loading branch information
LegendaryLinux authored Jun 3, 2024
1 parent c7eef13 commit 06e65c1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion WebHostLib/static/styles/playerOptions/playerOptions.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion WebHostLib/static/styles/playerOptions/playerOptions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ html{
border-radius: 8px;
padding: 1rem;
color: #eeffeb;
word-break: break-all;
word-break: break-word;

#player-options-header{
h1{
Expand Down
35 changes: 21 additions & 14 deletions WebHostLib/templates/weightedOptions/macros.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% macro Toggle(option_name, option) %}
<table>
<tbody>
{{ RangeRow(option_name, option, "No", "false") }}
{{ RangeRow(option_name, option, "Yes", "true") }}
{{ RandomRows(option_name, option) }}
{{ RangeRow(option_name, option, "No", "false", False, "true" if option.default else "false") }}
{{ RangeRow(option_name, option, "Yes", "true", False, "true" if option.default else "false") }}
{{ RandomRow(option_name, option) }}
</tbody>
</table>
{% endmacro %}
Expand All @@ -18,10 +18,10 @@
<tbody>
{% for id, name in option.name_lookup.items() %}
{% if name != 'random' %}
{{ RangeRow(option_name, option, option.get_option_name(id), name) }}
{{ RangeRow(option_name, option, option.get_option_name(id), name, False, name if option.get_option_name(option.default)|lower == name|lower else None) }}
{% endif %}
{% endfor %}
{{ RandomRows(option_name, option) }}
{{ RandomRow(option_name, option) }}
</tbody>
</table>
{% endmacro %}
Expand Down Expand Up @@ -72,7 +72,9 @@
</div>
<table>
<tbody>
<!-- This table to be filled by JS -->
{% if option.default %}
{{ RangeRow(option_name, option, option.default, option.default) }}
{% endif %}
</tbody>
</table>
</div>
Expand All @@ -90,10 +92,10 @@
<tbody>
{% for id, name in option.name_lookup.items() %}
{% if name != 'random' %}
{{ RangeRow(option_name, option, option.get_option_name(id), name) }}
{{ RangeRow(option_name, option, option.get_option_name(id), name, False, name if option.get_option_name(option.default)|lower == name else None) }}
{% endif %}
{% endfor %}
{{ RandomRows(option_name, option) }}
{{ RandomRow(option_name, option) }}
</tbody>
</table>
{% endmacro %}
Expand All @@ -112,7 +114,7 @@
type="number"
id="{{ option_name }}-{{ item_name }}-qty"
name="{{ option_name }}||{{ item_name }}"
value="0"
value="{{ option.default[item_name] if item_name in option.default else "0" }}"
/>
</div>
{% endfor %}
Expand All @@ -121,13 +123,14 @@

{% macro OptionList(option_name, option) %}
<div class="list-container">
{% for key in option.valid_keys|sort %}
{% for key in (option.valid_keys if option.valid_keys is ordered else option.valid_keys|sort) %}
<div class="list-entry">
<input
type="checkbox"
id="{{ option_name }}-{{ key }}"
name="{{ option_name }}||{{ key }}"
value="1"
checked="{{ "checked" if key in option.default else "" }}"
/>
<label for="{{ option_name }}-{{ key }}">
{{ key }}
Expand Down Expand Up @@ -183,7 +186,7 @@

{% macro OptionSet(option_name, option) %}
<div class="set-container">
{% for key in option.valid_keys|sort %}
{% for key in (option.valid_keys if option.valid_keys is ordered else 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>
Expand All @@ -200,13 +203,17 @@
</td>
{% endmacro %}

{% macro RandomRow(option_name, option, extra_column=False) %}
{{ RangeRow(option_name, option, "Random", "random") }}
{% 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) %}
{% macro RangeRow(option_name, option, display_value, value, can_delete=False, default_override=None) %}
<tr data-row="{{ option_name }}-{{ value }}-row" data-option-name="{{ option_name }}" data-value="{{ value }}">
<td class="td-left">
<label for="{{ option_name }}||{{ value }}">
Expand All @@ -220,7 +227,7 @@
name="{{ option_name }}||{{ value }}"
min="0"
max="50"
{% if option.default == value %}
{% if option.default == value or default_override == value %}
value="25"
{% else %}
value="0"
Expand All @@ -229,7 +236,7 @@
</td>
<td class="td-right">
<span id="{{ option_name }}||{{ value }}-value">
{% if option.default == value %}
{% if option.default == value or default_override == value %}
25
{% else %}
0
Expand Down

0 comments on commit 06e65c1

Please sign in to comment.