WebHost: Fix special-range value setting to `custom` when randomization is toggled off (#1856)

* WebHost: Fix custom-range value setting to `custom` when randomization is toggled off

* Remove redundant code

* Add optional parameter default
This commit is contained in:
Zach Parks 2023-06-22 21:12:22 -05:00 committed by GitHub
parent abd8eaf36e
commit 59ad9e97e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 10 deletions

View File

@ -148,7 +148,7 @@ const buildOptionsTable = (settings, romOpts = false) => {
randomButton.classList.add('randomize-button'); randomButton.classList.add('randomize-button');
randomButton.setAttribute('data-key', setting); randomButton.setAttribute('data-key', setting);
randomButton.setAttribute('data-tooltip', 'Toggle randomization for this option!'); randomButton.setAttribute('data-tooltip', 'Toggle randomization for this option!');
randomButton.addEventListener('click', (event) => toggleRandomize(event, [select])); randomButton.addEventListener('click', (event) => toggleRandomize(event, select));
if (currentSettings[gameName][setting] === 'random') { if (currentSettings[gameName][setting] === 'random') {
randomButton.classList.add('active'); randomButton.classList.add('active');
select.disabled = true; select.disabled = true;
@ -185,7 +185,7 @@ const buildOptionsTable = (settings, romOpts = false) => {
randomButton.classList.add('randomize-button'); randomButton.classList.add('randomize-button');
randomButton.setAttribute('data-key', setting); randomButton.setAttribute('data-key', setting);
randomButton.setAttribute('data-tooltip', 'Toggle randomization for this option!'); randomButton.setAttribute('data-tooltip', 'Toggle randomization for this option!');
randomButton.addEventListener('click', (event) => toggleRandomize(event, [range])); randomButton.addEventListener('click', (event) => toggleRandomize(event, range));
if (currentSettings[gameName][setting] === 'random') { if (currentSettings[gameName][setting] === 'random') {
randomButton.classList.add('active'); randomButton.classList.add('active');
range.disabled = true; range.disabled = true;
@ -269,7 +269,7 @@ const buildOptionsTable = (settings, romOpts = false) => {
randomButton.setAttribute('data-key', setting); randomButton.setAttribute('data-key', setting);
randomButton.setAttribute('data-tooltip', 'Toggle randomization for this option!'); randomButton.setAttribute('data-tooltip', 'Toggle randomization for this option!');
randomButton.addEventListener('click', (event) => toggleRandomize( randomButton.addEventListener('click', (event) => toggleRandomize(
event, [specialRange, specialRangeSelect]) event, specialRange, specialRangeSelect)
); );
if (currentSettings[gameName][setting] === 'random') { if (currentSettings[gameName][setting] === 'random') {
randomButton.classList.add('active'); randomButton.classList.add('active');
@ -294,23 +294,25 @@ const buildOptionsTable = (settings, romOpts = false) => {
return table; return table;
}; };
const toggleRandomize = (event, inputElements) => { const toggleRandomize = (event, inputElement, optionalSelectElement = null) => {
const active = event.target.classList.contains('active'); const active = event.target.classList.contains('active');
const randomButton = event.target; const randomButton = event.target;
if (active) { if (active) {
randomButton.classList.remove('active'); randomButton.classList.remove('active');
for (const element of inputElements) { inputElement.disabled = undefined;
element.disabled = undefined; if (optionalSelectElement) {
updateGameSetting(element); optionalSelectElement.disabled = undefined;
} }
} else { } else {
randomButton.classList.add('active'); randomButton.classList.add('active');
for (const element of inputElements) { inputElement.disabled = true;
element.disabled = true; if (optionalSelectElement) {
updateGameSetting(randomButton); optionalSelectElement.disabled = true;
} }
} }
updateGameSetting(randomButton);
}; };
const updateBaseSetting = (event) => { const updateBaseSetting = (event) => {