fix chrome and edge gamepad support. reenable keyboard
This commit is contained in:
parent
d0a063cebb
commit
bb0a110bcd
29
dist/tetrion.js
vendored
29
dist/tetrion.js
vendored
@ -249,6 +249,9 @@ var gamepadAPI = {
|
|||||||
console.log('Gamepad disconnected.');
|
console.log('Gamepad disconnected.');
|
||||||
},
|
},
|
||||||
update: function() {
|
update: function() {
|
||||||
|
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
||||||
|
if(!isFirefox)
|
||||||
|
gamepadAPI.controller = window.navigator.getGamepads()[0];
|
||||||
gamepadAPI.buttonsCache = [];
|
gamepadAPI.buttonsCache = [];
|
||||||
for (var k = 0; k < gamepadAPI.buttonsStatus.length; k++) {
|
for (var k = 0; k < gamepadAPI.buttonsStatus.length; k++) {
|
||||||
gamepadAPI.buttonsCache[k] = gamepadAPI.buttonsStatus[k];
|
gamepadAPI.buttonsCache[k] = gamepadAPI.buttonsStatus[k];
|
||||||
@ -364,8 +367,8 @@ var UserInputs = {
|
|||||||
if (this.nDeciframes >= deciDAS) {
|
if (this.nDeciframes >= deciDAS) {
|
||||||
this.nDeciframes = 0;
|
this.nDeciframes = 0;
|
||||||
this.isGamepadButtonDown = true;
|
this.isGamepadButtonDown = true;
|
||||||
if(isContained)
|
//if(isContained)
|
||||||
this.gamepadQueue.push(finds);
|
// this.gamepadQueue.push(finds);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.nDeciframes >= deciARR && isContained) {
|
if (this.nDeciframes >= deciARR && isContained) {
|
||||||
@ -376,10 +379,9 @@ var UserInputs = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
gamepadDown(finds) {
|
gamepadDown(finds) {
|
||||||
var DAS = 6;
|
var DAS = 5;
|
||||||
var ARR = 3;
|
var ARR = 4;
|
||||||
var isContained = this.gpButtons.includes(finds);
|
var isContained = this.gpButtons.includes(finds);
|
||||||
|
|
||||||
var isDas = true; //this.gpButtons.includes("DPad-Left") || this.gpButtons.includes("DPad-Right") ||
|
var isDas = true; //this.gpButtons.includes("DPad-Left") || this.gpButtons.includes("DPad-Right") ||
|
||||||
//this.gpButtons.includes("DPad-Up") || this.gpButtons.includes("DPad-Down");
|
//this.gpButtons.includes("DPad-Up") || this.gpButtons.includes("DPad-Down");
|
||||||
|
|
||||||
@ -467,6 +469,11 @@ var UserInputs = {
|
|||||||
this.isKeyDown = false;
|
this.isKeyDown = false;
|
||||||
this.keyboardKeys[event.keyCode] = false;
|
this.keyboardKeys[event.keyCode] = false;
|
||||||
},
|
},
|
||||||
|
gamepadButtonClear() {
|
||||||
|
gpButtons = [];
|
||||||
|
isGamepadDown = false;
|
||||||
|
isGamepadButtonDown = false;
|
||||||
|
},
|
||||||
isDown: false,
|
isDown: false,
|
||||||
isKeyDown: false,
|
isKeyDown: false,
|
||||||
isGamepadDown: false,
|
isGamepadDown: false,
|
||||||
@ -758,13 +765,14 @@ Tetris.prototype = {
|
|||||||
var deltaTime = this.currentTime - this.prevTime;
|
var deltaTime = this.currentTime - this.prevTime;
|
||||||
|
|
||||||
|
|
||||||
if(deltaTime >= 1) // 600hz
|
if(deltaTime >= 1) { // 600hz
|
||||||
inputs.incDeciframes();
|
inputs.incDeciframes();
|
||||||
|
inputs.processGamepadInput();
|
||||||
if(deltaTime > 10)
|
}
|
||||||
|
if(deltaTime >= 10)
|
||||||
{
|
{
|
||||||
inputs.incFrame();
|
inputs.incFrame();
|
||||||
inputs.processGamepadInput();
|
|
||||||
//inputs.processKeyShift();
|
//inputs.processKeyShift();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -815,7 +823,7 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
inputs.updateGamepad();
|
inputs.updateGamepad();
|
||||||
|
|
||||||
if(deltaTime > 5)
|
if(deltaTime >= 5)
|
||||||
{
|
{
|
||||||
inputs.processButtons();
|
inputs.processButtons();
|
||||||
}
|
}
|
||||||
@ -851,6 +859,7 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
}
|
}
|
||||||
inputs.gamepadQueue = [];
|
inputs.gamepadQueue = [];
|
||||||
|
inputs.gamepadButtonClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deltaTime > this.interval) {
|
if (deltaTime > this.interval) {
|
||||||
|
@ -13,6 +13,9 @@ var gamepadAPI = {
|
|||||||
console.log('Gamepad disconnected.');
|
console.log('Gamepad disconnected.');
|
||||||
},
|
},
|
||||||
update: function() {
|
update: function() {
|
||||||
|
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
||||||
|
if(!isFirefox)
|
||||||
|
gamepadAPI.controller = window.navigator.getGamepads()[0];
|
||||||
gamepadAPI.buttonsCache = [];
|
gamepadAPI.buttonsCache = [];
|
||||||
for (var k = 0; k < gamepadAPI.buttonsStatus.length; k++) {
|
for (var k = 0; k < gamepadAPI.buttonsStatus.length; k++) {
|
||||||
gamepadAPI.buttonsCache[k] = gamepadAPI.buttonsStatus[k];
|
gamepadAPI.buttonsCache[k] = gamepadAPI.buttonsStatus[k];
|
||||||
|
14
src/input.js
14
src/input.js
@ -50,8 +50,8 @@ var UserInputs = {
|
|||||||
if (this.nDeciframes >= deciDAS) {
|
if (this.nDeciframes >= deciDAS) {
|
||||||
this.nDeciframes = 0;
|
this.nDeciframes = 0;
|
||||||
this.isGamepadButtonDown = true;
|
this.isGamepadButtonDown = true;
|
||||||
if(isContained)
|
//if(isContained)
|
||||||
this.gamepadQueue.push(finds);
|
// this.gamepadQueue.push(finds);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.nDeciframes >= deciARR && isContained) {
|
if (this.nDeciframes >= deciARR && isContained) {
|
||||||
@ -62,10 +62,9 @@ var UserInputs = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
gamepadDown(finds) {
|
gamepadDown(finds) {
|
||||||
var DAS = 6;
|
var DAS = 5;
|
||||||
var ARR = 3;
|
var ARR = 4;
|
||||||
var isContained = this.gpButtons.includes(finds);
|
var isContained = this.gpButtons.includes(finds);
|
||||||
|
|
||||||
var isDas = true; //this.gpButtons.includes("DPad-Left") || this.gpButtons.includes("DPad-Right") ||
|
var isDas = true; //this.gpButtons.includes("DPad-Left") || this.gpButtons.includes("DPad-Right") ||
|
||||||
//this.gpButtons.includes("DPad-Up") || this.gpButtons.includes("DPad-Down");
|
//this.gpButtons.includes("DPad-Up") || this.gpButtons.includes("DPad-Down");
|
||||||
|
|
||||||
@ -153,6 +152,11 @@ var UserInputs = {
|
|||||||
this.isKeyDown = false;
|
this.isKeyDown = false;
|
||||||
this.keyboardKeys[event.keyCode] = false;
|
this.keyboardKeys[event.keyCode] = false;
|
||||||
},
|
},
|
||||||
|
gamepadButtonClear() {
|
||||||
|
gpButtons = [];
|
||||||
|
isGamepadDown = false;
|
||||||
|
isGamepadButtonDown = false;
|
||||||
|
},
|
||||||
isDown: false,
|
isDown: false,
|
||||||
isKeyDown: false,
|
isKeyDown: false,
|
||||||
isGamepadDown: false,
|
isGamepadDown: false,
|
||||||
|
12
src/main.js
12
src/main.js
@ -272,13 +272,14 @@ Tetris.prototype = {
|
|||||||
var deltaTime = this.currentTime - this.prevTime;
|
var deltaTime = this.currentTime - this.prevTime;
|
||||||
|
|
||||||
|
|
||||||
if(deltaTime >= 1) // 600hz
|
if(deltaTime >= 1) { // 600hz
|
||||||
inputs.incDeciframes();
|
inputs.incDeciframes();
|
||||||
|
inputs.processGamepadInput();
|
||||||
if(deltaTime > 10)
|
}
|
||||||
|
if(deltaTime >= 10)
|
||||||
{
|
{
|
||||||
inputs.incFrame();
|
inputs.incFrame();
|
||||||
inputs.processGamepadInput();
|
|
||||||
//inputs.processKeyShift();
|
//inputs.processKeyShift();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -329,7 +330,7 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
inputs.updateGamepad();
|
inputs.updateGamepad();
|
||||||
|
|
||||||
if(deltaTime > 5)
|
if(deltaTime >= 5)
|
||||||
{
|
{
|
||||||
inputs.processButtons();
|
inputs.processButtons();
|
||||||
}
|
}
|
||||||
@ -365,6 +366,7 @@ Tetris.prototype = {
|
|||||||
|
|
||||||
}
|
}
|
||||||
inputs.gamepadQueue = [];
|
inputs.gamepadQueue = [];
|
||||||
|
inputs.gamepadButtonClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deltaTime > this.interval) {
|
if (deltaTime > this.interval) {
|
||||||
|
Loading…
Reference in New Issue
Block a user