Skip to content

Commit b8665a1

Browse files
Zach ParksJouramie
Zach Parks
authored andcommitted
WebHost: Fix special-range value setting to custom when randomization is toggled off (ArchipelagoMW#1856)
* WebHost: Fix custom-range value setting to `custom` when randomization is toggled off * Remove redundant code * Add optional parameter default
1 parent 9d6424f commit b8665a1

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

WebHostLib/static/assets/player-settings.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const buildOptionsTable = (settings, romOpts = false) => {
148148
randomButton.classList.add('randomize-button');
149149
randomButton.setAttribute('data-key', setting);
150150
randomButton.setAttribute('data-tooltip', 'Toggle randomization for this option!');
151-
randomButton.addEventListener('click', (event) => toggleRandomize(event, [select]));
151+
randomButton.addEventListener('click', (event) => toggleRandomize(event, select));
152152
if (currentSettings[gameName][setting] === 'random') {
153153
randomButton.classList.add('active');
154154
select.disabled = true;
@@ -185,7 +185,7 @@ const buildOptionsTable = (settings, romOpts = false) => {
185185
randomButton.classList.add('randomize-button');
186186
randomButton.setAttribute('data-key', setting);
187187
randomButton.setAttribute('data-tooltip', 'Toggle randomization for this option!');
188-
randomButton.addEventListener('click', (event) => toggleRandomize(event, [range]));
188+
randomButton.addEventListener('click', (event) => toggleRandomize(event, range));
189189
if (currentSettings[gameName][setting] === 'random') {
190190
randomButton.classList.add('active');
191191
range.disabled = true;
@@ -269,7 +269,7 @@ const buildOptionsTable = (settings, romOpts = false) => {
269269
randomButton.setAttribute('data-key', setting);
270270
randomButton.setAttribute('data-tooltip', 'Toggle randomization for this option!');
271271
randomButton.addEventListener('click', (event) => toggleRandomize(
272-
event, [specialRange, specialRangeSelect])
272+
event, specialRange, specialRangeSelect)
273273
);
274274
if (currentSettings[gameName][setting] === 'random') {
275275
randomButton.classList.add('active');
@@ -294,23 +294,25 @@ const buildOptionsTable = (settings, romOpts = false) => {
294294
return table;
295295
};
296296

297-
const toggleRandomize = (event, inputElements) => {
297+
const toggleRandomize = (event, inputElement, optionalSelectElement = null) => {
298298
const active = event.target.classList.contains('active');
299299
const randomButton = event.target;
300300

301301
if (active) {
302302
randomButton.classList.remove('active');
303-
for (const element of inputElements) {
304-
element.disabled = undefined;
305-
updateGameSetting(element);
303+
inputElement.disabled = undefined;
304+
if (optionalSelectElement) {
305+
optionalSelectElement.disabled = undefined;
306306
}
307307
} else {
308308
randomButton.classList.add('active');
309-
for (const element of inputElements) {
310-
element.disabled = true;
311-
updateGameSetting(randomButton);
309+
inputElement.disabled = true;
310+
if (optionalSelectElement) {
311+
optionalSelectElement.disabled = true;
312312
}
313313
}
314+
315+
updateGameSetting(randomButton);
314316
};
315317

316318
const updateBaseSetting = (event) => {

0 commit comments

Comments
 (0)