From e78f04e07695c5becdb49ecb1365994a73147c15 Mon Sep 17 00:00:00 2001 From: VariableVince <24507472+VariableVince@users.noreply.github.com> Date: Mon, 18 May 2026 20:56:47 +0200 Subject: [PATCH] Fix bad merge conflict resolution by copilot (lesson learned) --- src/client/HelpModal.ts | 51 ++----- src/client/UserSettingModal.ts | 266 ++++++++++++++++++--------------- src/client/Utils.ts | 4 +- 3 files changed, 156 insertions(+), 165 deletions(-) diff --git a/src/client/HelpModal.ts b/src/client/HelpModal.ts index acba57635..d60547658 100644 --- a/src/client/HelpModal.ts +++ b/src/client/HelpModal.ts @@ -1,8 +1,12 @@ import { html } from "lit"; import { customElement, query, state } from "lit/decorators.js"; -import { translateText, TUTORIAL_VIDEO_URL } from "../client/Utils"; +import { + formatKeyForDisplay, + translateText, + TUTORIAL_VIDEO_URL, +} from "../client/Utils"; import { assetUrl } from "../core/AssetUrls"; -import { UserSettings } from "../core/game/UserSettings"; +import { KeybindAction, UserSettings } from "../core/game/UserSettings"; import { BaseModal } from "./components/BaseModal"; import "./components/Difficulties"; import { modalHeader } from "./components/ui/ModalHeader"; @@ -13,46 +17,15 @@ import { TroubleshootingModal } from "./TroubleshootingModal"; export class HelpModal extends BaseModal { protected routerName = "help"; - @state() private keybinds: Record = this.getKeybinds(); + @state() private keybinds = this.getKeybinds(); @query("#tutorial-video-iframe") private videoIframe?: HTMLIFrameElement; - private getKeybinds(): Record { + private getKeybinds(): Record { return new UserSettings().keybinds(Platform.isMac); } - private getKeyLabel(code: string): string { - if (!code) return ""; - - const specialLabels: Record = { - ShiftLeft: "⇧ Shift", - ShiftRight: "⇧ Shift", - ControlLeft: "Ctrl", - ControlRight: "Ctrl", - AltLeft: "Alt", - AltRight: "Alt", - MetaLeft: "⌘", - MetaRight: "⌘", - Space: "Space", - Escape: "Esc", - Enter: "↵ Return", - ArrowUp: "↑", - ArrowDown: "↓", - ArrowLeft: "←", - ArrowRight: "→", - Period: ">", - Comma: "<", - }; - - if (specialLabels[code]) return specialLabels[code]; - if (code.startsWith("Key") && code.length === 4) return code.slice(3); - if (code.startsWith("Digit")) return code.slice(5); - if (code.startsWith("Numpad")) return `Num ${code.slice(6)}`; - - return code; - } - private renderKey(code: string) { - const label = this.getKeyLabel(code); + const label = formatKeyForDisplay(code); return html`${label}
- ${this.renderKey(keybinds.modifierKey)} + ${this.renderKey(keybinds.buildMenuModifier)} +
- ${this.renderKey(keybinds.altKey)} + ${this.renderKey(keybinds.emojiMenuModifier)} +
- ${this.renderKey(keybinds.altKey)} + ${this.renderKey(keybinds.emojiMenuModifier)} + ${this.renderKey(keybinds.resetGfx)}
diff --git a/src/client/UserSettingModal.ts b/src/client/UserSettingModal.ts index 65edeb9fc..6a2a728e3 100644 --- a/src/client/UserSettingModal.ts +++ b/src/client/UserSettingModal.ts @@ -1,7 +1,12 @@ import { html } from "lit"; import { customElement, state } from "lit/decorators.js"; import { formatKeyForDisplay, translateText } from "../client/Utils"; -import { getDefaultKeybinds, UserSettings } from "../core/game/UserSettings"; +import { + getDefaultKeybinds, + KeybindAction, + KeyUnbound, + UserSettings, +} from "../core/game/UserSettings"; import "./components/baseComponents/setting/SettingKeybind"; import { SettingKeybind } from "./components/baseComponents/setting/SettingKeybind"; import "./components/baseComponents/setting/SettingNumber"; @@ -21,9 +26,8 @@ export class UserSettingModal extends BaseModal { @state() private keySequence: string[] = []; @state() private showEasterEggSettings = false; - @state() private userKeybinds: Record< - string, - { value: string; key: string } + @state() private userKeybinds: Partial< + Record > = {}; connectedCallback() { @@ -43,9 +47,12 @@ export class UserSettingModal extends BaseModal { return; } - const validated: Record = {}; + const validated: Partial< + 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 ( @@ -53,12 +60,12 @@ export class UserSettingModal extends BaseModal { entry !== null && !Array.isArray(entry) ) { - const rawValue = (entry as any).value ?? "Null"; + const rawValue = entry.value ?? KeyUnbound; const value = Array.isArray(rawValue) ? rawValue.find((v) => typeof v === "string") : rawValue; - const rawKey = (entry as any).key ?? value; + const rawKey = entry.key ?? value; const key = Array.isArray(rawKey) ? rawKey.find((v) => typeof v === "string") : rawKey; @@ -74,29 +81,43 @@ export class UserSettingModal extends BaseModal { private handleKeybindChange( e: CustomEvent<{ - action: string; + action: KeybindAction; value: string; key: string; prevValue?: string; }>, ) { - const { action, value, key, prevValue } = e.detail; + const { action, value, prevValue } = e.detail; + let { key } = e.detail; - const activeKeybinds: Record = { ...this.defaultKeybinds }; - for (const [k, v] of Object.entries(this.userKeybinds)) { - const normalizedValue = v.value; - if (normalizedValue === "Null") { - delete activeKeybinds[k]; + // TODO: remove after testing + console.info( + "handleKeybindChange received value: " + value, + ", key: " + key, + ); + + // Don't display "Dead" for Quote / Backquote https://en.wikipedia.org/wiki/QWERTY#US-International + // nor "Unidentified" for some keys in Firefox ("" in Chrome). Empty the key to use value (key code). + key = key === "Dead" || key === "Unidentified" ? "" : key; + + const activeKeybinds: Record = { + ...this.defaultKeybinds, + }; + for (const [rawAction, codeAndKey] of Object.entries(this.userKeybinds)) { + const action = rawAction as KeybindAction; + const normalizedCode = codeAndKey.value; + if (normalizedCode === KeyUnbound) { + delete activeKeybinds[action]; } else { - activeKeybinds[k] = normalizedValue; + activeKeybinds[action] = normalizedCode; } } - const values = Object.entries(activeKeybinds) - .filter(([k]) => k !== action) - .map(([, v]) => v); + const codes = Object.entries(activeKeybinds) + .filter(([a]) => a !== action) + .map(([, code]) => code); - if (values.includes(value) && value !== "Null") { + if (codes.includes(value) && value !== KeyUnbound) { const displayKey = formatKeyForDisplay(key || value); window.dispatchEvent( new CustomEvent("show-message", { @@ -140,11 +161,8 @@ export class UserSettingModal extends BaseModal { `setting-keybind[action="${action}"]`, ); if (element) { - element.value = - prevValue ?? - (this.defaultKeybinds as Record)[action] ?? - ""; - element.requestUpdate(); + element.value = prevValue ?? this.defaultKeybinds[action] ?? ""; + // requestUpdate() handled by SettingKeyBind which dispatches the "change" event that triggers this function } return; } @@ -156,15 +174,15 @@ export class UserSettingModal extends BaseModal { this.userSettings.setUserKeybinds(this.userKeybinds); } - private getKeyValue(action: string): string | undefined { + private getKeyValue(action: KeybindAction): string | undefined { const entry = this.userKeybinds[action]; if (!entry) return undefined; const normalizedValue = entry.value; - if (normalizedValue === "Null") return ""; + if (normalizedValue === KeyUnbound) return ""; return normalizedValue || undefined; } - private getKeyChar(action: string): string { + private getKeyChar(action: KeybindAction): string { const entry = this.userKeybinds[action]; if (!entry) return ""; return entry.key || ""; @@ -385,22 +403,22 @@ export class UserSettingModal extends BaseModal { @@ -411,102 +429,102 @@ export class UserSettingModal extends BaseModal { @@ -517,52 +535,52 @@ export class UserSettingModal extends BaseModal { @@ -573,26 +591,26 @@ export class UserSettingModal extends BaseModal { @@ -603,42 +621,42 @@ export class UserSettingModal extends BaseModal { @@ -649,22 +667,22 @@ export class UserSettingModal extends BaseModal { @@ -675,22 +693,22 @@ export class UserSettingModal extends BaseModal { @@ -701,52 +719,52 @@ export class UserSettingModal extends BaseModal { `; diff --git a/src/client/Utils.ts b/src/client/Utils.ts index 7ff9345b1..b6f7a12e6 100644 --- a/src/client/Utils.ts +++ b/src/client/Utils.ts @@ -374,8 +374,8 @@ export function formatKeyForDisplay(value: string): string { Minus: "-", Equal: "=", Semicolon: ";", - Comma: ",", - Period: ".", + Comma: ",", // old getKeyLabel in HelpModal, had this as "<", but not every keyboard layout has it that way? + Period: ".",// old getKeyLabel in HelpModal, had this as ">", but not every keyboard layout has it that way? Slash: "/", Backslash: "\\", Shift: "Shift ⇧",