Skip to content

Commit

Permalink
WebHost: Fix Named Range displays on Player Options page (#3521)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
NewSoupVi authored Jun 13, 2024
1 parent 2ae5136 commit 533395d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,12 @@ def __init__(self, value: int) -> None:
elif value > self.range_end and value not in self.special_range_names.values():
raise Exception(f"{value} is higher than maximum {self.range_end} for option {self.__class__.__name__} " +
f"and is also not one of the supported named special values: {self.special_range_names}")

# See docstring
for key in self.special_range_names:
if key != key.lower():
raise Exception(f"{self.__class__.__name__} has an invalid special_range_names key: {key}. "
f"NamedRange keys must use only lowercase letters, and ideally should be snake_case.")
self.value = value

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions WebHostLib/templates/playerOptions/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
<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>
<option value="{{ val }}" selected>{{ key|replace("_", " ")|title }} ({{ val }})</option>
{% else %}
<option value="{{ val }}">{{ key }} ({{ val }})</option>
<option value="{{ val }}">{{ key|replace("_", " ")|title }} ({{ val }})</option>
{% endif %}
{% endfor %}
<option value="custom" hidden>Custom</option>
Expand Down
2 changes: 1 addition & 1 deletion WebHostLib/templates/weightedOptions/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
The following values have special meanings, and may fall outside the normal range.
<ul>
{% for name, value in option.special_range_names.items() %}
<li>{{ value }}: {{ name }}</li>
<li>{{ value }}: {{ name|replace("_", " ")|title }}</li>
{% endfor %}
</ul>
{% endif %}
Expand Down

0 comments on commit 533395d

Please sign in to comment.