From 1dc4e2b44b241418fe2614c5264304a4d7973c5b Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 30 Mar 2023 19:01:31 -0400 Subject: [PATCH] Restore "random" option to weighted-settings (#1635) * 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 --- WebHostLib/options.py | 11 +++++++++++ WebHostLib/static/assets/weighted-settings.js | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/WebHostLib/options.py b/WebHostLib/options.py index 545556d4bb4c..a4d7ccc17c9f 100644 --- a/WebHostLib/options.py +++ b/WebHostLib/options.py @@ -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", @@ -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 diff --git a/WebHostLib/static/assets/weighted-settings.js b/WebHostLib/static/assets/weighted-settings.js index e914197d4c8c..e471e0837a46 100644 --- a/WebHostLib/static/assets/weighted-settings.js +++ b/WebHostLib/static/assets/weighted-settings.js @@ -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');