Skip to content

Commit

Permalink
improvements to multiplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
lunarcloud committed Nov 20, 2016
1 parent e2ca2ad commit a55789c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 47 deletions.
12 changes: 11 additions & 1 deletion gameinput.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,9 @@ var gi = {};
gi.Players[i].schema = gi.Models.Specific[j].schema;
gi.Players[i].theme = gi.Models.Specific[j].type.theme;

if (gi.debug) {
console.debug("Gamepad of type " + gi.Players[i].type.name + " configured");
}
break;
}
}
Expand All @@ -872,6 +875,9 @@ var gi = {};
gi.Players[i].model = gi.Models.Generic[j];
gi.Players[i].schema = gi.Models.Generic[j].schema;
gi.Players[i].theme = gi.Models.Generic[j].type.theme;
if (gi.debug) {
console.debug("Gamepad of type " + gi.Players[i].type.name + " configured");
}
}
}

Expand All @@ -889,6 +895,10 @@ var gi = {};
gi.Players[i].model = gi.Models.UnknownStandardMapping;
gi.Players[i].schema = gi.Models.UnknownStandardMapping.schema;
gi.Players[i].theme = gi.Models.UnknownStandardMapping.theme;

if (gi.debug) {
console.debug("Gamepad of type " + gi.Players[i].type.name + " configured");
}
}
}

Expand Down Expand Up @@ -966,7 +976,7 @@ var gi = {};
} // else { gi.browser = "Other" }


gi.initialGamePadSetup();
// gi.initialGamePadSetup(); // don't do this stuff until models exist
if (typeof(gi.Type.Keyboard.schema) === "undefined") gi.Type.Keyboard.setQWERTY();
gi.startUpdateLoop();

