Skip to content

Commit

Permalink
[gamepad] added rumble "weak", "normal", "strong" (only for chrome)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grovkillen committed Mar 24, 2020
1 parent 2b89dce commit 852127f
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/gui_easy_popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ guiEasy.popper.gamepad = function (event) {
if (gp !== null && gp.id.toUpperCase().includes(supportedGP) && event.gamepad.mapping === "standard") {
index++;
let currentGamepadMap = {
"gamepadObject": gp,
"gamepad": index,
"joystick": {
"left": {
Expand Down Expand Up @@ -189,12 +190,36 @@ guiEasy.popper.gamepad.eventListener = function (gamepadMap) {
//add key combos and stuff here
if (gamepadMap.button.a === 1) {
// call an event using event details + try call
console.log("gamepad " + gamepadMap.gamepad + "'s A button pressed");
guiEasy.popper.gamepad.vibrate(gamepadMap.gamepadObject, "strong");
}
};

guiEasy.popper.gamepad.vibrate = function (type = "normal") {

guiEasy.popper.gamepad.vibrate = function (gamepad, type = "normal") {
//This only work in Chrome at the moment...
if (type === "weak") {
gamepad.vibrationActuator.playEffect("dual-rumble", {
startDelay: 0,
duration: 250,
weakMagnitude: 0.2,
strongMagnitude: 0
});
}
if (type === "normal") {
gamepad.vibrationActuator.playEffect("dual-rumble", {
startDelay: 0,
duration: 500,
weakMagnitude: 1.0,
strongMagnitude: 0
});
}
if (type === "strong") {
gamepad.vibrationActuator.playEffect("dual-rumble", {
startDelay: 0,
duration: 1000,
weakMagnitude: 1.0,
strongMagnitude: 1.0
});
}
};

guiEasy.popper.gamepad.thrust = function (x, y) {
Expand Down

0 comments on commit 852127f

Please sign in to comment.