70 lines
1.6 KiB
JavaScript
70 lines
1.6 KiB
JavaScript
// Generated by CoffeeScript 1.6.3
|
|
/*
|
|
GamepadController (Orientation + buttons) for touch devices
|
|
|
|
@class bkcore.GamepadController
|
|
@author Mahesh Kulkarni <http://twitter.com/maheshkk>
|
|
*/
|
|
|
|
|
|
(function() {
|
|
var GamepadController, exports, _base;
|
|
|
|
GamepadController = (function() {
|
|
GamepadController.isCompatible = function() {
|
|
return ('getGamepads' in navigator) || ('webkitGetGamepads' in navigator);
|
|
};
|
|
|
|
/*
|
|
Creates a new GamepadController
|
|
*/
|
|
|
|
|
|
function GamepadController(buttonPressCallback) {
|
|
this.buttonPressCallback = buttonPressCallback;
|
|
this.active = true;
|
|
this.leftStickArray = [];
|
|
this.rightStickArray = [];
|
|
}
|
|
|
|
/*
|
|
@public
|
|
*/
|
|
|
|
|
|
GamepadController.prototype.updateAvailable = function() {
|
|
var gamepads, gp;
|
|
if (!this.active) {
|
|
return false;
|
|
}
|
|
gamepads = navigator.getGamepads ? navigator.getGamepads() : navigator.webkitGetGamepads();
|
|
if (!(gamepads != null ? gamepads[0] : void 0)) {
|
|
return false;
|
|
}
|
|
gp = gamepads[0];
|
|
if ((gp.buttons == null) || (gp.axes == null)) {
|
|
return;
|
|
}
|
|
this.acceleration = gp.buttons[0];
|
|
this.lstickx = gp.axes[0];
|
|
this.ltrigger = gp.buttons[6];
|
|
this.rtrigger = gp.buttons[7];
|
|
this.select = gp.buttons[8];
|
|
this.buttonPressCallback(this);
|
|
return true;
|
|
};
|
|
|
|
return GamepadController;
|
|
|
|
})();
|
|
|
|
exports = exports != null ? exports : this;
|
|
|
|
exports.bkcore || (exports.bkcore = {});
|
|
|
|
(_base = exports.bkcore).controllers || (_base.controllers = {});
|
|
|
|
exports.bkcore.controllers.GamepadController = GamepadController;
|
|
|
|
}).call(this);
|