]> git.eli173.com Git - hexmata/commitdiff
added flip, saner defaults
authorElijah Cohen <eli@eli173.com>
Tue, 5 Apr 2022 04:37:40 +0000 (23:37 -0500)
committerElijah Cohen <eli@eli173.com>
Tue, 5 Apr 2022 04:37:40 +0000 (23:37 -0500)
grid.js
index.html
play.js
wireworld.js

diff --git a/grid.js b/grid.js
index 830d4aac5af8b36bca075161972ef6fb02e18747..466c46f18530c23953d401f20caa37b73ff3760c 100644 (file)
--- a/grid.js
+++ b/grid.js
@@ -67,6 +67,15 @@ class Hex {
                                retitem.r = r+rr;
                                return retitem;
                }
+               flip(q,r) {
+                               // flips about point
+                               var ret = this.clone();
+                               let dq = q-this.q;
+                               let dr = r-this.r;
+                               ret.q = q + dq;
+                               ret.r = r + dr;
+                               return ret;
+               }
                
 }
 
index 26a8bbbe71d5b2fc585a8c6b92a5323c51247aaf..fda488e79c970852507146fbdd996e522d077d71 100644 (file)
                        <span>
                                <input type="button" id="step" value="step"/>
                                <input type="button" id="playpause" value="play"/>
-                               <input type="range" id="tempo" min="20" max="500"/>
+                               <input type="range" id="tempo" value="150" min="20" max="500"/>
                                <input type="button" id="clear" value="clear"/>
                                <input type="button" id="reset" value="reset"/>
                        </span>
                        <span>
-                               <input type="number" id="rad" value="5" min="1" max="30" step="1"/>
+                               <input type="number" id="rad" value="9" min="1" max="30" step="1"/>
                                <input type="button" id="rot" value="rotate hex"/>
+                               <input type="button" id="flp" value="flip hex"/>
                                <input type="button" id="copy" value="copy hex"/>
                                <input type="button" id="paste" value="paste hex"/>
                        </span>
diff --git a/play.js b/play.js
index 53bf25b9f3f54b9e382b3a70f0a3d7d09799b464..970a6c4949a33f7680a0fe3f5ecaeec38166cc22 100644 (file)
--- a/play.js
+++ b/play.js
@@ -68,6 +68,8 @@ function lc() {
                sv.onclick = saveState;
                ld = document.getElementById("load");
                ld.onclick = loadState;
+               fl = document.getElementById("flp");
+               fl.onclick = flipButtonHandler;
                load_demos(document.getElementById('seldemo'));
                dl = document.getElementById("dload");
                dl.onclick = demoHandler;
@@ -145,6 +147,21 @@ pptoggle = function(e) {
                }
 };
 
+flipButtonHandler = function(e) {
+               c.onclick =  e=>flipThingy(e);
+               c.addEventListener('mousemove', radius_hover);
+
+               // tf are those arguments globals are there for a reason
+}
+flipThingy = function(evt) {
+               c.removeEventListener('mousemove', radius_hover);
+               let coords = getClickCoords(c,scale,xcenter,ycenter,evt);
+               let rad = parseInt(document.getElementById('rad').value);
+               g.flipHex(coords.q,coords.r,rad);
+               drawGrid(g, ctx, xcenter,ycenter,scale);
+               c.onclick = e=>wwonclick(c,ctx,g,xcenter,ycenter,scale,e);
+}
+
 rotateButtonHandler = function(e) {
                c.onclick =  e=>rotateThingy(e);
                c.addEventListener('mousemove', radius_hover);
index c6a97363983f864fc0349cdeb58436258768434a..43458c572dbaac9e34f86f3d0f63f409f4102979 100644 (file)
@@ -121,6 +121,49 @@ class WWGrid {
                                let cells2 = this.cells.map((c)=>c.rotate(q,r,ccw));
                                this.cells = cells2;
                }
+
+               flipHex(q,r,radius) {
+                               var rcells = [this.cellAt(q,r)];
+                               for(let i=1; i<radius; i++) {
+                                               var currcell = this.cellAt(q,r+i);
+                                               for(let j=0; j<6; j++) {
+                                                               let dirv = null;
+                                                               switch(j) {
+                                                               case 0:
+                                                                               dirv = {q: 1, r:-1};
+                                                                               break;
+                                                               case 1:
+                                                                               dirv = {q: 0, r:-1};
+                                                                               break;
+                                                               case 2:
+                                                                               dirv = {q:-1, r: 0};
+                                                                               break;
+                                                               case 3:
+                                                                               dirv = {q:-1, r: 1};
+                                                                               break;
+                                                               case 4:
+                                                                               dirv = {q: 0, r: 1};
+                                                                               break;
+                                                               case 5:
+                                                                               dirv = {q: 1, r: 0};
+                                                                               break;
+                                                               }
+                                                               for(let k=0; k<i; k++) {
+                                                                               rcells.push(currcell);
+                                                                               currcell = this.cellAt(currcell.q + dirv.q, currcell.r + dirv.r);
+                                                               }
+                                               }                                                               
+                               }
+                               
+                               let newcells = rcells.map(x=>x.flip(q,r));
+                               //this.cells = newcells;
+                               for(let i of newcells) {
+                                               this.change(i.state, i.q, i.r);
+                               }
+                               this.clean();
+
+               }
+               
                rotateHex(q,r,radius,ccw=true) {
                                var rcells = [this.cellAt(q,r)];
                                for(let i=1; i<radius; i++) {