<input type="button" id="reset" value="reset"/>
<input type="button" id="es" value="export state"/>
<input type="button" id="is" value="import state"/>
+ <details><summary></summary><span id="outzone"></span></details>
</div>
<div><canvas width="2000" height="2000" id="c"></canvas></div>
</body>
ctx = c.getContext('2d');
//c.addEventListener('click', e=>getClickCoords(c, 20, 200, 200, e));
c.addEventListener('click', e=>wwonclick(c,ctx,g,xcenter,ycenter,scale,e));
+ window.oncontextmenu = (e) => {e.preventDefault();}
+ c.oncontextmenu = (e) => wwonrtclick(c,ctx,g,xcenter,ycenter,scale,e)
drawGrid(g, ctx, xcenter,ycenter,scale);
document.addEventListener('keydown', e=>{
- console.log(e.key);
if(e.key == "p") pptoggle(e);
if(e.key == "s") {g.step();drawGrid(g,ctx,xcenter,ycenter,scale);}
if(e.key == "r") {g=rstgrid.clone(); drawGrid(g, ctx, xcenter,ycenter,scale)}
exportState = function() {
let s = g.exportState();
- alert(s);
+ deets = document.getElementById("outzone");
+ deets.innerText = s
+ //alert(s);
}
importState = function() {
- console.log("hi");
let s = prompt("paste state string below");
g.loadState(s);
drawGrid(g, ctx, xcenter,ycenter,scale);
}
}
+function prevkey(k) {
+ switch(k) {
+ case WWState.EMPTY:
+ return WWState.TAIL;
+ case WWState.OFF:
+ return WWState.EMPTY;
+ case WWState.HEAD:
+ return WWState.OFF;
+ default: //tail
+ return WWState.HEAD;
+ }
+}
+
+function wwonrtclick(c, ctx, grid, cx, cy, scale, event) {
+ let rqcoord = getClickCoords(c, scale, cx, cy, event);
+ let currst8 = grid.stateAt(rqcoord.q, rqcoord.r);
+ let nextst8 = prevkey(currst8);
+ grid.change(nextst8, rqcoord.q, rqcoord.r);
+ drawGrid(grid, ctx, cx, cy, scale);
+
+}
+
function wwonclick(c, ctx, grid, cx, cy, scale, event) {
let rqcoord = getClickCoords(c, scale, cx, cy, event);
let currst8 = grid.stateAt(rqcoord.q, rqcoord.r);