Skip to content

Commit

Permalink
Fixed syntax errors and iterator variable name issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lunarcloud committed Apr 18, 2016
1 parent e6a2947 commit 3e03862
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 72 deletions.
35 changes: 18 additions & 17 deletions creator.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,15 @@ <h1>GameInput Mapping Creator</h1>

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");
Expand All @@ -251,12 +252,12 @@ <h1>GameInput Mapping Creator</h1>

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)
Expand Down Expand Up @@ -292,7 +293,7 @@ <h1>GameInput Mapping Creator</h1>
}

document.body.querySelector("#players").appendChild(row);
updateCode(row);
updateCode(row.children[0]);
}
}

Expand All @@ -304,7 +305,7 @@ <h1>GameInput Mapping Creator</h1>

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")
{
Expand Down Expand Up @@ -344,13 +345,13 @@ <h1>GameInput Mapping Creator</h1>

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);
}
Expand All @@ -363,7 +364,7 @@ <h1>GameInput Mapping Creator</h1>

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);
Expand All @@ -375,7 +376,7 @@ <h1>GameInput Mapping Creator</h1>
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;
Expand All @@ -401,11 +402,11 @@ <h1>GameInput Mapping Creator</h1>
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 )) + ")";

Expand Down
98 changes: 55 additions & 43 deletions gameinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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");
}
}
}
}
Expand Down Expand Up @@ -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;

}
}
Expand Down Expand Up @@ -1114,8 +1127,7 @@ var gi = {};
}
else
{
gi.KeyboardWatcher.PlayerToWatch = undefined;

gi.KeyboardWatcher.PlayerToWatch = undefined;
}

for (var i = 0; i < gi.Players.length; i++)
Expand Down
21 changes: 9 additions & 12 deletions tester.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ <h1>Game Input Tester</h1>

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 = "";
Expand All @@ -152,10 +153,10 @@ <h1>Game Input Tester</h1>
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]);
}
}

Expand Down Expand Up @@ -188,7 +189,7 @@ <h1>Game Input Tester</h1>
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++) {
Expand All @@ -204,16 +205,12 @@ <h1>Game Input Tester</h1>
}
}
}

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();
}

Expand Down

0 comments on commit 3e03862

Please sign in to comment.