Gamepad code (untested)

This commit is contained in:
Alexander Yakovlev 2021-09-20 20:31:15 +07:00
parent b527583ab9
commit b34e872289
Signed by: oreolek
GPG Key ID: 8D24103F5EE2A6C0
21 changed files with 2438 additions and 0 deletions

View File

@ -19,6 +19,7 @@ If you need a lighter template without any console commands: [inkjs-boilerplate.
* Autosaving (with a restart button)
* Keyboard support (press 1-9 to select 1th-9th choices, 0 to choose 10th)
* Gamepad support (arrows or Y axis to select, A to choose)
* Great game performance (all JS is ~200Kb in size with Inkjs runtime)
* For authors: `npm watch` will auto-recompile the game on changes to JS or JSON
* Auto-recompiling from ink to JSON is not included, though

254
js/gamepad.js Normal file
View File

@ -0,0 +1,254 @@
import $ from 'jquery';
const gamepadmappings = [
require("./mappings/ps4-ff-osx.json"),
require("./mappings/ps3-ff-linux.json"),
require("./mappings/ps4-ff-linux.json"),
require("./mappings/xbone-ff-linux.json"),
require("./mappings/ps4-chrome-linux.json"),
require("./mappings/xbox360-ff-linux.json"),
require("./mappings/ps3-chrome-osx-linux.json"),
require("./mappings/ps4-chrome-windows-osx.json"),
require("./mappings/xbone-chrome-osx-linux.json"),
require("./mappings/xbox360-chrome-windows-osx.json"),
require("./mappings/logitechf310-xinput-ff-linux.json"),
require("./mappings/logitechf310-directinput-ff-osx.json"),
require("./mappings/logitechf310-xinput-chrome-linux.json"),
require("./mappings/logitechf310-directinput-ff-windows.json"),
require("./mappings/logitechf310-directinput-chrome-ff-linux.json"),
require("./mappings/logitechf310-directinput-chrome-windows-osx.json"),
]
// Gamepad HTML5 API
export default class Gamepad {
constructor(pad) {
this.gamepad = pad;
this.map = this.detectMapping(pad.id, navigator.userAgent);
this.pressed = this.getPressed();
}
detectMapping(id, browser) {
for (let map of gamepadmappings) {
var device;
for (device of map.supported) {
if ((id.indexOf(device.id) !== -1) && (browser.indexOf(device.browser) !== -1)) {
return map;
}
}
// mapping not found, return the first map for this browser
for (device of map.supported) {
if (browser.indexOf(device.browser) !== -1) {
return map;
}
}
// browser and device are not supported, just return the first map
console.warn("Browser and device are not found, gamepad support not guaranteed.");
return gamepadmappings[0];
}
}
axis(name) {
const map = this.map.axes[name];
if (map == null) {
return 0;
}
if (map.index != null) {
return this.gamepad.axes[map.index];
}
if ((map.buttonPositive != null) && this.gamepad.buttons[map.buttonPositive].pressed) {
return 1;
}
if ((map.buttonNegative != null) && this.gamepad.buttons[map.buttonNegative].pressed) {
return -1;
}
return 0;
}
button(name) {
const map = this.map.buttons[name];
if (map == null) {
return 0;
}
if ((map.index != null) && (this.gamepad.buttons[map.index] != null)) {
return this.gamepad.buttons[map.index].pressed;
}
if (map.axis != null) {
if (map.direction < 0) {
return this.gamepad.axes[map.axis] < -0.75;
} else {
return this.gamepad.axes[map.axis] > 0.75;
}
}
return false;
}
// Return the name of the pressed button
getPressed() {
for (let buttonname in this.map.buttons) {
const button = this.map.buttons[buttonname];
if ((
(this.gamepad.buttons[button.index] != null) &&
this.gamepad.buttons[button.index].pressed
) || (
(this.gamepad.axes[button.axis] < -0.75) &&
(button.direction < 0)
) || (
(this.gamepad.axes[button.axis] > 0.75) &&
(button.direction > 0)
)) {
return buttonname;
}
}
}
// Select the previous choice
selectUp (event, button, padid) {
if ((button !== "dpad up") && (button !== "left stick up")) {
return;
}
if ($(".options li").length === 0) {
return selectUpLink(event, button, padid);
}
$(".options li").removeClass("active");
const count = $(".options li").length;
window.selectedoption--;
if (window.selectedoption <= 0) {
window.selectedoption = count;
}
$(`.options li:nth-child(${window.selectedoption}`).addClass("active");
}
// Select the next choice
selectDown (event, button, padid) {
if ((button !== "dpad down") && (button !== "left stick down")) {
return;
}
if ($(".options li").length === 0) {
return selectDownLink(event, button, padid);
}
$(".options li").removeClass("active");
window.selectedoption++;
const count = $(".options li").length;
if (window.selectedoption > count) {
window.selectedoption = 1;
}
$(`.options li:nth-child(${window.selectedoption})`).addClass("active");
};
// Select the next link inside room text
selectDownLink (event, button, padid) {
let tabid = $("#current-room .active").first().attr("tabindex");
$("#current-room .active").removeClass("active");
let maxtab = 0;
for (let element of $("#current-room [tabindex]")) {
if (maxtab < $(element).attr("tabindex")) {
maxtab = $(element).attr("tabindex");
}
}
tabid = Gamepad.prototype.increaseTabindex(tabid, maxtab);
$(`#current-room [tabindex='${tabid}']`).addClass("active");
};
// Select the previous link inside room text
selectUpLink (event, button, padid) {
let tabid = $("#current-room .active").attr("tabindex");
$("#current-room .active").removeClass("active");
tabid = this.decreaseTabindex(tabid);
$(`#current-room [tabindex='${tabid}']`).addClass("active");
};
decreaseTabindex (tabid) {
tabid--;
if (tabid < 0) {
// tabindex can't be negative, choosing maximum tabindex
let maxtab = 0;
for (let element of $("#current-room [tabindex]")) {
if (maxtab < $(element).attr("tabindex")) {
maxtab = $(element).attr("tabindex");
}
}
tabid = maxtab;
}
if ($(`#current-room [tabindex='${tabid}']`).length === 0) {
return this.decreaseTabindex(tabid);
}
};
increaseTabindex (tabid, maxtab) {
if (tabid < maxtab) {
tabid++;
} else {
tabid = 0;
}
if ($(`#current-room [tabindex='${tabid}']`).length === 0) {
return Gamepad.prototype.increaseTabindex(tabid);
}
};
selectOption (event, button) {
if (button !== "a") {
return;
}
$(".options li.active").click();
};
// enter the options room
enterOptions (event, button, padid) {
if ((button !== "back") && (button !== "start")) {
return;
}
if (button === "start") {
return salet.goTo(salet.optionsRoom);
}
if ((button === "back") && (salet.currentRoom === salet.optionsRoom)) {
return salet.goBack();
}
};
// Joystick check, fires events
joystick () {
if (typeof navigator.getGamepads === "function") {
return (() => {
const result = [];
for (let pad of navigator.getGamepads()) {
if (pad != null) {
const temp = new Gamepad(pad);
if (temp.pressed != null) {
if (window.gamepads[pad.id].pressed !== temp.pressed) {
$(document).trigger("press", temp.pressed, pad.id);
}
}
if (temp.map.axes != null) {
for (let axisname = 0; axisname < temp.map.axes.length; axisname++) {
const axis = temp.map.axes[axisname];
const oldval = window.gamepads[pad.id].gamepad.axes[axis.index];
let newval = temp.gamepad.axes[axis.index];
if (Math.abs(newval) <= 0.2) {
newval = 0;
}
if (newval !== oldval) {
$(document).trigger("axis", axisname, newval, padid);
}
}
}
result.push(window.gamepads[pad.id] = temp);
} else {
result.push(undefined);
}
}
return result;
})();
}
};
init() {
// Connected gamepads (see Gamepad class)
window.gamepads = {};
window.addEventListener("gamepadconnected", e => window.gamepads[e.gamepad.id] = new Gamepad(e.gamepad));
window.addEventListener("gamepaddisconnected", e => window.gamepads[e.gamepad.id] = undefined);
setInterval(joystick, 50); // 50 = 1000 / 20 fps
if (window.selectedoption == null) {
window.selectedoption = 1;
}
$(document).on("press", Gamepad.prototype.selectUp);
$(document).on("press", Gamepad.prototype.selectDown);
$(document).on("press", Gamepad.prototype.selectOption);
$(document).on("press", Gamepad.prototype.enterOptions);
}
}

View File

@ -0,0 +1,121 @@
{
"axes": {
"dpad x": {
"index": 4
},
"dpad y": {
"index": 5
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 3
}
},
"buttons": {
"a": {
"index": 1
},
"b": {
"index": 2
},
"back": {
"index": 8
},
"dpad down": {
"axis": 5,
"direction": 1
},
"dpad left": {
"axis": 4,
"direction": -1
},
"dpad right": {
"axis": 4,
"direction": 1
},
"dpad up": {
"axis": 5,
"direction": -1
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 3,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 3,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 0
},
"y": {
"index": 3
}
},
"name": "Logitech F310 (DirectInput) Chrome/Firefox Linux",
"supported": [
{
"browser": "Chrome",
"id": "Logitech Logitech Dual Action (Vendor: 046d Product: c216)",
"os": "Linux"
},
{
"browser": "Firefox",
"id": "046d-c216-Logitech Logitech Dual Action",
"os": "Linux"
}
]
}

View File

@ -0,0 +1,120 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 3
},
"right trigger": {
"index": 5
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 8
},
"dpad down": {
"index": 13
},
"dpad left": {
"index": 14
},
"dpad right": {
"index": 15
},
"dpad up": {
"index": 12
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 3,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 3,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "Logitech F310 (DirectInput) Chrome Windows/OSX",
"supported": [
{
"browser": "Chrome",
"id": "Logitech Dual Action (STANDARD GAMEPAD Vendor: 046d Product: c216)",
"os": "Mac OS X"
},
{
"browser": "Chrome",
"id": "Logitech Dual Action (STANDARD GAMEPAD Vendor: 046d Product: c216)",
"os": "Windows NT"
}
]
}

