/** * @constructor **/ function Definition(data) { /** @type {Array.} */ this.text = data["text"]; /** @type {number} */ this.direction = data["pos"]; } /** @const */ Definition.RIGHT_HORIZONTAL = 1; /** @const */ Definition.RIGHT_VERTICAL = 2; /** @const */ Definition.BOTTOM_HORIZONTAL = 3; /** @const */ Definition.BOTTOM_VERTICAL = 4; /** * @constructor **/ function Cell() { /** @type {boolean} */ this.isBlack = false; /** @type {Array.} */ this.definitions = null; } Cell.prototype.update = function(data) { if (data["type"] === null) { this.isBlack = true; } else if (data["definitions"] !== undefined) { this.definitions = []; data["definitions"].forEach(function(definition) { this.definitions.push(new Definition(definition)); }.bind(this)); } else { // Grid letter // TODO return version } return 0; }; /** * @constructor **/ function Grid(data) { /** @type {string} */ this.title = data["title"] || ""; /** @type {number} */ this.difficulty = data["difficulty"]; /** @type {number} */ this.width = data["w"]; /** @type {number} */ this.height = data["h"]; this.grid = []; for (var i =0; i < this.width; i++) { this.grid[i] = []; for (var j =0; j < this.height; j++) { this.grid[i][j] = new Cell(); } } } /** * @return {number|null} **/ Grid.prototype.update = function(data) { var maxVersion = null ,grid = this.grid; data.forEach(function(cellData) { maxVersion = Math.max(maxVersion || 0, grid[cellData["x"]][cellData["y"]].update(cellData)); }); return maxVersion; };