2014-01-09 20:18:46 +00:00
|
|
|
goog.provide('ascii.State');
|
2014-01-08 21:58:41 +00:00
|
|
|
|
2014-01-11 18:53:45 +00:00
|
|
|
/** @const */ var MAX_GRID_SIZE = 1000;
|
2014-01-11 16:40:01 +00:00
|
|
|
|
2014-01-08 21:58:41 +00:00
|
|
|
/**
|
2014-01-12 10:37:38 +00:00
|
|
|
* An individual cell within the diagram and it's current value.
|
|
|
|
*
|
2014-01-08 21:58:41 +00:00
|
|
|
* @constructor
|
|
|
|
*/
|
2014-01-09 20:18:46 +00:00
|
|
|
ascii.Cell = function() {
|
2014-01-12 10:37:38 +00:00
|
|
|
/** @type {?string} */ this.value = null;
|
2014-01-08 21:58:41 +00:00
|
|
|
};
|
|
|
|
|
2014-01-12 10:37:38 +00:00
|
|
|
/**
|
|
|
|
* Sets the cells value.
|
|
|
|
*
|
|
|
|
* @param {string} value
|
|
|
|
*/
|
2014-01-09 20:18:46 +00:00
|
|
|
ascii.Cell.prototype.setValue = function(value) {
|
2014-01-08 21:58:41 +00:00
|
|
|
this.value = value;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-01-12 10:37:38 +00:00
|
|
|
* Holds the entire state of the diagram as a 2D array of cells.
|
|
|
|
*
|
2014-01-08 21:58:41 +00:00
|
|
|
* @constructor
|
|
|
|
*/
|
2014-01-09 20:18:46 +00:00
|
|
|
ascii.State = function() {
|
|
|
|
/** @type {Array.<Array.<ascii.Cell>>} */
|
2014-01-11 18:53:45 +00:00
|
|
|
this.cells = new Array(MAX_GRID_SIZE);
|
2014-01-08 21:58:41 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < this.cells.length; i++) {
|
2014-01-11 18:53:45 +00:00
|
|
|
this.cells[i] = new Array(MAX_GRID_SIZE);
|
2014-01-08 21:58:41 +00:00
|
|
|
for (var j = 0; j < this.cells[i].length; j++) {
|
2014-01-09 20:18:46 +00:00
|
|
|
this.cells[i][j] = new ascii.Cell();
|
2014-01-08 21:58:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-12 10:37:38 +00:00
|
|
|
/**
|
|
|
|
* Returns the cell at the given coordinates.
|
|
|
|
*
|
|
|
|
* @param {ascii.Vector} vector
|
|
|
|
* @return {asii.Cell}
|
|
|
|
*/
|
2014-01-11 16:40:01 +00:00
|
|
|
ascii.State.prototype.getCell = function(vector) {
|
2014-01-11 17:41:44 +00:00
|
|
|
return this.cells[vector.x][vector.y];
|
2014-01-08 21:58:41 +00:00
|
|
|
};
|