Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mamayaya1
GitHub Repository: mamayaya1/game
Path: blob/main/projects/HexGL/bkcore.coffee/controllers/GamepadController.js
4627 views
1
// Generated by CoffeeScript 1.6.3
2
/*
3
GamepadController (Orientation + buttons) for touch devices
4
5
@class bkcore.GamepadController
6
@author Mahesh Kulkarni <http://twitter.com/maheshkk>
7
*/
8
9
10
(function() {
11
var GamepadController, exports, _base;
12
13
GamepadController = (function() {
14
GamepadController.isCompatible = function() {
15
return ('getGamepads' in navigator) || ('webkitGetGamepads' in navigator);
16
};
17
18
/*
19
Creates a new GamepadController
20
*/
21
22
23
function GamepadController(buttonPressCallback) {
24
this.buttonPressCallback = buttonPressCallback;
25
this.active = true;
26
this.leftStickArray = [];
27
this.rightStickArray = [];
28
}
29
30
/*
31
@public
32
*/
33
34
35
GamepadController.prototype.updateAvailable = function() {
36
var accel, gamepads, gp, lt, rt, sel, _ref, _ref1, _ref2, _ref3;
37
if (!this.active) {
38
return false;
39
}
40
gamepads = navigator.getGamepads ? navigator.getGamepads() : navigator.webkitGetGamepads();
41
if (!(gamepads != null ? gamepads[0] : void 0)) {
42
return false;
43
}
44
gp = gamepads[0];
45
if ((gp.buttons == null) || (gp.axes == null)) {
46
return;
47
}
48
this.lstickx = gp.axes[0];
49
accel = gp.buttons[0];
50
lt = gp.buttons[6];
51
rt = gp.buttons[7];
52
sel = gp.buttons[8];
53
this.acceleration = (_ref = accel.pressed) != null ? _ref : accel;
54
this.ltrigger = (_ref1 = lt.pressed) != null ? _ref1 : lt;
55
this.rtrigger = (_ref2 = rt.pressed) != null ? _ref2 : rt;
56
this.select = (_ref3 = sel.pressed) != null ? _ref3 : sel;
57
this.buttonPressCallback(this);
58
return true;
59
};
60
61
return GamepadController;
62
63
})();
64
65
exports = exports != null ? exports : this;
66
67
exports.bkcore || (exports.bkcore = {});
68
69
(_base = exports.bkcore).controllers || (_base.controllers = {});
70
71
exports.bkcore.controllers.GamepadController = GamepadController;
72
73
}).call(this);
74
75