From fec6709c1054faa7a2cb2bedf68436a076897f9a Mon Sep 17 00:00:00 2001 From: VariableVince <24507472+VariableVince@users.noreply.github.com> Date: Mon, 18 May 2026 19:48:44 +0200 Subject: [PATCH] Use enums in more places (after last merge with main), fix ts errors, better comments --- src/client/UserSettingModal.ts | 18 ++++++++++-------- src/core/game/UserSettings.ts | 5 +++-- tests/InputHandler.test.ts | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/client/UserSettingModal.ts b/src/client/UserSettingModal.ts index 129240f0a..8af33eb47 100644 --- a/src/client/UserSettingModal.ts +++ b/src/client/UserSettingModal.ts @@ -52,7 +52,8 @@ export class UserSettingModal extends BaseModal { Record > = {}; - 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} > { 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(); });