View File

@ -0,0 +1,114 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"left trigger": {
"index": 2
},
"right stick x": {
"index": 3
},
"right stick y": {
"index": 4
},
"right trigger": {
"index": 5
}
},
"buttons": {
"a": {
"index": 1
},
"b": {
"index": 2
},
"back": {
"index": 8
},
"dpad down": {
"index": 13
},
"dpad left": {
"index": 14
},
"dpad right": {
"index": 15
},
"dpad up": {
"index": 12
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 2,
"direction": 1
},
"left stick left": {
"axis": 1,
"direction": -1
},
"left stick right": {
"axis": 1,
"direction": 1
},
"left stick up": {
"axis": 2,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 4,
"direction": 1
},
"right stick left": {
"axis": 3,
"direction": -1
},
"right stick up": {
"axis": 4,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 0
},
"y": {
"index": 3
}
},
"name": "Logitech F310 (DirectInput) Firefox OSX",
"supported": [
{
"browser": "Firefox",
"id": "46d-c216-Logitech Dual Action",
"os": "Mac OS X"
}
]
}

View File

@ -0,0 +1,115 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 3
},
"right trigger": {
"index": 5
}
},
"buttons": {
"a": {
"index": 1
},
"b": {
"index": 2
},
"back": {
"index": 8
},
"dpad down": {
"index": 14
},
"dpad left": {
"index": 15
},
"dpad right": {
"index": 16
},
"dpad up": {
"index": 13
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 3,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 3,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 0
},
"y": {
"index": 3
}
},
"name": "Logitech F310 (DirectInput) Firefox Windows",
"supported": [
{
"browser": "Firefox",
"id": "046d-c216-Logitech Dual Action",
"os": "Windows NT"
}
]
}

