revert locked on top

This commit is contained in:
Greenlamp 2024-05-17 14:29:26 +02:00
parent 87fec224a0
commit e77163dfae

View File

@ -21,24 +21,6 @@ export interface LayoutConfig {
keys: string[]; keys: string[];
bindingSettings: Array<String>; bindingSettings: Array<String>;
} }
/**
* Moves elements in the blacklist to the top of the original array.
* @param {string[]} originalArray - The original array of strings.
* @param {string[]} blacklist - The array of strings to be moved to the top.
* @returns {string[]} - The new array with blacklisted elements at the top.
*/
function moveBlacklistedToTop(originalArray, blacklist) {
// Filter the original array to get blacklisted elements
const blacklistedElements = originalArray.filter(element => blacklist.includes(element.toUpperCase()));
// Filter the original array to get non-blacklisted elements
const nonBlacklistedElements = originalArray.filter(element => !blacklist.includes(element.toUpperCase()));
// Concatenate the blacklisted elements and the non-blacklisted elements
return blacklistedElements.concat(nonBlacklistedElements);
}
/** /**
* Abstract class for handling UI elements related to settings. * Abstract class for handling UI elements related to settings.
*/ */
@ -171,8 +153,7 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
// Fetch default values for these settings and prepare to highlight selected options. // Fetch default values for these settings and prepare to highlight selected options.
const optionCursors = Object.values(Object.keys(this.settingDeviceDefaults).filter(s => specificBindingKeys.includes(s)).map(k => this.settingDeviceDefaults[k])); const optionCursors = Object.values(Object.keys(this.settingDeviceDefaults).filter(s => specificBindingKeys.includes(s)).map(k => this.settingDeviceDefaults[k]));
// Filter out settings that are not relevant to the current gamepad configuration. // Filter out settings that are not relevant to the current gamepad configuration.
const unsortedSettingFiltered = Object.keys(this.settingDevice).filter(_key => specificBindingKeys.includes(this.settingDevice[_key])) const settingFiltered = Object.keys(this.settingDevice).filter(_key => specificBindingKeys.includes(this.settingDevice[_key]))
const settingFiltered = moveBlacklistedToTop(unsortedSettingFiltered, this.settingBlacklisted);
// Loop through the filtered settings to manage display and options. // Loop through the filtered settings to manage display and options.
settingFiltered.forEach((setting, s) => { settingFiltered.forEach((setting, s) => {
@ -407,10 +388,12 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
this.scene.ui.revertMode(); this.scene.ui.revertMode();
} else { } else {
const cursor = this.cursor + this.scrollCursor; // Calculate the absolute cursor position. const cursor = this.cursor + this.scrollCursor; // Calculate the absolute cursor position.
const setting = this.settingDevice[Object.keys(this.settingDevice)[cursor]];
switch (button) { switch (button) {
case Button.ACTION: case Button.ACTION:
if (!this.optionCursors || !this.optionValueLabels) return; if (!this.optionCursors || !this.optionValueLabels) return;
const setting = this.settingDevice[Object.keys(this.settingDevice)[cursor]]; if (this.settingBlacklisted.includes(setting) || !setting.includes('BUTTON_')) success = false;
else
success = this.setSetting(this.scene, setting, 1); success = this.setSetting(this.scene, setting, 1);
break; break;
case Button.UP: // Move up in the menu. case Button.UP: // Move up in the menu.
@ -445,16 +428,20 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
success = successA && successB; // Indicates a successful cursor and scroll adjustment. success = successA && successB; // Indicates a successful cursor and scroll adjustment.
} }
break; break;
// case Button.LEFT: // Move selection left within the current option set. case Button.LEFT: // Move selection left within the current option set.
// if (!this.optionCursors || !this.optionValueLabels) return; if (!this.optionCursors || !this.optionValueLabels) return;
// if (this.optionCursors[cursor]) if (this.settingBlacklisted.includes(setting) || setting.includes('BUTTON_')) success = false;
// success = this.setOptionCursor(cursor, this.optionCursors[cursor] - 1, true); else if (this.optionCursors[cursor]) {
// break; success = this.setOptionCursor(cursor, this.optionCursors[cursor] - 1, true);
// case Button.RIGHT: // Move selection right within the current option set. }
// if (!this.optionCursors || !this.optionValueLabels) return; break;
// if (this.optionCursors[cursor] < this.optionValueLabels[cursor].length - 1) case Button.RIGHT: // Move selection right within the current option set.
// success = this.setOptionCursor(cursor, this.optionCursors[cursor] + 1, true); if (!this.optionCursors || !this.optionValueLabels) return;
// break; if (this.settingBlacklisted.includes(setting) || setting.includes('BUTTON_')) success = false;
else if (this.optionCursors[cursor] < this.optionValueLabels[cursor].length - 1) {
success = this.setOptionCursor(cursor, this.optionCursors[cursor] + 1, true);
}
break;
case Button.CYCLE_FORM: case Button.CYCLE_FORM:
success = this.navigateMenuLeft(); success = this.navigateMenuLeft();
break; break;