]> git.eli173.com Git - hexmata/commitdiff
added better export, right-clicking
authorElijah Cohen <eli@eli173.com>
Fri, 1 Apr 2022 07:39:30 +0000 (02:39 -0500)
committerElijah Cohen <eli@eli173.com>
Fri, 1 Apr 2022 07:39:30 +0000 (02:39 -0500)
index.html
play.js
wireworld.js

index f086894bd56cd3b50d84ac797f030f40d41ad7d5..944f861168ff3f3bb920a11f2949951a2e53d234 100644 (file)
@@ -22,6 +22,7 @@
                        <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>
diff --git a/play.js b/play.js
index 1f3f43d9b1d5528a69311e17d149b942b3ea44b2..d815d905321f283ed9297793dfc016ef51fd8e29 100644 (file)
--- 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);                
index 167bee46af93430e715838b42712f8201ec360c0..15ef28c20c0c490de4c6a588b002714dedc73cb5 100644 (file)
@@ -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);