Skip to content

Commit 8c6cc36

Browse files
committed
fixed jshint on javascript
1 parent d6ca136 commit 8c6cc36

15 files changed

+74
-67
lines changed

gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ gulp.task('compile_js', ['clean_dist'], function(){
6363
});
6464

6565
gulp.task('lint', function() {
66-
return gulp.src('./dist/js/*.js')
66+
return gulp.src('./js/**/*.js')
6767
.pipe(jshint())
6868
.pipe(jshint.reporter('default'));
6969
});

js/asciiRPG/actor.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,12 @@ Actor.prototype.canMove = function(direction){
4141
switch(direction){
4242
case UP:
4343
return this.room.isAvailable(this, this.x, this.y - 5, direction);
44-
break;
4544
case DOWN:
4645
return this.room.isAvailable(this, this.x, this.y + 5, direction);
47-
break;
4846
case LEFT:
4947
return this.room.isAvailable(this, this.x - 10, this.y, direction);
50-
break;
5148
case RIGHT:
5249
return this.room.isAvailable(this, this.x + 10, this.y, direction);
53-
break;
5450
}
5551
return false;
5652
};
@@ -59,7 +55,7 @@ Actor.prototype.move = function(direction, _countdown){
5955
// recursively move 1 tile for smooth transition
6056

6157
var actor = this;
62-
if(!actor._moving || _countdown != undefined){
58+
if(!actor._moving || _countdown !== undefined){
6359

6460

6561
//change direction if needed immediately
@@ -99,13 +95,16 @@ Actor.prototype.move = function(direction, _countdown){
9995
delay = 15;
10096
else
10197
delay = 30;
102-
setTimeout(function(){actor.move(direction, _countdown - 1)}, delay);
98+
setTimeout(
99+
function(){actor.move(direction, _countdown - 1);},
100+
delay
101+
);
103102
}else{ // base case
104103
actor.setMoving(false);
105104
this.room.objectAt(this.x, this.y).onEnter(this);
106105
actor._wereMoving = true;
107106
refirePressedKeys(); // trigger another move after we finish this one
108-
setTimeout(function(){actor._wereMoving = false}, 100)
107+
setTimeout(function(){actor._wereMoving = false;}, 100);
109108
}
110109
}
111110
};

js/asciiRPG/animated_sprite.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11

22
var AnimatedSprite = function(sprite_data, options){
3-
Sprite.call(this);
3+
Sprite.call(this);
4+
var frame, state;
45

56
this.image = jQuery.extend(true, [], sprite_data.states);
67
this.map = jQuery.extend(true, [], sprite_data.states);
78

8-
for(var state=0;state<this.image.length;state++){
9-
for(var frame=0;frame<this.image[state].frames.length;frame++){
9+
for(state=0;state<this.image.length;state++){
10+
for(frame=0;frame<this.image[state].frames.length;frame++){
1011
this.image[state].frames[frame] = this.image[state].frames[frame].split('\n');
1112
}
1213
}
13-
for(var state=0;state<this.map.length;state++){
14-
for(var frame=0;frame<this.map[state].frames.length;frame++){
14+
for(state=0;state<this.map.length;state++){
15+
for(frame=0;frame<this.map[state].frames.length;frame++){
1516
this.map[state].frames[frame] = this.map[state].frames[frame].split('\n');
1617
}
1718
}
@@ -52,8 +53,8 @@ AnimatedSprite.prototype.fromString = function(imageString, mapString){
5253
states[Math.floor(row_i/TILE_HEIGHT)][i] += "\n";
5354
}
5455
}
55-
for(var i=0;i<4;i++){
56-
states[i][3] = states[i][1];
56+
for(var j=0;j<4;j++){
57+
states[j][3] = states[j][1];
5758
}
5859
return states;
5960
};

js/asciiRPG/compositor.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ function generateBox(width, height, fillChar){
3131
for(var row=0;row<height;row++){
3232
var line = "";
3333
for(var col=0;col<width;col++){
34-
if( (row == 0 && col == 0) ||
35-
(row == height - 1 && col == width -1) ||
36-
(row == 0 && col == width - 1) ||
37-
(row == height - 1 && col == 0))
34+
if( (row === 0 && col === 0) ||
35+
(row === height - 1 && col === width -1) ||
36+
(row === 0 && col === width - 1) ||
37+
(row === height - 1 && col === 0))
3838
line += "+";
39-
else if(row == 0 || row == height-1)
39+
else if(row === 0 || row === height-1)
4040
line += "-";
41-
else if(col == 0 || col == width - 1)
41+
else if(col === 0 || col === width - 1)
4242
line += "|";
4343
else
4444
line += fillChar;
@@ -69,12 +69,12 @@ function layerText(base, content, map, x, y){
6969
var img_col = col - x;
7070
if(img_row >= 0 && img_row < map.length &&
7171
img_col >= 0 && img_col < map[0].length &&
72-
map[img_row] != "" &&
72+
map[img_row] !== "" &&
7373
map[img_row][img_col] != " ")
7474
base[row][col] = content[img_row][img_col];
7575
}
7676
}
77-
};
77+
}
7878

7979
var Compositor = function(canvasElement){
8080
this.el = canvasElement;

js/asciiRPG/game.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var Game = function(canvasEl, game_data){
1111
this.modes.title = new TitleScreen(this.modes.title, this);
1212
break;
1313
default:
14-
this.modes[mode] = new this.modes[mode](this)
14+
this.modes[mode] = new this.modes[mode](this);
1515
}
1616
}
1717
this.switchMode('title');
@@ -38,7 +38,7 @@ Game.prototype.run = function(){
3838
gameFrame = 0;
3939
}
4040

41-
setTimeout(function(){g.run()}, 1000/actual_fps);
41+
setTimeout(function(){g.run();}, 1000/actual_fps);
4242
};
4343

4444
Game.prototype.handleInput = function(key){

js/asciiRPG/game_object.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ GameObject.prototype.covers = function(x, y){
7070

7171
GameObject.prototype.inspect = function(actor){
7272
return this.description;
73-
}
73+
};

js/asciiRPG/global.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var REVISION = "4"
1+
var REVISION = "4";
22

33

44
var SCREEN_WIDTH = 100;
@@ -30,7 +30,7 @@ var asciiRPG = {
3030
load: function(canvasEl, game_data){
3131
return new Game(canvasEl, game_data);
3232
}
33-
}
33+
};
3434

3535
// http://stackoverflow.com/a/1465409/4187005
3636
if (typeof KeyEvent == "undefined") {

js/asciiRPG/hud.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ HUD.prototype.draw = function(compositor){
5050
var hud = this;
5151
// draw message/prompt box
5252
if(this.displayQueue.length > 0 && this.message.trim() === ""){
53-
var displayRequest = this.displayQueue.pop()
53+
var displayRequest = this.displayQueue.pop();
5454
this.message = displayRequest.message;
5555
this.yesno.isUp = displayRequest.type === this.PROMPT;
5656
if(this.yesno.isUp)
@@ -59,7 +59,7 @@ HUD.prototype.draw = function(compositor){
5959
displayRequest.callback(value);
6060
this.selectHandler = null;
6161
this.isUp = false;
62-
}
62+
};
6363
}
6464

6565
//3 chars padding either side with twice char size
@@ -68,7 +68,11 @@ HUD.prototype.draw = function(compositor){
6868
var lines = str.split('\n');
6969
var out = [];
7070
for(var i=0;i<lines.length;i++)
71-
out = out.concat(lines[i].match(new RegExp('.{1,' + charsPerLine + '}', 'g')))
71+
out = out.concat(
72+
lines[i].match(
73+
new RegExp('.{1,' + charsPerLine + '}', 'g')
74+
)
75+
);
7276
return out.slice(0,3).join('\n');
7377
}
7478

@@ -96,8 +100,8 @@ HUD.prototype.draw = function(compositor){
96100
};
97101

98102
HUD.prototype.scrollMessage = function(){
99-
var lines = this.message.split('\n')
100-
lines.shift()
103+
var lines = this.message.split('\n');
104+
lines.shift();
101105
this.message = lines.join('\n');
102106
};
103107

@@ -141,11 +145,12 @@ HUD.prototype.handleInput = function(key){
141145
case KeyEvent.DOM_VK_Q:
142146
if(this.yesno.isUp){
143147
this.yesno.handleInput(key);
144-
}else if(this.message == "" && this.menuUp){
148+
}else if(this.message === "" && this.menuUp){
145149
this.menuUp = false;
146150
play('menuDown');
147151
}else
148152
this.scrollMessage();
153+
break;
149154
default:
150155
break;
151156
}

js/asciiRPG/input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var isPressed = function(key){
5252
if(key in keyPressers && keyPressers[key] !== null)
5353
return true;
5454
return false;
55-
}
55+
};
5656

5757
$(document).keyup(function(event){
5858
switch(event.keyCode){

js/asciiRPG/room.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ Room.prototype.isAvailable = function(actor, x, y, fromDirection){
3636
}
3737
}
3838
return true;
39-
}
39+
};
40+
4041
Room.prototype.objectAt = function(x, y){
4142
for(var i=0;i<this.gameObjects.length;i++){
4243
if(this.gameObjects[i].x == x && this.gameObjects[i].y == y){
4344
return this.gameObjects[i];
4445
}
4546
}
4647
return null;
47-
}
48+
};
4849

4950
Room.prototype.removeGameObject = function(go, x, y){
5051
for(var i=0;i<this.gameObjects.length;i++){
@@ -53,4 +54,4 @@ Room.prototype.removeGameObject = function(go, x, y){
5354
}
5455
}
5556
return null;
56-
}
57+
};

js/asciiRPG/sound.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ var sfx = {
66
selectChange: 'sounds/selectChange.wav',
77
unlock: 'sounds/select.wav',
88
};
9-
var play = function(sound){
10-
if(sfx.hasOwnProperty(sound)){
11-
var sound = new Audio(sfx[sound]);
9+
var play = function(soundName){
10+
if(sfx.hasOwnProperty(soundName)){
11+
var sound = new Audio(sfx[soundName]);
1212
sound.play();
1313
return sound;
1414
}

js/asciiRPG/title_screen.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ TitleScreen.prototype.draw = function(compositor){
3535

3636
TitleScreen.prototype.handleInput = function(key){
3737
this.game.switchMode('world');
38-
play('select')
38+
play('select');
3939
};
4040

4141
TitleScreen.prototype.onEnterMode = function(params){
4242
if(this.music !== undefined)
4343
this.music.play();
44-
}
44+
};
4545

4646
TitleScreen.prototype.onExitMode = function(){
4747
if(this.music !== undefined)
4848
this.music.pause();
49-
}
49+
};

js/asciiRPG/world.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,18 @@ World.prototype.draw = function(compositor){
6262
// set the current room (Immediately -- see setRoom for transitions)
6363
World.prototype.setRoomNow = function(roomName, callback){
6464
var world = this;
65+
var loadTMXData = function(tmxData){
66+
world.data.rooms[current_room_i] = tmxToRoomData(tmxData);
67+
world.data.rooms[current_room_i].name = roomName;
68+
world.setRoomNow(roomName);
69+
if(callback)callback();
70+
};
6571
for(var i=0;i<world.data.rooms.length;i++){
6672
if(world.data.rooms[i].name === roomName){
6773
var room_data = world.data.rooms[i];
6874
if(room_data.hasOwnProperty('url')){ // lazy load
6975
var current_room_i = i;
70-
$.get(room_data.url, function(tmxData){
71-
world.data.rooms[current_room_i] = tmxToRoomData(tmxData);
72-
world.data.rooms[current_room_i].name = roomName;
73-
world.setRoomNow(roomName);
74-
if(callback)callback();
75-
});
76+
$.get(room_data.url, loadTMXData);
7677
return;
7778
}else{ // we have the data, don't lazy load
7879
world.room = new Room(room_data);
@@ -130,9 +131,9 @@ World.prototype.handleInput = function(key){
130131
World.prototype.onEnterMode = function(params){
131132
if(this.music !== undefined)
132133
this.music.play();
133-
}
134+
};
134135

135136
World.prototype.onExitMode = function(){
136137
if(this.music !== undefined)
137138
this.music.pause();
138-
}
139+
};

0 commit comments

Comments
 (0)