Permalink
Browse files

Some code readability changes

  • Loading branch information...
1 parent 412a6d1 commit 5b99dc154db863fbf64134c89fd82b91a330cd7b @Ambilight committed Mar 31, 2012
Showing with 17 additions and 9 deletions.
  1. +17 −9 server/js/map.js
View
@@ -27,6 +27,7 @@ module.exports = Map = cls.Class.extend({
},
initMap: function(map) {
+ // Why don't use this = map?
this.width = map.width;
this.height = map.height;
this.collisions = map.collisions;
@@ -57,22 +58,26 @@ module.exports = Map = cls.Class.extend({
// It seems like magic and not much understandable
// Why not using it in generateCollisionGridMethod? Let's try.
- tileIndexToGridPosition: function(tileNum) {
+ tileIndexToGridPosition: function(tileNum)
+ {
var x = 0,
y = 0;
- var getX = function(num, w) {
- if(num == 0) {
+ var getX = function ( num, w )
+ {
+ if ( num == 0 )
+ {
return 0;
}
return (num % w == 0) ? w - 1 : (num % w) - 1;
}
tileNum -= 1;
- x = getX(tileNum + 1, this.width);
- y = Math.floor(tileNum / this.width);
+ x = getX( tileNum + 1, this.width );
+ y = Math.floor( tileNum / this.width );
- return { x: x, y: y };
+ // Why don't use pos(x,y) -> {x:x,y:y} function?
+ return { x:x, y:y };
},
GridPositionToTileIndex: function(x, y) {
@@ -243,10 +248,13 @@ module.exports = Map = cls.Class.extend({
}
});
-var pos = function(x, y) {
+// Improve code readability:
+var pos = function( x, y )
+{
return { x: x, y: y };
};
-var equalPositions = function(pos1, pos2) {
- return pos1.x === pos2.x && pos2.y === pos2.y;
+// Little bit of bugfix here and improving code readability:
+var equalPositions = function( pos1, pos2 ) {
+ return ( pos1.x === pos2.x ) && ( pos1.y === pos2.y );
};

0 comments on commit 5b99dc1

Please sign in to comment.