/** Turning ids into the words printed on the panel and in combo lines. */ import { CTX, GNAME, GROUPS, L } from "./labels"; import type { ContextCode, ControlId, Entry, GroupId, RawEntry } from "./types"; const GROUP_IDS: ReadonlySet = new Set(Object.keys(GROUPS)); /** Name of a single control: `"shift"` becomes `"SHIFT"`. */ export function controlName(id: ControlId): string { return L[id] ?? id; } /** * Name of whatever an entry targets: one control, a group ("PAD 1–16"), or an * explicit list joined with a slash. */ export function targetName(target: RawEntry[1]): string { if (Array.isArray(target)) return target.map(controlName).join(" / "); if (GROUP_IDS.has(target)) return GNAME[target as GroupId]; return controlName(target); } export function contextNames(ctx: readonly ContextCode[]): string[] { return ctx.map((c) => CTX[c]); } /** The combo as its parts: modifiers first, then the target. */ export function comboParts(entry: Entry): string[] { return [...entry.mods.map(controlName), targetName(entry.target)]; } /** The combo as one line: `"SHIFT + PAD 1"`. */ export function comboText(entry: Entry): string { return comboParts(entry).join(" + "); }