export class GamepadDevice {
    previousButtons = new Map();
    poll(gamepads, deadZone = 0.1) {
        const snapshots = [];
        for (const gamepad of gamepads) {
            if (!gamepad?.connected) {
                continue;
            }
            const key = `${gamepad.index}:${gamepad.id}`;
            const previous = this.previousButtons.get(key) ?? [];
            const buttons = gamepad.buttons.map((button, index) => {
                const down = button.pressed || button.value > 0.5;
                const wasDown = previous[index] ?? false;
                return Object.freeze({ down, pressed: down && !wasDown, released: !down && wasDown });
            });
            snapshots.push(Object.freeze({
                id: gamepad.id,
                index: gamepad.index,
                axes: Object.freeze(gamepad.axes.map((axis) => (Math.abs(axis) < deadZone ? 0 : axis))),
                buttons: Object.freeze(buttons)
            }));
            this.previousButtons.set(key, buttons.map((button) => button.down));
        }
        return snapshots;
    }
}
//# sourceMappingURL=GamepadDevice.js.map