Constellations/js/Grid/Color.js
2022-08-11 09:58:57 +02:00

40 lines
841 B
JavaScript

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