Constellations/js/Grid/Color.js

41 lines
836 B
JavaScript
Raw Normal View History

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);
}
2022-07-31 16:32:24 +02:00
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');
}
}
}