1
0
Fork 0
mirror of https://github.com/Oreolek/gamebookformat.git synced 2024-06-28 20:55:13 +03:00

Fixed all jshint warnings.

This commit is contained in:
Pelle Nilsson 2014-04-03 23:58:19 +02:00
parent a76893a659
commit 4b27cef281

View file

@ -14,8 +14,8 @@ var gamebook = {
'contents' : [], 'contents' : [],
'dropped' : {}, 'dropped' : {},
'add' : function(what) { 'add' : function(what) {
if (this.contents.indexOf(what) === -1 if (this.contents.indexOf(what) === -1 &&
&& !(what in this.dropped)) { !(what in this.dropped)) {
this.contents.push(what); this.contents.push(what);
this.contents.sort(); this.contents.sort();
} }
@ -37,7 +37,7 @@ var gamebook = {
count : function(type, name) { count : function(type, name) {
if (type in this.counters) { if (type in this.counters) {
return; return;
}; }
this.counters[type] = { this.counters[type] = {
inited : false, inited : false,
name : name, name : name,
@ -144,15 +144,15 @@ var gamebook = {
this.collections[c].contents = collection.contents; this.collections[c].contents = collection.contents;
this.collections[c].dropped = collection.dropped; this.collections[c].dropped = collection.dropped;
} }
for (var c in parsedState.counters) { for (var ct in parsedState.counters) {
var counter = parsedState.counters[c]; var counter = parsedState.counters[ct];
if (c in this.counters) { if (ct in this.counters) {
this.counters[c].name = counter.name; this.counters[ct].name = counter.name;
} else { } else {
this.count(c, counter.name); this.count(ct, counter.name);
} }
this.counters[c].minValue = counter.minValue; this.counters[ct].minValue = counter.minValue;
this.counters[c].value = counter.value; this.counters[ct].value = counter.value;
} }
} }
}, },
@ -170,9 +170,9 @@ var gamebook = {
if (!gamebook.player.started) { if (!gamebook.player.started) {
gamebook.start(); gamebook.start();
} }
if (!nr in this.sections) { if (!(nr in this.sections)) {
throw new Exception("Can not turn to non-existing section " throw new Exception("Can not turn to non-existing section " +
+ nr + "."); nr + ".");
} }
this.displaySection(nr); this.displaySection(nr);
}, },
@ -273,8 +273,8 @@ var gamebook = {
var xorEnableNext = false; var xorEnableNext = false;
var lastCanHaveCost = null; var lastCanHaveCost = null;
var autoDisableAllRemaining = ( var autoDisableAllRemaining = (
gamebook.player.started gamebook.player.started &&
&& e.classList.contains('introsectionbody')); e.classList.contains('introsectionbody'));
Array.prototype.forEach.call(e.childNodes, function(c) { Array.prototype.forEach.call(e.childNodes, function(c) {
if (!c.classList) { if (!c.classList) {
return; return;
@ -305,31 +305,31 @@ var gamebook = {
gamebook.player.count(c.dataset.type, c.dataset.name); gamebook.player.count(c.dataset.type, c.dataset.name);
} else if (c.classList.contains('set')) { } else if (c.classList.contains('set')) {
gamebook.player.set(c.dataset.type, gamebook.player.set(c.dataset.type,
parseInt(c.dataset.amount)); parseInt(c.dataset.amount, 10));
} else if (c.classList.contains('init')) { } else if (c.classList.contains('init')) {
gamebook.player.init(c.dataset.type, gamebook.player.init(c.dataset.type,
parseInt(c.dataset.amount)); parseInt(c.dataset.amount, 10));
} else if (c.classList.contains('inc')) { } else if (c.classList.contains('inc')) {
gamebook.player.inc(c.dataset.type, gamebook.player.inc(c.dataset.type,
parseInt(c.dataset.amount)); parseInt(c.dataset.amount, 10));
} else if (c.classList.contains('dec')) { } else if (c.classList.contains('dec')) {
gamebook.player.dec(c.dataset.type, gamebook.player.dec(c.dataset.type,
parseInt(c.dataset.amount)); parseInt(c.dataset.amount, 10));
} else if (c.classList.contains('min')) { } else if (c.classList.contains('min')) {
gamebook.player.min(c.dataset.type, gamebook.player.min(c.dataset.type,
parseInt(c.dataset.limit)); parseInt(c.dataset.limit, 10));
} else if (c.classList.contains('has')) { } else if (c.classList.contains('has')) {
enableNextLink = gamebook.player.has(c.dataset.type, enableNextLink = gamebook.player.has(c.dataset.type,
c.dataset.what); c.dataset.what);
} else if (c.classList.contains('morethan')) { } else if (c.classList.contains('morethan')) {
enableNextLink = gamebook.player.hasMoreThan( enableNextLink = gamebook.player.hasMoreThan(
c.dataset.type, parseInt(c.dataset.amount)); c.dataset.type, parseInt(c.dataset.amount, 10));
} else if (c.classList.contains('lessthan')) { } else if (c.classList.contains('lessthan')) {
enableNextLink = gamebook.player.hasLessThan( enableNextLink = gamebook.player.hasLessThan(
c.dataset.type, parseInt(c.dataset.amount)); c.dataset.type, parseInt(c.dataset.amount, 10));
} else if (c.classList.contains('atleast')) { } else if (c.classList.contains('atleast')) {
enableNextLink = gamebook.player.hasMoreThan( enableNextLink = gamebook.player.hasMoreThan(
c.dataset.type, parseInt(c.dataset.amount) - 1); c.dataset.type, parseInt(c.dataset.amount, 10) - 1);
} else if (c.classList.contains('hasnot')) { } else if (c.classList.contains('hasnot')) {
enableNextLink = !gamebook.player.has(c.dataset.type, enableNextLink = !gamebook.player.has(c.dataset.type,
c.dataset.what); c.dataset.what);
@ -357,7 +357,7 @@ var gamebook = {
}, },
addCost : function(c, e) { addCost : function(c, e) {
var cost = parseInt(c.dataset.amount); var cost = parseInt(c.dataset.amount, 10);
var counter = gamebook.player.counters[c.dataset.type]; var counter = gamebook.player.counters[c.dataset.type];
if (counter.value - cost >= counter.minValue) { if (counter.value - cost >= counter.minValue) {
e.classList.add("enabledlink"); e.classList.add("enabledlink");
@ -409,7 +409,7 @@ var gamebook = {
e = e.nextSibling; e = e.nextSibling;
} }
if (links.length > 0) { if (links.length > 0) {
var selected = links[Math.floor(Math.random()*links.length)] var selected = links[Math.floor(Math.random()*links.length)];
gamebook.enableLink(selected); gamebook.enableLink(selected);
} else { } else {
console.log("Random with nothing to select?"); console.log("Random with nothing to select?");
@ -489,7 +489,7 @@ var gamebook = {
'payPrice' : function(e) { 'payPrice' : function(e) {
var cost, counter, trade, tradetype; var cost, counter, trade, tradetype;
if ('cost' in e.dataset && 'costtype' in e.dataset) { if ('cost' in e.dataset && 'costtype' in e.dataset) {
cost = parseInt(e.dataset.cost); cost = parseInt(e.dataset.cost, 10);
counter = gamebook.player.counters[e.dataset.costtype]; counter = gamebook.player.counters[e.dataset.costtype];
if (counter.value - cost < counter.minValue) { if (counter.value - cost < counter.minValue) {
return false; return false;
@ -517,7 +517,7 @@ var gamebook = {
var cs = e.getElementsByClassName('sectiontext')[0].childNodes; var cs = e.getElementsByClassName('sectiontext')[0].childNodes;
Array.prototype.forEach.call(cs, function(c) { Array.prototype.forEach.call(cs, function(c) {
if (c.dataset && 'cost' in c.dataset && 'costtype' in c.dataset) { if (c.dataset && 'cost' in c.dataset && 'costtype' in c.dataset) {
var cost = parseInt(c.dataset.cost); var cost = parseInt(c.dataset.cost, 10);
var counter = gamebook.player.counters[c.dataset.costtype]; var counter = gamebook.player.counters[c.dataset.costtype];
if (counter.value - cost < counter.minValue) { if (counter.value - cost < counter.minValue) {
c.classList.remove("enabledlink"); c.classList.remove("enabledlink");