fix chrome and edge gamepad support. reenable keyboard

This commit is contained in:
PolicyChanges1@gmail.com 2021-02-05 08:41:37 -05:00
parent d0a063cebb
commit bb0a110bcd
4 changed files with 38 additions and 20 deletions

29
dist/tetrion.js vendored
View File

@ -249,6 +249,9 @@ var gamepadAPI = {
console.log('Gamepad disconnected.');
},
update: function() {
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
if(!isFirefox)
gamepadAPI.controller = window.navigator.getGamepads()[0];
gamepadAPI.buttonsCache = [];
for (var k = 0; k < gamepadAPI.buttonsStatus.length; k++) {
gamepadAPI.buttonsCache[k] = gamepadAPI.buttonsStatus[k];
@ -364,8 +367,8 @@ var UserInputs = {
if (this.nDeciframes >= deciDAS) {
this.nDeciframes = 0;
this.isGamepadButtonDown = true;
if(isContained)
this.gamepadQueue.push(finds);
//if(isContained)
// this.gamepadQueue.push(finds);
}
} else {
if (this.nDeciframes >= deciARR && isContained) {
@ -376,10 +379,9 @@ var UserInputs = {
},
gamepadDown(finds) {
var DAS = 6;
var ARR = 3;
var DAS = 5;
var ARR = 4;
var isContained = this.gpButtons.includes(finds);
var isDas = true; //this.gpButtons.includes("DPad-Left") || this.gpButtons.includes("DPad-Right") ||
//this.gpButtons.includes("DPad-Up") || this.gpButtons.includes("DPad-Down");
@ -467,6 +469,11 @@ var UserInputs = {
this.isKeyDown = false;
this.keyboardKeys[event.keyCode] = false;
},
gamepadButtonClear() {
gpButtons = [];
isGamepadDown = false;
isGamepadButtonDown = false;
},
isDown: false,
isKeyDown: false,
isGamepadDown: false,
@ -758,13 +765,14 @@ Tetris.prototype = {
var deltaTime = this.currentTime - this.prevTime;
if(deltaTime >= 1) // 600hz
if(deltaTime >= 1) { // 600hz
inputs.incDeciframes();
if(deltaTime > 10)
inputs.processGamepadInput();
}
if(deltaTime >= 10)
{
inputs.incFrame();
inputs.processGamepadInput();
//inputs.processKeyShift();
}
/*
@ -815,7 +823,7 @@ Tetris.prototype = {
inputs.updateGamepad();
if(deltaTime > 5)
if(deltaTime >= 5)
{
inputs.processButtons();
}
@ -851,6 +859,7 @@ Tetris.prototype = {
}
inputs.gamepadQueue = [];
inputs.gamepadButtonClear();
}
if (deltaTime > this.interval) {

View File

@ -13,6 +13,9 @@ var gamepadAPI = {
console.log('Gamepad disconnected.');
},
update: function() {
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
if(!isFirefox)
gamepadAPI.controller = window.navigator.getGamepads()[0];
gamepadAPI.buttonsCache = [];
for (var k = 0; k < gamepadAPI.buttonsStatus.length; k++) {
gamepadAPI.buttonsCache[k] = gamepadAPI.buttonsStatus[k];

View File

@ -50,8 +50,8 @@ var UserInputs = {
if (this.nDeciframes >= deciDAS) {
this.nDeciframes = 0;
this.isGamepadButtonDown = true;
if(isContained)
this.gamepadQueue.push(finds);
//if(isContained)
// this.gamepadQueue.push(finds);
}
} else {
if (this.nDeciframes >= deciARR && isContained) {
@ -62,10 +62,9 @@ var UserInputs = {
},
gamepadDown(finds) {
var DAS = 6;
var ARR = 3;
var DAS = 5;
var ARR = 4;
var isContained = this.gpButtons.includes(finds);
var isDas = true; //this.gpButtons.includes("DPad-Left") || this.gpButtons.includes("DPad-Right") ||
//this.gpButtons.includes("DPad-Up") || this.gpButtons.includes("DPad-Down");
@ -153,6 +152,11 @@ var UserInputs = {
this.isKeyDown = false;
this.keyboardKeys[event.keyCode] = false;
},
gamepadButtonClear() {
gpButtons = [];
isGamepadDown = false;
isGamepadButtonDown = false;
},
isDown: false,
isKeyDown: false,
isGamepadDown: false,

View File

@ -272,13 +272,14 @@ Tetris.prototype = {
var deltaTime = this.currentTime - this.prevTime;
if(deltaTime >= 1) // 600hz
if(deltaTime >= 1) { // 600hz
inputs.incDeciframes();
if(deltaTime > 10)
inputs.processGamepadInput();
}
if(deltaTime >= 10)
{
inputs.incFrame();
inputs.processGamepadInput();
//inputs.processKeyShift();
}
/*
@ -329,7 +330,7 @@ Tetris.prototype = {
inputs.updateGamepad();
if(deltaTime > 5)
if(deltaTime >= 5)
{
inputs.processButtons();
}
@ -365,6 +366,7 @@ Tetris.prototype = {
}
inputs.gamepadQueue = [];
inputs.gamepadButtonClear();
}
if (deltaTime > this.interval) {