View File

@ -0,0 +1,118 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 3
},
"right trigger": {
"index": 5
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 8
},
"dpad down": {
"index": 13
},
"dpad left": {
"index": 14
},
"dpad right": {
"index": 15
},
"dpad up": {
"index": 12
},
"home": {
"index": 16
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 3,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 3,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "Logitech F310 (XInput) Chrome Linux",
"supported": [
{
"browser": "Chrome",
"id": "Logitech Gamepad F310 (STANDARD GAMEPAD Vendor: 046d Product: c21d)",
"os": "Linux"
}
]
}

View File

@ -0,0 +1,127 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"left trigger": {
"index": 2
},
"right stick x": {
"index": 3
},
"right stick y": {
"index": 4
},
"right trigger": {
"index": 5
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 6
},
"dpad down": {
"axis": 7,
"direction": 1
},
"dpad left": {
"axis": 6,
"direction": -1
},
"dpad right": {
"axis": 6,
"direction": 1
},
"dpad up": {
"axis": 7,
"direction": -1
},
"home": {
"index": 8
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 9
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"axis": 2,
"direction": 1
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 10
},
"right stick down": {
"axis": 4,
"direction": 1
},
"right stick left": {
"axis": 3,
"direction": -1
},
"right stick right": {
"axis": 3,
"direction": 1
},
"right stick up": {
"axis": 4,
"direction": -1
},
"right trigger": {
"axis": 5,
"direction": 1
},
"start": {
"index": 7
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "Logitech F310 (XInput) Firefox Linux",
"supported": [
{
"browser": "Firefox",
"id": "046d-c21d-Logitech Gamepad F310",
"os": "Linux"
}
]
}

