Constellations/js/Grid/Color.js

40 lines
836 B
JavaScript

import CellSet;
import Grid;
import iter from Grid.Util;
import Toolbox;
import Mode;
return {
ize: colorize,
paint: paint,
set: set
};
function colorize(row, column, color) {
var grid = Grid.get();
grid.colors[row][column] = color || Toolbox.color();
Grid.cell(row, column).className = 'color' + grid.colors[row][column];
grid.missing.remove(row, column);
}
function paint(row, column) {
var cellSet = CellSet.make(
{type: 'isochrome', row: row, column: column, grid: Grid.get().colors}
);
cellSet.iter(colorize);
}
function set(grid) {
if(grid != undefined) {
iter(grid, function(row, column) {
if(grid[row][column] != undefined) {
colorize(row, column, grid[row][column]);
}
});
if(Grid.get().missing.isEmpty()) {
Mode.setEnabled(true, ['play', 'solve']);
} else {
Mode.set('edit');
}
}
}