Expand Down
Empty file modified gameinput.models.js
100644 → 100755
Empty file.
110 changes: 64 additions & 46 deletions impactjs-plugin/gameinput-gamepad.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/**
* @preserve
* @source: https://raw.githubusercontent.com/lunarcloud/gameinputjs/master/impactjs-plugin/gameinput-gamepad.js
* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT (Expat) License
* @author Samuel J Sarette
*
* @licstart The following is the entire license notice for the JavaScript code in this module.
*
* Copyright (C) 2016 Samuel J Sarette
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of the copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the copyright holder.
*
* @licend The above is the entire license notice for the JavaScript code in this module.
*/
ig.module(
'plugins.gameinput-gamepad'
Expand All @@ -17,47 +27,38 @@ ig.module(
// here so we don't collide with the keyboard buttons when binding.
ig.GAMEPAD_BUTTON_OFFSET = 256;

function setMaxPlayers(players) {
for (var i = 1; i <= players; i++) {
ig['GAMEPAD' + i] = {
d_up : ig.GAMEPAD_BUTTON_OFFSET * i + 0,
d_down : ig.GAMEPAD_BUTTON_OFFSET * i + 1,
d_left : ig.GAMEPAD_BUTTON_OFFSET * i + 2,
d_right : ig.GAMEPAD_BUTTON_OFFSET * i + 3,
menu : ig.GAMEPAD_BUTTON_OFFSET * i + 4,
button0 : ig.GAMEPAD_BUTTON_OFFSET * i + 5,
button1 : ig.GAMEPAD_BUTTON_OFFSET * i + 6,
button2 : ig.GAMEPAD_BUTTON_OFFSET * i + 7,
button3 : ig.GAMEPAD_BUTTON_OFFSET * i + 8,
l_up : ig.GAMEPAD_BUTTON_OFFSET * i + 9,
l_down : ig.GAMEPAD_BUTTON_OFFSET * i + 10,
l_left : ig.GAMEPAD_BUTTON_OFFSET * i + 11,
l_right : ig.GAMEPAD_BUTTON_OFFSET * i + 12,
r_up : ig.GAMEPAD_BUTTON_OFFSET * i + 13,
r_down : ig.GAMEPAD_BUTTON_OFFSET * i + 14,
r_left : ig.GAMEPAD_BUTTON_OFFSET * i + 15,
r_right : ig.GAMEPAD_BUTTON_OFFSET * i + 16,
l_button : ig.GAMEPAD_BUTTON_OFFSET * i + 17,
r_button : ig.GAMEPAD_BUTTON_OFFSET * i + 18,
l_trigger : ig.GAMEPAD_BUTTON_OFFSET * i + 19,
r_trigger : ig.GAMEPAD_BUTTON_OFFSET * i + 20
};
}
for (var i = 1; i <= 4; i++) {
ig['GAMEPAD' + i] = {
d_up : ig.GAMEPAD_BUTTON_OFFSET * i + 0,
d_down : ig.GAMEPAD_BUTTON_OFFSET * i + 1,
d_left : ig.GAMEPAD_BUTTON_OFFSET * i + 2,
d_right : ig.GAMEPAD_BUTTON_OFFSET * i + 3,
menu : ig.GAMEPAD_BUTTON_OFFSET * i + 4,
button0 : ig.GAMEPAD_BUTTON_OFFSET * i + 5,
button1 : ig.GAMEPAD_BUTTON_OFFSET * i + 6,
button2 : ig.GAMEPAD_BUTTON_OFFSET * i + 7,
button3 : ig.GAMEPAD_BUTTON_OFFSET * i + 8,
l_up : ig.GAMEPAD_BUTTON_OFFSET * i + 9,
l_down : ig.GAMEPAD_BUTTON_OFFSET * i + 10,
l_left : ig.GAMEPAD_BUTTON_OFFSET * i + 11,
l_right : ig.GAMEPAD_BUTTON_OFFSET * i + 12,
r_up : ig.GAMEPAD_BUTTON_OFFSET * i + 13,
r_down : ig.GAMEPAD_BUTTON_OFFSET * i + 14,
r_left : ig.GAMEPAD_BUTTON_OFFSET * i + 15,
r_right : ig.GAMEPAD_BUTTON_OFFSET * i + 16,
l_button : ig.GAMEPAD_BUTTON_OFFSET * i + 17,
r_button : ig.GAMEPAD_BUTTON_OFFSET * i + 18,
l_trigger : ig.GAMEPAD_BUTTON_OFFSET * i + 19,
r_trigger : ig.GAMEPAD_BUTTON_OFFSET * i + 20
};
}
setMaxPlayers(1); // default to only 1 gamepad/player

ig.normalizeVendorAttribute(navigator, 'getGamepads');

ig.Input.inject({
hasSetupGameInput: false,

maxPlayers: 1,
hasSetupGameInput: [false,false,false,false],

setMaxPlayers: function(players)
{
ig.input.maxPlayers = players;
setMaxPlayers(players);
},
maxPlayers: 4,

disableGamepadLeftAnalogStrafe: false,

Expand All @@ -78,7 +79,7 @@ ig.module(

onGamepadChange: function(action) { GameInput.onReshufflePlayers(action); },

pollGamepads: function(player)
pollGamepads: function()
{
for (var i = 1; i <= ig.input.maxPlayers; i++) {
ig.input.pollGamepad(i);
Expand All @@ -90,7 +91,7 @@ ig.module(
if (isNaN(player)) player = 1;
var index = player - 1;

if (ig.input.hasSetupGameInput === false)
if (ig.input.hasSetupGameInput[index] === false)
{
GameInput.stopUpdateLoop();
GameInput.handleKeyboard = false;
Expand Down Expand Up @@ -118,7 +119,7 @@ ig.module(
}());
}

ig.input.hasSetupGameInput = true;
ig.input.hasSetupGameInput[index] = true;
}
if (!document.hasFocus || document.hasFocus()) GameInput.update();
},
Expand All @@ -134,6 +135,17 @@ ig.module(
return false;
},

getGamepadType: function(player)
{
if (isNaN(player)) player = 1;
var index = player - 1;

if (typeof(GameInput.Players[GameInput.Connection.GamePadMapping[index]].model) !== "undefined") {
return GameInput.Players[GameInput.Connection.GamePadMapping[index]].type.name.toLowerCase();
}
return false;
},

getUnmappedGamepadName: function(player)
{
if (isNaN(player)) player = 1;
Expand All @@ -155,6 +167,17 @@ ig.module(
&& GameInput.Players[GameInput.Connection.GamePadMapping[index]].type !== GameInput.Type.Keyboard;
},

gamepadsCount: function()
{
var count = 0;

for (var i = 1; i <= ig.input.maxPlayers; i++) {
count += ig.input.playerHasGamepad(i) ? 1 : 0;
}

return count;
},

icons: {
dc: new ig.Image("media/gamepads/dc.png"),
xbox360: new ig.Image("media/gamepads/xbox360.png"),
Expand Down Expand Up @@ -246,8 +269,3 @@ ig.module(
});

});

/**
* @preserve
* @license-end
*/

0 comments on commit a55789c

Please sign in to comment.