View File

@ -0,0 +1,123 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 3
},
"right trigger": {
"index": 5
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 8
},
"dpad down": {
"index": 13
},
"dpad left": {
"index": 14
},
"dpad right": {
"index": 15
},
"dpad up": {
"index": 12
},
"home": {
"index": 16
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 3,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 3,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "PLAYSTATION(R)3 Controller (STANDARD GAMEPAD Vendor: 054c Product: 0268) Chrome OSX Linux",
"supported": [
{
"browser": "Chrome",
"id": "PLAYSTATION(R)3 Controller (STANDARD GAMEPAD Vendor: 054c Product: 0268)",
"os": "Mac OS X"
},
{
"browser": "Chrome",
"id": "Sony PLAYSTATION(R)3 Controller (STANDARD GAMEPAD Vendor: 054c Product: 0268)",
"os": "Linux"
}
]
}

View File

@ -0,0 +1,121 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"left trigger": {
"index": 12
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 3
},
"right trigger": {
"index": 13
}
},
"buttons": {
"a": {
"index": 14
},
"b": {
"index": 13
},
"back": {
"index": 0
},
"dpad down": {
"index": 6
},
"dpad left": {
"index": 7
},
"dpad right": {
"index": 5
},
"dpad up": {
"index": 4
},
"home": {
"index": 16
},
"left stick": {
"index": 1
},
"left shoulder": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 8
},
"right stick": {
"index": 2
},
"right stick down": {
"axis": 3,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 3,
"direction": -1
},
"right trigger": {
"index": 9
},
"right shoulder": {
"index": 11
},
"start": {
"index": 3
},
"x": {
"index": 15
},
"y": {
"index": 12
}
},
"name": "054c-0268-Sony PLAYSTATION(R)3 Controller Firefox Linux",
"supported": [
{
"browser": "Firefox",
"id": "054c-0268-Sony PLAYSTATION(R)3 Controller",
"os": "Linux"
}
]
}

View File

