Current section
Files
Jump to
Current section
Files
src/rcade/inputs/controls_ffi.mjs
import { PLAYER_1, PLAYER_2, SYSTEM, STATUS, on } from "@rcade/plugin-input-classic";
import { Controls, SystemButtons } from "./controls.mjs";
export const read_player = (player) => {
const input = player === 1 ? PLAYER_1 : PLAYER_2;
return new Controls(
input.DPAD.up,
input.DPAD.down,
input.DPAD.left,
input.DPAD.right,
input.A,
input.B,
);
};
export const read_system = () => {
return new SystemButtons(SYSTEM.ONE_PLAYER, SYSTEM.TWO_PLAYER);
};
export const connected = () => {
return STATUS.connected;
};
export const subscribe = (callback) => {
return on("press", (data) => {
callback(data.player ?? 0, data.button, data.type === "system");
});
};