From: Elijah Cohen Date: Fri, 1 Apr 2022 07:39:30 +0000 (-0500) Subject: added better export, right-clicking X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=66fa558b25b7bcca4261dee4effbc3b9117ff0c7;p=hexmata added better export, right-clicking --- diff --git a/index.html b/index.html index f086894..944f861 100644 --- a/index.html +++ b/index.html @@ -22,6 +22,7 @@ +
diff --git a/play.js b/play.js index 1f3f43d..d815d90 100644 --- a/play.js +++ b/play.js @@ -44,9 +44,10 @@ function lc() { 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)} @@ -84,11 +85,12 @@ pptoggle = function(e) { 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); diff --git a/wireworld.js b/wireworld.js index 167bee4..15ef28c 100644 --- a/wireworld.js +++ b/wireworld.js @@ -167,6 +167,28 @@ function nextkey(k) { } } +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);