Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add: `toJSON` method of GridModel

  • Loading branch information...
commit 4cbf4beed6496f9b212015996b73724f37fbbd56 1 parent 2b08e72
@qiao authored
Showing with 25 additions and 0 deletions.
  1. +25 −0 visual/grid.js
View
25 visual/grid.js
@@ -116,6 +116,27 @@ window.GridModel = {
this.allReset.notify();
},
+
+ toJSON: function() {
+ var i, j,
+ grid = this._grid,
+ width = grid.width,
+ height = grid.height,
+ matrix = [];
+
+ for (i = 0; i < height; ++i) {
+ matrix.push([]);
+ for (j = 0; j < width; j++) {
+ matrix[i].push(grid.isWalkableAt(j, i) ? 0 : 1);
+ };
+ }
+
+ return {
+ width: width,
+ height: height,
+ matrix: matrix
+ };
+ },
};
@@ -410,6 +431,7 @@ window.GridView = {
window.GridController = {
init: function() {
this.initGeometry();
+ this.initHashSetter();
},
supportedDispatcher: {
@@ -444,6 +466,9 @@ window.GridController = {
GridModel.setEndPos(centerX + 5, centerY);
},
+ initHashSetter: function() {
+ },
+
onMouseDown: function(x, y) {
if (this.isRunning()) {
return;
Please sign in to comment.
Something went wrong with that request. Please try again.