All checks were successful
Build and Push Docker Image / build (push) Successful in 3m25s
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
const CODE_TO_NDS_BUTTON: Record<string, string> = {
|
|
ArrowUp: "UP",
|
|
ArrowDown: "DOWN",
|
|
ArrowLeft: "LEFT",
|
|
ArrowRight: "RIGHT",
|
|
KeyD: "A",
|
|
KeyS: "B",
|
|
KeyW: "X",
|
|
KeyA: "Y",
|
|
Space: "SELECT",
|
|
Enter: "START",
|
|
};
|
|
|
|
export const mapCodeToNDS = (code: string): string | null => {
|
|
return CODE_TO_NDS_BUTTON[code] ?? null;
|
|
};
|
|
|
|
const NDS_BUTTON_TO_CODE = Object.fromEntries(
|
|
Object.entries(CODE_TO_NDS_BUTTON).map(([code, nds]) => [nds, code]),
|
|
);
|
|
|
|
const LAYOUT_OVERRIDES: Record<string, Record<string, string>> = {
|
|
// AZERTY: fr
|
|
fr: { KeyQ: "A", KeyA: "Q", KeyW: "Z", KeyZ: "W", KeyM: ",", Semicolon: "M" },
|
|
// QWERTZ: de, cs, hu, sk, sl, hr, bs, sr, pl
|
|
de: { KeyY: "Z", KeyZ: "Y" },
|
|
cs: { KeyY: "Z", KeyZ: "Y" },
|
|
hu: { KeyY: "Z", KeyZ: "Y" },
|
|
sk: { KeyY: "Z", KeyZ: "Y" },
|
|
sl: { KeyY: "Z", KeyZ: "Y" },
|
|
hr: { KeyY: "Z", KeyZ: "Y" },
|
|
bs: { KeyY: "Z", KeyZ: "Y" },
|
|
sr: { KeyY: "Z", KeyZ: "Y" },
|
|
pl: { KeyY: "Z", KeyZ: "Y" },
|
|
};
|
|
|
|
const getLayoutOverrides = (): Record<string, string> => {
|
|
if (!import.meta.client) return {};
|
|
const lang = navigator.language.split("-")[0]!;
|
|
return LAYOUT_OVERRIDES[lang] ?? {};
|
|
};
|
|
|
|
export const mapNDSToKey = (nds: string): string => {
|
|
const code = NDS_BUTTON_TO_CODE[nds];
|
|
if (!code) return nds;
|
|
|
|
const overrides = getLayoutOverrides();
|
|
if (overrides[code]) return overrides[code];
|
|
|
|
if (code.startsWith("Key")) return code.slice(3);
|
|
return code;
|
|
};
|
|
|
|
export const useMouseUp = (callback: () => void) => {
|
|
onMounted(() => {
|
|
document.addEventListener("mouseup", callback);
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
document.removeEventListener("mouseup", callback);
|
|
});
|
|
};
|