Package Exports
- @hmans/controlfreak
- @hmans/controlfreak/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@hmans/controlfreak) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
CONTROL FREAK
tl;dr
import { Device, GamepadDevice, KeyboardDevice, VectorControl } from "controlfreak"
export const devices = [new KeyboardDevice().start(), new GamepadDevice().start()]
let activeDevice: Device
for (const device of devices) {
device.onActivity.on(() => (activeDevice = device))
}
export const stick = new VectorControl()
.addStep(({ value }) => {
if (activeDevice instanceof KeyboardDevice) {
const { isPressed } = activeDevice
value.x = isPressed("d") - isPressed("a")
value.y = isPressed("w") - isPressed("s")
}
})
.addStep(({ value }) => {
if (activeDevice instanceof GamepadDevice) {
const { device } = activeDevice
if (device) {
value.x = device.axes[0]
value.y = -device.axes[1]
}
}
})
.addStep(({ value }) => {
const length = Math.sqrt(value.x ** 2 + value.y ** 2) || 1
value.x /= length
value.y /= length
})