185 lines
8.1 KiB
JavaScript
185 lines
8.1 KiB
JavaScript
// Rôle : centralise les options, palettes et helpers purs de l'outil Combos.
|
||
export const DEVICE_OPTIONS = [
|
||
{ value: "playstation", label: "PlayStation" },
|
||
{ value: "xbox", label: "Xbox" },
|
||
{ value: "switch", label: "Switch" },
|
||
{ value: "n64", label: "Nintendo 64" },
|
||
{ value: "keyboardMouse", label: "Clavier/Souris" }
|
||
];
|
||
|
||
export const SPECIAL_INPUT_GROUP = { title: "Spéciale", column: "actions", inputs: [["button", "fist"], ["button", "foot"], ["button", "grab"], ["button", "protect"], ["button", "shoot"]] };
|
||
|
||
export const DEVICE_GROUPS = {
|
||
playstation: [
|
||
{ title: "Directions", kind: "directions", column: "movement", inputs: [["direction", "up-left"], ["direction", "up"], ["direction", "up-right"], ["direction", "left"], null, ["direction", "right"], ["direction", "down-left"], ["direction", "down"], ["direction", "down-right"]] },
|
||
{ title: "Actions", column: "actions", inputs: [["button", "triangle"], ["button", "circle"], ["button", "cross"], ["button", "square"], ["button", "l1"], ["button", "r1"], ["button", "l2"], ["button", "r2"]] },
|
||
SPECIAL_INPUT_GROUP,
|
||
{ title: "Système", inputs: [["button", "options"], ["button", "share"], ["button", "l3"], ["button", "r3"]] }
|
||
],
|
||
xbox: [
|
||
{ title: "Directions", kind: "directions", column: "movement", inputs: [["direction", "up-left"], ["direction", "up"], ["direction", "up-right"], ["direction", "left"], null, ["direction", "right"], ["direction", "down-left"], ["direction", "down"], ["direction", "down-right"]] },
|
||
{ title: "Actions", column: "actions", inputs: [["button", "a"], ["button", "b"], ["button", "x"], ["button", "y"], ["button", "lb"], ["button", "rb"], ["button", "lt"], ["button", "rt"]] },
|
||
SPECIAL_INPUT_GROUP,
|
||
{ title: "Système", inputs: [["button", "menu"], ["button", "view"], ["button", "ls"], ["button", "rs"]] }
|
||
],
|
||
switch: [
|
||
{ title: "Directions", kind: "directions", column: "movement", inputs: [["direction", "up-left"], ["direction", "up"], ["direction", "up-right"], ["direction", "left"], null, ["direction", "right"], ["direction", "down-left"], ["direction", "down"], ["direction", "down-right"]] },
|
||
{ title: "Actions", column: "actions", inputs: [["button", "a"], ["button", "b"], ["button", "x"], ["button", "y"], ["button", "l"], ["button", "r"], ["button", "zl"], ["button", "zr"]] },
|
||
SPECIAL_INPUT_GROUP,
|
||
{ title: "Système", inputs: [["button", "plus"], ["button", "minus"], ["button", "ls"], ["button", "rs"]] }
|
||
],
|
||
n64: [
|
||
{ title: "Stick", kind: "directions", column: "movement", inputs: [["direction", "stick-up-left"], ["direction", "stick-up"], ["direction", "stick-up-right"], ["direction", "stick-left"], null, ["direction", "stick-right"], ["direction", "stick-down-left"], ["direction", "stick-down"], ["direction", "stick-down-right"]] },
|
||
{ title: "D-Pad", kind: "directions", column: "movement", inputs: [["direction", "up-left"], ["direction", "up"], ["direction", "up-right"], ["direction", "left"], null, ["direction", "right"], ["direction", "down-left"], ["direction", "down"], ["direction", "down-right"]] },
|
||
{ title: "Actions", column: "actions", inputs: [["button", "a"], ["button", "b"], ["button", "z"], ["button", "start"], ["button", "l"], ["button", "r"]] },
|
||
SPECIAL_INPUT_GROUP,
|
||
{ title: "C-buttons", kind: "directions", inputs: [["button", "c-up"], ["button", "c-down"], ["button", "c-left"], ["button", "c-right"]] }
|
||
]
|
||
};
|
||
|
||
export const KEYBOARD_GROUPS = {
|
||
azerty: [
|
||
{ title: "ZQSD", kind: "directions", column: "movement", inputs: [null, ["key", "z"], null, ["key", "q"], ["key", "s"], ["key", "d"], null, null, null] },
|
||
{ title: "Flèches", kind: "directions", column: "movement", inputs: [null, ["direction", "up"], null, ["direction", "left"], ["direction", "down"], ["direction", "right"], null, null, null] },
|
||
{ title: "Touches", column: "actions", inputs: [["key", "ctrl"], ["key", "alt"], ["key", "shift"], ["key", "space"], ["key", "enter"], ["key", "tab"], ["key", "e"], ["key", "a"], ["key", "r"], ["key", "f"]] },
|
||
SPECIAL_INPUT_GROUP,
|
||
{ title: "Souris", inputs: [["mouse", "left"], ["mouse", "right"], ["mouse", "middle"], ["mouse", "wheel-up"], ["mouse", "wheel-down"]] }
|
||
],
|
||
qwerty: [
|
||
{ title: "WASD", kind: "directions", column: "movement", inputs: [null, ["key", "w"], null, ["key", "a"], ["key", "s"], ["key", "d"], null, null, null] },
|
||
{ title: "Flèches", kind: "directions", column: "movement", inputs: [null, ["direction", "up"], null, ["direction", "left"], ["direction", "down"], ["direction", "right"], null, null, null] },
|
||
{ title: "Touches", column: "actions", inputs: [["key", "ctrl"], ["key", "alt"], ["key", "shift"], ["key", "space"], ["key", "enter"], ["key", "tab"], ["key", "e"], ["key", "q"], ["key", "r"], ["key", "f"]] },
|
||
SPECIAL_INPUT_GROUP,
|
||
{ title: "Souris", inputs: [["mouse", "left"], ["mouse", "right"], ["mouse", "middle"], ["mouse", "wheel-up"], ["mouse", "wheel-down"]] }
|
||
]
|
||
};
|
||
|
||
export const INPUT_LABELS = {
|
||
triangle: "△",
|
||
circle: "○",
|
||
cross: "×",
|
||
square: "□",
|
||
options: "Options",
|
||
share: "Share",
|
||
up: "↑",
|
||
down: "↓",
|
||
left: "←",
|
||
right: "→",
|
||
"up-left": "↖",
|
||
"up-right": "↗",
|
||
"down-left": "↙",
|
||
"down-right": "↘",
|
||
"stick-up": "↑",
|
||
"stick-down": "↓",
|
||
"stick-left": "←",
|
||
"stick-right": "→",
|
||
"stick-up-left": "↖",
|
||
"stick-up-right": "↗",
|
||
"stick-down-left": "↙",
|
||
"stick-down-right": "↘",
|
||
plus: "+",
|
||
minus: "-",
|
||
"c-up": "C↑",
|
||
"c-down": "C↓",
|
||
"c-left": "C←",
|
||
"c-right": "C→",
|
||
fist: "Poing",
|
||
foot: "Pied",
|
||
grab: "Grab",
|
||
protect: "Protect",
|
||
shoot: "Shoot",
|
||
space: "Espace"
|
||
};
|
||
|
||
export const INPUT_ICONS = {
|
||
fist: "fist",
|
||
foot: "foot",
|
||
grab: "grab",
|
||
protect: "shield",
|
||
shoot: "gun"
|
||
};
|
||
|
||
export const MOUSE_LABELS = {
|
||
left: "Clic G",
|
||
right: "Clic D",
|
||
middle: "Molette",
|
||
"wheel-up": "Molette ↑",
|
||
"wheel-down": "Molette ↓"
|
||
};
|
||
|
||
export function getInputLabel(input) {
|
||
const value = String(input?.value || "");
|
||
if (input?.kind === "key" && value.length === 1) return value.toUpperCase();
|
||
if (input?.kind === "mouse") return MOUSE_LABELS[value] || value;
|
||
return INPUT_LABELS[value] || value.toUpperCase();
|
||
}
|
||
|
||
export function inputKey(input) {
|
||
return `${input.kind}:${input.value}:${input.hold ? "hold" : ""}:${input.holdMs || 0}`;
|
||
}
|
||
|
||
export function createInput(kind, value, holdMs = 0) {
|
||
const input = { kind, value };
|
||
if (holdMs > 0) input.holdMs = holdMs;
|
||
return input;
|
||
}
|
||
|
||
export function getHoldSeconds(input) {
|
||
return Math.round((Number(input?.holdMs) || 0) / 1000);
|
||
}
|
||
|
||
export function formatHoldLabel(input) {
|
||
const seconds = getHoldSeconds(input);
|
||
if (!seconds) return input?.hold ? "hold" : "";
|
||
return `${seconds}s`;
|
||
}
|
||
|
||
export function parseHoldSeconds(value) {
|
||
const seconds = Number.parseInt(String(value || "").replace(/[^\d]/g, ""), 10);
|
||
if (!Number.isInteger(seconds) || seconds <= 0) return 0;
|
||
return Math.min(99, seconds);
|
||
}
|
||
|
||
export function isDirectionInput(input) {
|
||
return input?.kind === "direction";
|
||
}
|
||
|
||
export function createCombo(context, id, name, category, inputs, fallbackName, device) {
|
||
const combo = {
|
||
id: id || context.uid("combo"),
|
||
name: name.trim() || fallbackName,
|
||
device,
|
||
inputs: inputs.map((step) => step.map((input) => ({ ...input }))).filter((step) => step.length)
|
||
};
|
||
if (category.trim()) combo.category = category.trim();
|
||
return combo;
|
||
}
|
||
|
||
export function normalizeCustomKey(value) {
|
||
return String(value || "")
|
||
.trim()
|
||
.replace(/\s+/g, " ")
|
||
.slice(0, 16);
|
||
}
|
||
|
||
export function getPaletteGroups(device, keyboardLayout) {
|
||
return device === "keyboardMouse" ? KEYBOARD_GROUPS[keyboardLayout] : DEVICE_GROUPS[device] || DEVICE_GROUPS.playstation;
|
||
}
|
||
|
||
export function getPaletteColumns(groups) {
|
||
return [
|
||
groups.filter((group) => group.column === "movement"),
|
||
groups.filter((group) => group.column !== "movement")
|
||
];
|
||
}
|
||
|
||
export function getComboCategory(combo) {
|
||
return String(combo?.category || "").trim();
|
||
}
|
||
|
||
export function setComboItemCategory(combo, category) {
|
||
const nextCombo = { ...combo };
|
||
if (category) nextCombo.category = category;
|
||
else delete nextCombo.category;
|
||
return nextCombo;
|
||
}
|