Compare commits

..

6 Commits

Author SHA1 Message Date
NewSoupVi
8ac5ae2177 Bring change to Weighted Options as well 2024-06-13 19:47:31 +02:00
NewSoupVi
45c910f038 Do replace first so title works correctly 2024-06-13 19:46:06 +02:00
NewSoupVi
9a63482b49 Comment 2024-06-13 18:22:37 +02:00
NewSoupVi
7ad9495041 Don't break Stardew 2024-06-13 18:16:03 +02:00
NewSoupVi
e22eea056d Also add validation to the NamedRange class itself 2024-06-13 18:08:28 +02:00
NewSoupVi
0396559643 Player Options: Fix Named Range displays 2024-06-13 00:04:16 +02:00
3 changed files with 12 additions and 6 deletions

View File

@@ -735,6 +735,12 @@ class NamedRange(Range):
elif value > self.range_end and value not in self.special_range_names.values(): 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__} " + 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}") 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 self.value = value
@classmethod @classmethod

View File

@@ -57,9 +57,9 @@
<select id="{{ option_name }}-select" data-option-name="{{ option_name }}" {{ "disabled" if option.default == "random" }}> <select id="{{ option_name }}-select" data-option-name="{{ option_name }}" {{ "disabled" if option.default == "random" }}>
{% for key, val in option.special_range_names.items() %} {% for key, val in option.special_range_names.items() %}
{% if option.default == val %} {% if option.default == val %}
<option value="{{ val }}" selected>{{ key }} ({{ val }})</option> <option value="{{ val }}" selected>{{ key|replace("_", " ")|title }} ({{ val }})</option>
{% else %} {% else %}
<option value="{{ val }}">{{ key }} ({{ val }})</option> <option value="{{ val }}">{{ key|replace("_", " ")|title }} ({{ val }})</option>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<option value="custom" hidden>Custom</option> <option value="custom" hidden>Custom</option>

View File

@@ -41,13 +41,13 @@
The following values have special meanings, and may fall outside the normal range. The following values have special meanings, and may fall outside the normal range.
<ul> <ul>
{% for name, value in option.special_range_names.items() %} {% for name, value in option.special_range_names.items() %}
<li>{{ value }}: {{ name }}</li> <li>{{ value }}: {{ name|replace("_", " ")|title }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} {% endif %}
<div class="add-option-div"> <div class="add-option-div">
<input type="number" class="range-option-value" data-option="{{ option_name }}" /> <input type="number" class="range-option-value" data-option="{{ option_name }}" />
<button type="button" class="add-range-option-button" data-option="{{ option_name }}">Add</button> <button class="add-range-option-button" data-option="{{ option_name }}">Add</button>
</div> </div>
</div> </div>
<table class="range-rows" data-option="{{ option_name }}"> <table class="range-rows" data-option="{{ option_name }}">
@@ -72,7 +72,7 @@
This option allows custom values only. Please enter your desired values below. This option allows custom values only. Please enter your desired values below.
<div class="custom-value-wrapper"> <div class="custom-value-wrapper">
<input class="custom-value" data-option="{{ option_name }}" placeholder="Custom Value" /> <input class="custom-value" data-option="{{ option_name }}" placeholder="Custom Value" />
<button type="button" data-option="{{ option_name }}">Add</button> <button data-option="{{ option_name }}">Add</button>
</div> </div>
<table> <table>
<tbody> <tbody>
@@ -89,7 +89,7 @@
Custom values are also allowed for this option. To create one, enter it into the input box below. Custom values are also allowed for this option. To create one, enter it into the input box below.
<div class="custom-value-wrapper"> <div class="custom-value-wrapper">
<input class="custom-value" data-option="{{ option_name }}" placeholder="Custom Value" /> <input class="custom-value" data-option="{{ option_name }}" placeholder="Custom Value" />
<button type="button" data-option="{{ option_name }}">Add</button> <button data-option="{{ option_name }}">Add</button>
</div> </div>
</div> </div>
<table> <table>