From: Elijah Cohen Date: Tue, 5 Apr 2022 04:37:40 +0000 (-0500) Subject: added flip, saner defaults X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=f5c88e5358257d8b63633b850a2953bb2043bf66;p=hexmata added flip, saner defaults --- diff --git a/grid.js b/grid.js index 830d4aa..466c46f 100644 --- 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; + } } diff --git a/index.html b/index.html index 26a8bbb..fda488e 100644 --- a/index.html +++ b/index.html @@ -35,13 +35,14 @@ - + - + + diff --git a/play.js b/play.js index 53bf25b..970a6c4 100644 --- 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); diff --git a/wireworld.js b/wireworld.js index c6a9736..43458c5 100644 --- a/wireworld.js +++ b/wireworld.js @@ -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; ix.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