Constellations/js/Grid/Color.js

41 lines
841 B
JavaScript
Raw Normal View History

2022-08-10 21:12:39 +02:00
import * as CellSet from Geometry.CellSet;
import Grid;
2022-08-10 21:12:39 +02:00
import {at, iter, set} from Grid.Util;
import Toolbox;
import Mode;
return {
ize: colorize,
paint: paint,
2022-08-10 21:12:39 +02:00
setColors: setColors
};
2022-08-10 21:12:39 +02:00
function colorize(cell, color) {
var grid = Grid.get();
2022-08-10 21:12:39 +02:00
set(grid.colors, cell, color || Toolbox.color());
at(Grid.get().cells, cell).className = 'color' + at(grid.colors, cell);
grid.missing.remove(cell);
}
2022-08-10 21:12:39 +02:00
function paint(origin) {
var cellSet = CellSet.make(
2022-08-10 21:12:39 +02:00
{type: 'isochrome', grid: Grid.get().colors, origin: origin}
);
cellSet.iter(colorize);
}
2022-08-10 21:12:39 +02:00
function setColors(grid) {
if(grid != undefined) {
2022-08-10 21:12:39 +02:00
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');
}
}
}