Skip to content

Commit

Permalink
[gamepad] started adding Xbox controller support
Browse files Browse the repository at this point in the history
  • Loading branch information
Grovkillen committed Mar 23, 2020
1 parent 4a2fc26 commit 94f1bfa
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
54 changes: 54 additions & 0 deletions src/gui_easy_popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ guiEasy.popper.events = function() {
document.addEventListener('click', guiEasy.popper.click, true);
document.addEventListener('change', guiEasy.popper.change, true);
document.addEventListener('focusout', guiEasy.popper.focus, true);
window.addEventListener('gamepadconnected', guiEasy.popper.gamepad, false);
window.addEventListener('gamepaddisconnected', guiEasy.popper.gamepad, false);
};

//BELOW IS FUNCTION TO INTERCEPT AND TRANSLATE THE EVENT INTO A ESP EASY EVENT//
Expand Down Expand Up @@ -67,6 +69,7 @@ guiEasy.popper.change = function (event) {
"args": x
};
if (eventDetails.type !== undefined) {
helpEasy.addToLogDOM("Calling change event: " + JSON.stringify(eventDetails), 2);
guiEasy.popper.tryCallEvent(eventDetails);
}
};
Expand All @@ -82,6 +85,7 @@ guiEasy.popper.keyboard = function (event) {
"event": event
};
if (eventDetails.type !== undefined) {
helpEasy.addToLogDOM("Calling keyboard event: " + JSON.stringify(eventDetails), 2);
guiEasy.popper.tryCallEvent(eventDetails);
}
};
Expand All @@ -101,9 +105,50 @@ guiEasy.popper.click = function (event) {
"y": event.y,
"element": event.target
};
helpEasy.addToLogDOM("Calling click event: " + JSON.stringify(eventDetails), 2);
guiEasy.popper.tryCallEvent(eventDetails);
}
};

guiEasy.popper.gamepad = function (event) {
//We only support X360 controller types (original or OEMs that address themselves as one)
const supportedGP = "Xbox 360 Controller (XInput STANDARD GAMEPAD)";
if (window.gamepads === undefined) {
window.gamepads = 0;
}
let loopInterval;
if (event.type === "gamepadconnected" && event.gamepad.id === supportedGP) {
window.gamepads++;
//controllers doesn't do event listeners so we need to query the states over and over again...
loopInterval = setInterval( function() {
let gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads : []);
for (let i = 0; i < gamepads.length; i++) {
let gp = gamepads[i];
if (gp !== null && gp.id === supportedGP) {
let currentGamepadMap = {
"LJx": Math.floor(gp.axes[0] * 100)/100,
"LJY": Math.floor(gp.axes[1] * 100)/100,
"RJx": Math.floor(gp.axes[2] * 100)/100,
"RJY": Math.floor(gp.axes[3] * 100)/100
};
guiEasy.popper.gamepad.eventListener(currentGamepadMap);
}
}
}, 1000);
}
if (event.type === "gamepaddisconnected" && event.gamepad.id === supportedGP) {
window.gamepads--;
}
if (window.gamepads === 0) {
clearInterval(loopInterval);
helpEasy.addToLogDOM("Gamepad events disabled, no gamepad active.", 2);
}
};

guiEasy.popper.gamepad.eventListener = function (gamepadMap) {
helpEasy.addToLogDOM("Calling gamepad event: " + JSON.stringify(gamepadMap), 0);
};

//ABOVE IS FUNCTION TO INTERCEPT AND TRANSLATE THE EVENT INTO A ESP EASY EVENT//
//BELOW IS THE FUNCTION TO TRIGGER ESP EASY EVENT + FIND WHAT WAS FOCUSED//
guiEasy.popper.guiEvent = function (event) {
Expand Down Expand Up @@ -359,6 +404,15 @@ guiEasy.popper.menu = function (menuToOpen) {
helpEasy.addToLogDOM("menu: " + x, 1);
};

guiEasy.popper.drawer = function (drawerToOpen) {
let drawerName = drawerToOpen.args[1];
let drawerObject = document.getElementById("drawer-" + drawerName);
let x = drawerObject.dataset;
drawerObject.classList.toggle(x.close);
drawerObject.classList.toggle(x.open);
helpEasy.addToLogDOM("drawer: " + drawerName, 1);
};

guiEasy.popper.modal = function (modalToOpen) {
let x = modalToOpen.args[1];
let y = modalToOpen.args[2];
Expand Down
9 changes: 0 additions & 9 deletions src/gui_easy_popper_extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ guiEasy.popper.modal.unlockStuff = function () {
}
};

guiEasy.popper.drawer = function (drawerToOpen) {
let drawerName = drawerToOpen.args[1];
let drawerObject = document.getElementById("drawer-" + drawerName);
let x = drawerObject.dataset;
drawerObject.classList.toggle(x.close);
drawerObject.classList.toggle(x.open);
helpEasy.addToLogDOM("drawer: " + drawerName, 1);
};

guiEasy.popper.theme = function (whatToDo) {
let what = whatToDo.args[1];
if (what === "default") {
Expand Down
4 changes: 0 additions & 4 deletions src/gui_easy_tender.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ guiEasy.tender = function (processID, processType) {
guiEasy.popper.topNotifier("unitUp","Connection with unit is re-established.", "success", 3);
}
//is the settings in gui updated?
//helpEasy.guiUpdaterSettings();
//console.log(defaultSettings);
//console.log(guiEasy.nodes);
}, guiEasy.fetchSettings.intervalGUIupdater);

helpEasy.processDone(processID, processType);
};

0 comments on commit 94f1bfa

Please sign in to comment.