import GUI; import Grid; import Grid.Color; import Mode; import Toolbox; import Share; var down = false; Grid.get().root.addEventListener('mouseleave', function() { down = false; }); var save = document.getElementById('save'); return { events: { onEnter: onEnter, onLeave: onLeave, onMousedown: onMousedown, onMouseup: onMouseup, onMouseenter: onMouseenter } }; function onEnter() { GUI.activate(true, [Grid.get().root, Toolbox.get(), save]); if(!Grid.get().missing.isEmpty()) { Mode.setEnabled(false, ['play', 'solve']); } else { Share.link(Grid.get().colors); } } function onLeave() { GUI.activate(false, [Grid.get().root, Toolbox.get(), save, Share.get()]); } function onMousedown(e, cell) { if(e.button == GUI.mouse.left) { down = true; if(Toolbox.tool() == 'draw') { colorCell(cell); } } } function onMouseup(e, cell) { if(e.button == GUI.mouse.left) { down = false; if(Toolbox.tool() == 'paint') { Grid.Color.paint(cell); checkCompleteness(); } } } function onMouseenter(e, cell) { if(down && Toolbox.tool() == 'draw') { colorCell(cell); } } function colorCell(cell) { Grid.Color.ize(cell); checkCompleteness(); } function checkCompleteness() { if(Grid.get().missing.isEmpty()) { Mode.setEnabled(true, ['play', 'solve']); Share.link(Grid.get().colors); } }