38 lines
794 B
JavaScript
38 lines
794 B
JavaScript
import size from Config;
|
|
import * as CellSet from Geometry.CellSet;
|
|
import * as Dom from UnitJS.Dom;
|
|
import {at, generate, iter, square} from Grid.Util;
|
|
import {diagonal, zero} from Geometry.Vector;
|
|
|
|
var grid = {
|
|
root: document.getElementById('grid'),
|
|
cells: null,
|
|
colors: null,
|
|
missing: null,
|
|
};
|
|
|
|
return {
|
|
clear: clear,
|
|
get: get,
|
|
init: init,
|
|
};
|
|
|
|
function init(eventHandlers) {
|
|
grid.cells = square(size, function(cell) {
|
|
return Dom.make('td', eventHandlers(cell));
|
|
});
|
|
for(var row = 0; row < size; row++) {
|
|
grid.root.appendChild(Dom.make('tr', {}, grid.cells[row]));
|
|
}
|
|
clear();
|
|
}
|
|
|
|
function clear() {
|
|
grid.colors = square(size);
|
|
grid.missing = CellSet.rectangle(zero(), diagonal(size));
|
|
iter(grid.cells, function(td) {td.className = '';});
|
|
}
|
|
|
|
function get() {
|
|
return grid;
|
|
}
|