diff --git a/creator.html b/creator.html
index 421580e..93450cf 100644
--- a/creator.html
+++ b/creator.html
@@ -230,14 +230,15 @@
GameInput Mapping Creator
for (var i = 0; i < GameInput.Players.length; i++)
{
- if ( typeof(GameInput.Players[GameInput.Connection.GamePadMapping[i]]) === "undefined"
- || typeof(GameInput.Players[GameInput.Connection.GamePadMapping[i]].schema) === "undefined"
- || typeof(GameInput.Players[GameInput.Connection.GamePadMapping[i]].type) === "undefined"
- || typeof(GameInput.Connection.Gamepads[i]) === "undefined"
- || GameInput.Players[GameInput.Connection.GamePadMapping[i]].type === GameInput.Type.Keyboard) continue;
+ if ( typeof(GameInput.getPlayer(i)) === "undefined"
+ || typeof(GameInput.getPlayer(i).schema) === "undefined"
+ || typeof(GameInput.getPlayer(i).type) === "undefined"
+ || typeof(GameInput.Connection.Gamepads[GameInput.Connection.GamePadMapping[i]]) === "undefined"
+ || GameInput.getPlayer(i).type === GameInput.Type.Keyboard) continue;
var row = document.querySelector("#player-template").cloneNode(true);
row.id = "";
+ row.setAttribute("number", (i+1));
row.classList.remove("template");
var playerNumberReferences = row.querySelectorAll(".player-number");
@@ -251,12 +252,12 @@ GameInput Mapping Creator
var gamepadIDReferences = row.querySelectorAll(".gamepad-id");
for (var k = 0; k < gamepadIDReferences.length; k++) {
- gamepadIDReferences[k].textContent = GameInput.Connection.Gamepads[i].id;
+ gamepadIDReferences[k].textContent = GameInput.Connection.Gamepads[GameInput.Connection.GamePadMapping[i]].id;
}
var iconSelectorReferences = row.querySelectorAll("select.icon");
for (var k = 0; k < iconSelectorReferences.length; k++) {
- iconSelectorReferences[k].value = GameInput.Players[GameInput.Connection.GamePadMapping[i]].model.iconName;
+ iconSelectorReferences[k].value = GameInput.getPlayer(i).model.iconName;
}
for (var j in GameInput.Schema.Names)
@@ -292,7 +293,7 @@ GameInput Mapping Creator
}
document.body.querySelector("#players").appendChild(row);
- updateCode(row);
+ updateCode(row.children[0]);
}
}
@@ -304,7 +305,7 @@ GameInput Mapping Creator
var isUndefined = false;
var currentAxis;
- var currentButton = GameInput.Players[GameInput.Connection.GamePadMapping[index]].schema[schemaName];
+ var currentButton = GameInput.getPlayer(index).schema[schemaName];
if (typeof(currentButton) === "undefined")
{
@@ -344,13 +345,13 @@ GameInput Mapping Creator
if (type == "button")
{
- GameInput.Players[GameInput.Connection.GamePadMapping[index]].model.schema[schemaName] = value;
- GameInput.Players[GameInput.Connection.GamePadMapping[index]].schema[schemaName] = value;
+ GameInput.getPlayer(index).model.schema[schemaName] = value;
+ GameInput.getPlayer(index).schema[schemaName] = value;
}
else //if (type == "axis")
{
- GameInput.Players[GameInput.Connection.GamePadMapping[index]].model.schema[schemaName] = new GameInput.Schema.AxisButton(value);
- GameInput.Players[GameInput.Connection.GamePadMapping[index]].schema[schemaName] = new GameInput.Schema.AxisButton(value);
+ GameInput.getPlayer(index).model.schema[schemaName] = new GameInput.Schema.AxisButton(value);
+ GameInput.getPlayer(index).schema[schemaName] = new GameInput.Schema.AxisButton(value);
}
updateCode(player);
}
@@ -363,7 +364,7 @@ GameInput Mapping Creator
var detectedIconReferences = playerElement.querySelectorAll(".detected-icon");
for (var k = 0; k < detectedIconReferences.length; k++ ) {
- detectedIconReferences.src = "css/gameinput/img/models/" + icon + ".png";
+ detectedIconReferences[k].src = "css/gameinput/img/models/" + icon + ".png";
}
updateCode(element);
@@ -375,7 +376,7 @@ GameInput Mapping Creator
var player = playerElement.getAttribute("number");
var index = player - 1;
- if (GameInput.Players[GameInput.Connection.GamePadMapping[index]].type == GameInput.Type.Keyboard)
+ if (GameInput.getPlayer(index).type == GameInput.Type.Keyboard)
{
console.warn("Player is Keyboard user.");
return;
@@ -401,11 +402,11 @@ GameInput Mapping Creator
break;
}
- var newCode = 'new GameInput.Model(\n\t' + theme + ',\n\t"' + icon + '",\n\t"' + GameInput.Players[GameInput.Connection.GamePadMapping[index]].model.id + '",\n\t"' + GameInput.OS.Detected + '",\n\tnew GameInput.Schema.GamePadAPI(\n';
+ var newCode = 'new GameInput.Model(\n\t' + theme + ',\n\t"' + icon + '",\n\t"' + GameInput.getPlayer(index).model.id + '",\n\t"' + GameInput.os + '",\n\tnew GameInput.Schema.GamePadAPI(\n';
for (var schemaName in GameInput.Schema.Names)
{
- var item = GameInput.Players[GameInput.Connection.GamePadMapping[index]].schema[schemaName];
+ var item = GameInput.getPlayer(index).schema[schemaName];
if (item !== undefined && isNaN(item)) item = "new GameInput.Schema.AxisButton(" + ( item.index * (item.direction === "positive" ? 1 : -1 )) + ")";
diff --git a/gameinput.js b/gameinput.js
index 6372a2b..e899fb9 100644
--- a/gameinput.js
+++ b/gameinput.js
@@ -857,7 +857,9 @@ var gi = {};
if (typeof(schemaButtonName) !== "undefined" )
{
var buttonElements = document.querySelectorAll(".gameinput-player" + player.index + "-" + schemaButtonName);
- for (var i = 0; i < buttonElements.length; i++) buttonElements[i].classList.remove("gameinput-button-active");
+ for (var i = 0; i < buttonElements.length; i++) {
+ buttonElements[i].classList.remove("gameinput-button-active");
+ }
player.buttonUp(schemaButtonName);
}
@@ -874,7 +876,9 @@ var gi = {};
if (typeof(schemaButtonName) !== "undefined" )
{
var buttonElements = document.querySelectorAll(".gameinput-player" + player.index + "-" + schemaButtonName);
- for (var i = 0; i < buttonElements.length; i++) buttonElements[i].classList.add("gameinput-button-active");
+ for (var i = 0; i < buttonElements.length; i++) {
+ buttonElements[i].classList.add("gameinput-button-active");
+ }
player.buttonDown(schemaButtonName);
}
}
@@ -909,59 +913,68 @@ var gi = {};
for (var i = 0; i < gi.Connection.Gamepads.length; i++)
{
- gi.getPlayer(i).previous.state = gi.getPlayer(i).state;
- gi.getPlayer(i).state = {};
+ gi.Players[i].previous.state = gi.Players[i].state;
+ gi.Players[i].state = {};
+
+ var currentGamepad = gi.Connection.Gamepads[i];
+ var currentSchema = gi.Players[i].schema;
- var currentGamepad = gi.Connection.Gamepads[gi.Connection.GamePadMapping[i]];
- var currentSchema = gi.getPlayer(i).schema;
if (typeof(currentGamepad) === "undefined") continue;
- for (var schemaIndex in currentSchema)
+ for (var j in currentSchema)
{
- if (typeof(currentSchema[schemaIndex]) === "undefined")
+ if (typeof(currentSchema[j]) === "undefined")
{
//skip
}
- else if ( typeof(currentGamepad.buttons[currentSchema[schemaIndex] - 1]
+ else if ( typeof(currentGamepad.buttons[currentSchema[j] - 1]
) === "undefined")
{
var negativeAxis = false;
- if (currentSchema[schemaIndex].threshold < 0) negativeAxis = true;
+ if (currentSchema[j].threshold < 0) negativeAxis = true;
- var axisValue = gi.Connection.Gamepads[i].axes[currentSchema[schemaIndex].index - 1];
- var threshold = currentSchema[schemaIndex].threshold;
+ var axisValue = currentGamepad.axes[currentSchema[j].index - 1];
+ var threshold = currentSchema[j].threshold;
if ( (negativeAxis && axisValue < threshold)
|| (!negativeAxis && axisValue > threshold))
{
- gi.getPlayer(i).state[schemaIndex] = true;
+ gi.Players[i].state[j] = true;
- var buttonElements = document.querySelectorAll(".gameinput-player" + i + "-" + schemaIndex);
- for (var i = 0; i < buttonElements.length; i++) buttonElements[i].classList.add("gameinput-button-active");
+ var buttonElements = document.querySelectorAll(".gameinput-player" + i + "-" + j);
+ for (var k = 0; k < buttonElements.length; k++) {
+ buttonElements[k].classList.add("gameinput-button-active");
+ }
}
else
{
- gi.getPlayer(i).state[schemaIndex] = false;
+ gi.Players[i].state[j] = false;
- var buttonElements = document.querySelectorAll(".gameinput-player" + i + "-" + schemaIndex);
- for (var i = 0; i < buttonElements.length; i++) buttonElements[i].classList.remove("gameinput-button-active");
+ var buttonElements = document.querySelectorAll(".gameinput-player" + i + "-" + j);
+ for (var k = 0; k < buttonElements.length; k++) {
+ buttonElements[k].classList.remove("gameinput-button-active");
+ }
}
}
else
{
- if (gi.Connection.Gamepads[i].buttons[currentSchema[schemaIndex] - 1].pressed)
+ if (currentGamepad.buttons[currentSchema[j] - 1].pressed)
{
- gi.getPlayer(i).state[schemaIndex] = true;
+ gi.Players[i].state[j] = true;
- var buttonElements = document.querySelectorAll(".gameinput-player" + i + "-" + schemaIndex);
- for (var i = 0; i < buttonElements.length; i++) buttonElements[i].classList.add("gameinput-button-active");
+ var buttonElements = document.querySelectorAll(".gameinput-player" + i + "-" + j);
+ for (var k = 0; k < buttonElements.length; k++) {
+ buttonElements[k].classList.add("gameinput-button-active");
+ }
}
else
{
- gi.getPlayer(i).state[schemaIndex] = false;
+ gi.Players[i].state[j] = false;
- var buttonElements = document.querySelectorAll(".gameinput-player" + i + "-" + schemaIndex);
- for (var i = 0; i < buttonElements.length; i++) buttonElements[i].classList.remove("gameinput-button-active");
+ var buttonElements = document.querySelectorAll(".gameinput-player" + i + "-" + j);
+ for (var k = 0; k < buttonElements.length; k++) {
+ buttonElements[k].classList.remove("gameinput-button-active");
+ }
}
}
}
@@ -1049,41 +1062,41 @@ var gi = {};
if ( toASCII(gi.Models.Specific[j].id) === toASCII(gi.Connection.Gamepads[i].id)
&& gi.os === gi.Models.Specific[j].os )
{
- gi.getPlayer(i).type = gi.Models.Specific[j].type;
- gi.getPlayer(i).model = gi.Models.Specific[j];
- gi.getPlayer(i).schema = gi.Models.Specific[j].schema;
- gi.getPlayer(i).theme = gi.Models.Specific[j].type.theme;
+ gi.Players[i].type = gi.Models.Specific[j].type;
+ gi.Players[i].model = gi.Models.Specific[j];
+ gi.Players[i].schema = gi.Models.Specific[j].schema;
+ gi.Players[i].theme = gi.Models.Specific[j].type.theme;
}
}
- if (typeof(gi.getPlayer(i).model) === "undefined")
+ if (typeof(gi.Players[i].model) === "undefined")
{
for (var j = 0; j < gi.Models.Generic.length; j++)
{
if (gi.Connection.Gamepads[i].id.match(gi.Models.Generic[j].id) !== null)
{
- gi.getPlayer(i).type = gi.Models.Generic[j].type;
- gi.getPlayer(i).model = gi.Models.Generic[j];
- gi.getPlayer(i).schema = gi.Models.Generic[j].schema;
- gi.getPlayer(i).theme = gi.Models.Generic[j].type.theme;
+ gi.Players[i].type = gi.Models.Generic[j].type;
+ 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.Connection.Gamepads[i] instanceof Gamepad && typeof(gi.getPlayer(i).model) === "undefined")
+ if (gi.Connection.Gamepads[i] instanceof Gamepad && typeof(gi.Players[i].model) === "undefined")
{
console.warn("Gamepad not mapped: \"" + gi.Connection.Gamepads[i].id + "\"");
}
}
// blank state to start
- gi.getPlayer(i).state = {};
+ gi.Players[i].state = {};
// setup Previous as current
- gi.getPlayer(i).previous.type = gi.getPlayer(i).type;
- gi.getPlayer(i).previous.model = gi.getPlayer(i).model;
- gi.getPlayer(i).previous.schema = gi.getPlayer(i).schema;
- gi.getPlayer(i).previous.theme = gi.getPlayer(i).theme;
- gi.getPlayer(i).previous.state = gi.getPlayer(i).state;
+ gi.Players[i].previous.type = gi.Players[i].type;
+ gi.Players[i].previous.model = gi.Players[i].model;
+ gi.Players[i].previous.schema = gi.Players[i].schema;
+ gi.Players[i].previous.theme = gi.Players[i].theme;
+ gi.Players[i].previous.state = gi.Players[i].state;
}
}
@@ -1114,8 +1127,7 @@ var gi = {};
}
else
{
- gi.KeyboardWatcher.PlayerToWatch = undefined;
-
+ gi.KeyboardWatcher.PlayerToWatch = undefined;
}
for (var i = 0; i < gi.Players.length; i++)
diff --git a/tester.html b/tester.html
index b19ed87..4cbf44e 100644
--- a/tester.html
+++ b/tester.html
@@ -138,8 +138,9 @@ Game Input Tester
for (var i = 0; i < GameInput.Players.length; i++)
{
- if (typeof(GameInput.Players[GameInput.Connection.GamePadMapping[i]].type) === "undefined"
- || typeof(GameInput.Players[GameInput.Connection.GamePadMapping[i]].schema) === "undefined") continue;
+ if (typeof(GameInput.getPlayer(i)) === "undefined"
+ || typeof(GameInput.getPlayer(i).type) === "undefined"
+ || typeof(GameInput.getPlayer(i).schema) === "undefined") continue;
var row = document.querySelector("#player-template").cloneNode(true);
row.id = "";
@@ -152,10 +153,10 @@ Game Input Tester
var keyboardLayoutReferences = row.querySelectorAll(".keyboard-layout");
for (var k = 0; k < keyboardLayoutReferences.length; k++)
{
- if (GameInput.Players[GameInput.Connection.GamePadMapping[i]].type === GameInput.Type.Keyboard) {
- keyboardLayoutReferences[k].value = GameInput.Players[GameInput.Connection.GamePadMapping[0]].schema === GameInput.Schema.KeyboardAPI.Standard.Dvorak ? "Dvorak" : "QWERTY";
+ if (GameInput.getPlayer(i).type === GameInput.Type.Keyboard) {
+ keyboardLayoutReferences[k].value = GameInput.getPlayer(i).schema === GameInput.Schema.KeyboardAPI.Standard.Dvorak ? "Dvorak" : "QWERTY";
} else {
- keyboardLayoutReferences[k].parentElement.removeChild(keyboardLayoutReferences[k].parentElement);
+ keyboardLayoutReferences[k].parentElement.removeChild(keyboardLayoutReferences[k]);
}
}
@@ -188,7 +189,7 @@ Game Input Tester
templateRightReferences[k].classList.remove("gameinput-player-template-right");
}
- if (typeof(GameInput.Players[GameInput.Connection.GamePadMapping[i]].schema[GameInput.Schema.Names[j]]) === "undefined")
+ if (typeof(GameInput.getPlayer(i).schema[GameInput.Schema.Names[j]]) === "undefined")
{
var unmappedReferences = row.querySelectorAll(".gameinput-player-template-" + GameInput.Schema.Names[j]);
for (var k = 0; k < unmappedReferences.length; k++) {
@@ -204,16 +205,12 @@ Game Input Tester
}
}
}
-
document.body.querySelector("#players").appendChild(row);
}
}
- function changeKeyboardLayout(element) {
- var playerElement = findAncestor(element, "player");
- var player = playerElement.getAttribute("number");
- var index = player - 1;
- if ( playerElement.querySelector(".keyboard-layout").value === "Dvorak") GameInput.Type.Keyboard.setDvorak();
+ function changeKeyboardLayout() {
+ if ( document.querySelector(".keyboard-layout").value === "Dvorak") GameInput.Type.Keyboard.setDvorak();
else GameInput.Type.Keyboard.setQWERTY();
}