Use enums in more places (after last merge with main), fix ts errors, better comments

This commit is contained in:
VariableVince
2026-05-18 19:48:44 +02:00
parent 747da28a0d
commit fec6709c10
3 changed files with 15 additions and 12 deletions
+10 -8
View File
@@ -52,7 +52,8 @@ export class UserSettingModal extends BaseModal {
Record<KeybindAction, { value: string; key: string }>
> = {};
for (const [action, entry] of Object.entries(parsed)) {
for (const [rawAction, entry] of Object.entries(parsed)) {
const action = rawAction as KeybindAction;
if (typeof entry === "string") {
validated[action] = { value: entry, key: entry };
} else if (
@@ -101,12 +102,13 @@ export class UserSettingModal extends BaseModal {
key = key === "Dead" || key === "Unidentified" ? "" : key;
const activeKeybinds = { ...this.defaultKeybinds };
for (const [action, codeAndKey] of Object.entries(this.userKeybinds)) {
for (const [rawIterAction, codeAndKey] of Object.entries(this.userKeybinds)) {
const iterAction = rawIterAction as KeybindAction;
const normalizedCode = codeAndKey.value;
if (normalizedCode === KeyUnbound) {
delete activeKeybinds[action];
delete activeKeybinds[iterAction];
} else {
activeKeybinds[action] = normalizedCode;
activeKeybinds[iterAction] = normalizedCode;
}
}
@@ -667,14 +669,14 @@ export class UserSettingModal extends BaseModal {
action==${KeybindAction.retaliateAttack}
label=${translateText("user_setting.retaliate_attack")}
description=${translateText("user_setting.retaliate_attack_desc")}
defaultKey=${this.defaultKeybinds.retaliateAttack}
.value=${this.getKeyValue("retaliateAttack")}
.display=${this.getKeyChar("retaliateAttack")}
.defaultKey=${this.defaultKeybinds.retaliateAttack}
.value=${this.getKeyValue(KeybindAction.retaliateAttack)}
.display=${this.getKeyChar(KeybindAction.retaliateAttack)}
@change=${this.handleKeybindChange}
></setting-keybind>
<setting-keybind
action="swapDirection"
action=${KeybindAction.swapDirection}
label=${translateText("user_setting.swap_direction")}
description=${translateText("user_setting.swap_direction_desc")}
.defaultKey=${this.defaultKeybinds.swapDirection}
+3 -2
View File
@@ -417,9 +417,10 @@ export class UserSettings {
...this.normalizedUserKeybinds(),
};
// Actually unbind key: if Unbind is clicked in UserSettingsModal, eg. for Attack Ratio Up,
// keybind is KeyUnbound. Even if it is in default kindbinds (Y), it should not work anymore.
// keybind is "Null". Even if it is in default kindbinds (Y), it should not work anymore.
// The key (Y) can now be bound to another action like Boat Attack, and no two actions listen to the same key.
for (const action in mergedKeybinds) {
for (const rawAction in mergedKeybinds) {
const action = rawAction as KeybindAction;
if (mergedKeybinds[action] === KeyUnbound) {
delete mergedKeybinds[action];
}
+2 -2
View File
@@ -513,7 +513,7 @@ describe("InputHandler AutoUpgrade", () => {
expect((inputHandler as any).keybinds.moveUp).toBe("KeyX");
});
test("ignores non-string values and preserves defaults, removes KeyUnbound keys", () => {
test("ignores non-string values and preserves defaults, removes 'Null' keys", () => {
const mixed = {
moveUp: { key: "moveUp", value: null },
moveLeft: KeyUnbound,
@@ -523,7 +523,7 @@ describe("InputHandler AutoUpgrade", () => {
inputHandler.initialize();
expect((inputHandler as any).keybinds.moveUp).toBe("KeyW");
// KeyUnbound entries are removed entirely to indicate unbound keybind
// "Null" entries are removed entirely to indicate unbound keybind
expect((inputHandler as any).keybinds.moveLeft).toBeUndefined();
});