@ -0,0 +1,123 @@
{
"axes": {
"dpad x": {
"buttonPositive": 15,
"buttonNegative": 14
},
"dpad y": {
"buttonPositive": 13,
"buttonNegative": 12
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"left trigger": {
"buttonPositive": 6
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 3
},
"right trigger": {
"buttonPositive": 7
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 8
},
"dpad down": {
"index": 13
},
"dpad left": {
"index": 14
},
"dpad right": {
"index": 15
},
"dpad up": {
"index": 12
},
"home": {
"index": 16
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 3,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 3,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "PS4 Chrome Linux",
"supported": [
{
"browser": "Chrome",
"id": "Sony Computer Entertainment Wireless Controller (STANDARD GAMEPAD Vendor: 054c Product: 05c4)",
"os": "Linux"
}
]
}

View File

@ -0,0 +1,123 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 3
},
"right trigger": {
"index": 5
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 8
},
"dpad down": {
"index": 13
},
"dpad left": {
"index": 14
},
"dpad right": {
"index": 15
},
"dpad up": {
"index": 12
},
"home": {
"index": 16
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 3,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 3,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "PS4 Chrome Windows/OSX",
"supported": [
{
"browser": "Chrome",
"id": "Wireless Controller (STANDARD GAMEPAD Vendor: 054c Product: 05c4)",
"os": "Windows NT"
},
{
"browser": "Chrome",
"id": "Wireless Controller (STANDARD GAMEPAD Vendor: 054c Product: 05c4)",
"os": "Mac OS X"
}
]
}

View File

@ -0,0 +1,125 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"left trigger": {
"index": 3
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 5
},
"right trigger": {
"index": 4
}
},
"buttons": {
"a": {
"index": 1
},
"b": {
"index": 2
},
"back": {
"index": 8
},
"dpad down": {
"axis": 7,
"direction": 1
},
"dpad left": {
"axis": 6,
"direction": -1
},
"dpad right": {
"axis": 6,
"direction": 1
},
"dpad up": {
"axis": 7,
"direction": -1
},
"home": {
"index": 12
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 5,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 5,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 0
},
"y": {
"index": 3
}
},
"name": "PS4 Firefox Linux",
"supported": [
{
"browser": "Firefox",
"id": "054c-05c4-Sony Computer Entertainment Wireless Controller",
"os": "Linux"
}
]
}

115
js/mappings/ps4-ff-osx.json Normal file
View File

@ -0,0 +1,115 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 5
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 8
},
"dpad down": {
"index": 15
},
"dpad left": {
"index": 16
},
"dpad right": {
"index": 17
},
"dpad up": {
"index": 14
},
"home": {
"index": 12
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 5,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 5,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "PS4 Firefox OSX",
"supported": [
{
"browser": "Firefox",
"id": "54c-5c4-Wireless Controller",
"os": "Mac OS X"
}
]
}

View File

@ -0,0 +1,127 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"left trigger": {
"index": 2
},
"right stick x": {
"index": 3
},
"right stick y": {
"index": 4
},
"right trigger": {
"index": 5
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 6
},
"dpad down": {
"axis": 7,
"direction": 1
},
"dpad left": {
"axis": 6,
"direction": -1
},
"dpad right": {
"axis": 6,
"direction": 1
},
"dpad up": {
"axis": 7,
"direction": -1
},
"home": {
"index": 8
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 9
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"axis": 2,
"direction": 1
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 10
},
"right stick down": {
"axis": 4,
"direction": 1
},
"right stick left": {
"axis": 3,
"direction": -1
},
"right stick right": {
"axis": 3,
"direction": 1
},
"right stick up": {
"axis": 4,
"direction": -1
},
"right trigger": {
"axis": 5,
"direction": 1
},
"start": {
"index": 7
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "XBone Chrome Linux",
"supported": [
{
"browser": "Chrome",
"id": "Microsoft Controller (Vendor: 045e Product: 02d1)",
"os": "Linux"
}
]
}

View File

@ -0,0 +1,114 @@
{
"axes": {
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 3
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 8
},
"dpad down": {
"index": 13
},
"dpad left": {
"index": 14
},
"dpad right": {
"index": 15
},
"dpad up": {
"index": 12
},
"home": {
"index": 16
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 3,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 3,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "Xbox One Chrome OSX Linux",
"supported": [
{
"browser": "Chrome",
"id": "©Microsoft Corporation Controller (STANDARD GAMEPAD Vendor: 045e Product: 028e)",
"os": "Linux"
},
{
"browser": "Chrome",
"id": "Xbox One Controller (STANDARD GAMEPAD Vendor: 02d1 Product: 045e)",
"os": "Mac OS X"
}
]
}

View File

@ -0,0 +1,127 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"left trigger": {
"index": 2
},
"right stick x": {
"index": 3
},
"right stick y": {
"index": 4
},
"right trigger": {
"index": 5
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 6
},
"dpad down": {
"axis": 7,
"direction": 1
},
"dpad left": {
"axis": 6,
"direction": -1
},
"dpad right": {
"axis": 6,
"direction": 1
},
"dpad up": {
"axis": 7,
"direction": -1
},
"home": {
"index": 8
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 9
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"axis": 2,
"direction": 1
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 10
},
"right stick down": {
"axis": 4,
"direction": 1
},
"right stick left": {
"axis": 3,
"direction": -1
},
"right stick right": {
"axis": 3,
"direction": 1
},
"right stick up": {
"axis": 4,
"direction": -1
},
"right trigger": {
"axis": 5,
"direction": 1
},
"start": {
"index": 7
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "Xbone Firefox Linux",
"supported": [
{
"browser": "Firefox",
"id": "045e-02d1-Microsoft X-Box One pad",
"os": "Linux"
}
]
}

View File

@ -0,0 +1,123 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 3
},
"right trigger": {
"index": 5
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 8
},
"dpad down": {
"index": 13
},
"dpad left": {
"index": 14
},
"dpad right": {
"index": 15
},
"dpad up": {
"index": 12
},
"home": {
"index": 16
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 3,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 3,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "Xbox 360 Chrome Windows/OSX",
"supported": [
{
"browser": "Chrome",
"id": "Xbox 360 Controller (STANDARD GAMEPAD Vendor: 028e Product: 045e)",
"os": "Mac OS X"
},
{
"browser": "Chrome",
"id": "Xbox 360 Controller (XInput STANDARD GAMEPAD)",
"os": "Windows NT"
}
]
}

