2022-07-28 17:39:51 +02:00
|
|
|
import GUI;
|
|
|
|
import Grid;
|
|
|
|
import Grid.Color;
|
|
|
|
import Mode;
|
|
|
|
import Toolbox;
|
2022-08-06 18:33:10 +02:00
|
|
|
import Share;
|
2022-07-28 17:39:51 +02:00
|
|
|
|
|
|
|
var down = false;
|
2022-08-10 21:12:39 +02:00
|
|
|
Grid.get().root.addEventListener('mouseleave', function() {
|
2022-07-28 17:39:51 +02:00
|
|
|
down = false;
|
|
|
|
});
|
|
|
|
var save = document.getElementById('save');
|
|
|
|
|
|
|
|
return {
|
|
|
|
events: {
|
|
|
|
onEnter: onEnter,
|
|
|
|
onLeave: onLeave,
|
|
|
|
onMousedown: onMousedown,
|
|
|
|
onMouseup: onMouseup,
|
|
|
|
onMouseenter: onMouseenter
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onEnter() {
|
2022-08-10 21:12:39 +02:00
|
|
|
GUI.activate(true, [Grid.get().root, Toolbox.get(), save]);
|
2022-09-01 21:51:48 +02:00
|
|
|
if(Grid.get().missing.size() > 0) {
|
2022-07-28 17:39:51 +02:00
|
|
|
Mode.setEnabled(false, ['play', 'solve']);
|
2022-08-06 20:18:30 +02:00
|
|
|
} else {
|
|
|
|
Share.link(Grid.get().colors);
|
2022-07-28 17:39:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onLeave() {
|
2022-08-10 21:12:39 +02:00
|
|
|
GUI.activate(false, [Grid.get().root, Toolbox.get(), save, Share.get()]);
|
2022-07-28 17:39:51 +02:00
|
|
|
}
|
|
|
|
|
2022-08-10 21:12:39 +02:00
|
|
|
function onMousedown(e, cell) {
|
2022-07-28 17:39:51 +02:00
|
|
|
if(e.button == GUI.mouse.left) {
|
|
|
|
down = true;
|
|
|
|
if(Toolbox.tool() == 'draw') {
|
2022-08-10 21:12:39 +02:00
|
|
|
colorCell(cell);
|
2022-07-28 17:39:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-10 21:12:39 +02:00
|
|
|
function onMouseup(e, cell) {
|
2022-07-28 17:39:51 +02:00
|
|
|
if(e.button == GUI.mouse.left) {
|
|
|
|
down = false;
|
|
|
|
if(Toolbox.tool() == 'paint') {
|
2022-08-10 21:12:39 +02:00
|
|
|
Grid.Color.paint(cell);
|
2022-07-28 17:39:51 +02:00
|
|
|
checkCompleteness();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-10 21:12:39 +02:00
|
|
|
function onMouseenter(e, cell) {
|
2022-07-28 17:39:51 +02:00
|
|
|
if(down && Toolbox.tool() == 'draw') {
|
2022-08-10 21:12:39 +02:00
|
|
|
colorCell(cell);
|
2022-07-28 17:39:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-10 21:12:39 +02:00
|
|
|
function colorCell(cell) {
|
|
|
|
Grid.Color.ize(cell);
|
2022-07-28 17:39:51 +02:00
|
|
|
checkCompleteness();
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkCompleteness() {
|
2022-09-01 21:51:48 +02:00
|
|
|
if(Grid.get().missing.size() < 1) {
|
2022-07-28 17:39:51 +02:00
|
|
|
Mode.setEnabled(true, ['play', 'solve']);
|
2022-08-06 20:18:30 +02:00
|
|
|
Share.link(Grid.get().colors);
|
2022-07-28 17:39:51 +02:00
|
|
|
}
|
|
|
|
}
|