UNPKG

@mesmotronic/xpad

Version:

Simplified Gamepad API for Xbox 360 and Xbox One controllers

49 lines (48 loc) 1.42 kB
import { EventDispatcher } from "conbine"; import { XpadEvent } from "../events/XpadEvent"; export class XpadStick extends EventDispatcher { constructor(x = 0, y = 0, index = -1) { super(); Object.defineProperty(this, "x", { enumerable: true, configurable: true, writable: true, value: x }); Object.defineProperty(this, "y", { enumerable: true, configurable: true, writable: true, value: y }); Object.defineProperty(this, "index", { enumerable: true, configurable: true, writable: true, value: index }); } set(x, y) { if (this.x !== x || this.y !== y) { const active = this.active; this.x = x; this.y = y; if (active !== this.active) { this.dispatchEvent(new XpadEvent(active ? XpadEvent.STICK_ACTIVE : XpadEvent.STICK_INACTIVE)); } this.dispatchEvent(new XpadEvent(XpadEvent.STICK_CHANGE, this.index)); } } get active() { return this.x !== 0 || this.y !== 0; } } /** * @deprecated Use XpadStick instead */ export class XpadAxes extends XpadStick { constructor(x = 0, y = 0) { console.warn('XpadAxes is deprecated, use XpadStick instead'); super(x, y); } }