Skip to content

Commit

Permalink
Restore "random" option to weighted-settings (#1635)
Browse files Browse the repository at this point in the history
* Restore "random" option to weighted-settings, adjust capitalization of hardcoded settings

* Set default value as "random" for Choice, TextChoice, and Toggle options with no default value
  • Loading branch information
LegendaryLinux authored Mar 30, 2023
1 parent d5b4a91 commit 1dc4e2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions WebHostLib/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def get_html_doc(option_type: type(Options.Option)) -> str:
if sub_option_id == option.default:
this_option["defaultValue"] = sub_option_name

if not this_option["defaultValue"]:
this_option["defaultValue"] = "random"

elif issubclass(option, Options.Range):
game_options[option_name] = {
"type": "range",
Expand Down Expand Up @@ -157,6 +160,14 @@ def get_html_doc(option_type: type(Options.Option)) -> str:
json.dump(player_settings, f, indent=2, separators=(',', ': '))

if not world.hidden and world.web.settings_page is True:
# Add the random option to Choice, TextChoice, and Toggle settings
for option in game_options.values():
if option["type"] == "select":
option["options"].append({"name": "Random", "value": "random"})

if not option["defaultValue"]:
option["defaultValue"] = "random"

weighted_settings["baseOptions"]["game"][game_name] = 0
weighted_settings["games"][game_name] = {}
weighted_settings["games"][game_name]["gameSettings"] = game_options
Expand Down
12 changes: 11 additions & 1 deletion WebHostLib/static/assets/weighted-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,17 @@ const buildWeightedSettingsDiv = (game, settings, gameItems, gameLocations) => {
const tr = document.createElement('tr');
const tdLeft = document.createElement('td');
tdLeft.classList.add('td-left');
tdLeft.innerText = option;
switch(option){
case 'random':
tdLeft.innerText = 'Random';
break;
case 'random-low':
tdLeft.innerText = "Random (Low)";
break;
case 'random-high':
tdLeft.innerText = "Random (High)";
break;
}
tr.appendChild(tdLeft);

const tdMiddle = document.createElement('td');
Expand Down

0 comments on commit 1dc4e2b

Please sign in to comment.