Path: blob/main/projects/HexGL/bkcore.coffee/controllers/GamepadController.js
4627 views
// Generated by CoffeeScript 1.6.31/*2GamepadController (Orientation + buttons) for touch devices34@class bkcore.GamepadController5@author Mahesh Kulkarni <http://twitter.com/maheshkk>6*/789(function() {10var GamepadController, exports, _base;1112GamepadController = (function() {13GamepadController.isCompatible = function() {14return ('getGamepads' in navigator) || ('webkitGetGamepads' in navigator);15};1617/*18Creates a new GamepadController19*/202122function GamepadController(buttonPressCallback) {23this.buttonPressCallback = buttonPressCallback;24this.active = true;25this.leftStickArray = [];26this.rightStickArray = [];27}2829/*30@public31*/323334GamepadController.prototype.updateAvailable = function() {35var accel, gamepads, gp, lt, rt, sel, _ref, _ref1, _ref2, _ref3;36if (!this.active) {37return false;38}39gamepads = navigator.getGamepads ? navigator.getGamepads() : navigator.webkitGetGamepads();40if (!(gamepads != null ? gamepads[0] : void 0)) {41return false;42}43gp = gamepads[0];44if ((gp.buttons == null) || (gp.axes == null)) {45return;46}47this.lstickx = gp.axes[0];48accel = gp.buttons[0];49lt = gp.buttons[6];50rt = gp.buttons[7];51sel = gp.buttons[8];52this.acceleration = (_ref = accel.pressed) != null ? _ref : accel;53this.ltrigger = (_ref1 = lt.pressed) != null ? _ref1 : lt;54this.rtrigger = (_ref2 = rt.pressed) != null ? _ref2 : rt;55this.select = (_ref3 = sel.pressed) != null ? _ref3 : sel;56this.buttonPressCallback(this);57return true;58};5960return GamepadController;6162})();6364exports = exports != null ? exports : this;6566exports.bkcore || (exports.bkcore = {});6768(_base = exports.bkcore).controllers || (_base.controllers = {});6970exports.bkcore.controllers.GamepadController = GamepadController;7172}).call(this);737475