View File

@ -0,0 +1,127 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"left trigger": {
"index": 2
},
"right stick x": {
"index": 3
},
"right stick y": {
"index": 4
},
"right trigger": {
"index": 5
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 6
},
"dpad down": {
"axis": 7,
"direction": 1
},
"dpad left": {
"axis": 6,
"direction": -1
},
"dpad right": {
"axis": 6,
"direction": 1
},
"dpad up": {
"axis": 7,
"direction": -1
},
"home": {
"index": 8
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 9
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"axis": 2,
"direction": 1
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 10
},
"right stick down": {
"axis": 4,
"direction": 1
},
"right stick left": {
"axis": 3,
"direction": -1
},
"right stick right": {
"axis": 3,
"direction": 1
},
"right stick up": {
"axis": 4,
"direction": -1
},
"right trigger": {
"axis": 5,
"direction": 1
},
"start": {
"index": 7
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "Xbox 360 Firefox Linux",
"supported": [
{
"browser": "Firefox",
"id": "045e-028e-Microsoft X-Box 360 pad",
"os": "Linux"
}
]
}

View File

@ -0,0 +1,115 @@
{
"axes": {
"dpad x": {
"index": 6
},
"dpad y": {
"index": 7
},
"left stick x": {
"index": 0
},
"left stick y": {
"index": 1
},
"right stick x": {
"index": 2
},
"right stick y": {
"index": 3
},
"right trigger": {
"index": 5
}
},
"buttons": {
"a": {
"index": 0
},
"b": {
"index": 1
},
"back": {
"index": 8
},
"dpad down": {
"index": 13
},
"dpad left": {
"index": 14
},
"dpad right": {
"index": 15
},
"dpad up": {
"index": 12
},
"left shoulder": {
"index": 4
},
"left stick": {
"index": 10
},
"left stick down": {
"axis": 1,
"direction": 1
},
"left stick left": {
"axis": 0,
"direction": -1
},
"left stick right": {
"axis": 0,
"direction": 1
},
"left stick up": {
"axis": 1,
"direction": -1
},
"left trigger": {
"index": 6
},
"right shoulder": {
"index": 5
},
"right stick": {
"index": 11
},
"right stick down": {
"axis": 3,
"direction": 1
},
"right stick left": {
"axis": 2,
"direction": -1
},
"right stick right": {
"axis": 2,
"direction": 1
},
"right stick up": {
"axis": 3,
"direction": -1
},
"right trigger": {
"index": 7
},
"start": {
"index": 9
},
"x": {
"index": 2
},
"y": {
"index": 3
}
},
"name": "Xbox 360 FF Windows",
"supported": [
{
"browser": "Firefox",
"id": "xinput",
"os": "Windows NT"
}
]
}

View File

@ -1,4 +1,5 @@
import jQuery from 'jquery'
import Gamepad from './gamepad'
const inkjs = require('inkjs').Story;
/**
* Path to your game's compiled JSON.
@ -170,3 +171,7 @@ jQuery(document).on('keydown', function(key) {
}
return false;
});
jQuery(document).on('ready', function() {
Gamepad.prototype.init()
})