Skip to content

Commit fa9dbc7

Browse files
NewSoupVisflavelle
authored andcommitted
WebHost: Fix Named Range displays on Player Options page (ArchipelagoMW#3521)
* Player Options: Fix Named Range displays * Also add validation to the NamedRange class itself * Don't break Stardew * Comment * Do replace first so title works correctly * Bring change to Weighted Options as well
1 parent a6d0220 commit fa9dbc7

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Options.py

+6
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,12 @@ def __init__(self, value: int) -> None:
735735
elif value > self.range_end and value not in self.special_range_names.values():
736736
raise Exception(f"{value} is higher than maximum {self.range_end} for option {self.__class__.__name__} " +
737737
f"and is also not one of the supported named special values: {self.special_range_names}")
738+
739+
# See docstring
740+
for key in self.special_range_names:
741+
if key != key.lower():
742+
raise Exception(f"{self.__class__.__name__} has an invalid special_range_names key: {key}. "
743+
f"NamedRange keys must use only lowercase letters, and ideally should be snake_case.")
738744
self.value = value
739745

740746
@classmethod

WebHostLib/templates/playerOptions/macros.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
<select id="{{ option_name }}-select" data-option-name="{{ option_name }}" {{ "disabled" if option.default == "random" }}>
5858
{% for key, val in option.special_range_names.items() %}
5959
{% if option.default == val %}
60-
<option value="{{ val }}" selected>{{ key }} ({{ val }})</option>
60+
<option value="{{ val }}" selected>{{ key|replace("_", " ")|title }} ({{ val }})</option>
6161
{% else %}
62-
<option value="{{ val }}">{{ key }} ({{ val }})</option>
62+
<option value="{{ val }}">{{ key|replace("_", " ")|title }} ({{ val }})</option>
6363
{% endif %}
6464
{% endfor %}
6565
<option value="custom" hidden>Custom</option>

WebHostLib/templates/weightedOptions/macros.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
The following values have special meanings, and may fall outside the normal range.
4242
<ul>
4343
{% for name, value in option.special_range_names.items() %}
44-
<li>{{ value }}: {{ name }}</li>
44+
<li>{{ value }}: {{ name|replace("_", " ")|title }}</li>
4545
{% endfor %}
4646
</ul>
4747
{% endif %}

0 commit comments

Comments
 (0)