this.change(cp.state, cp.q+q, cp.r+r);
}
}
+
+
+ // still experimental, not a clear way to properly utilise yet
+ getLine(idx, dir) {
+ // idx is the index, i.e. 6 in r=6
+ // dir is in {q,r,s}
+ var theline = [];
+ for(let i of this.cells) {
+ if(i[dir] == idx) theline.push(i);
+ }
+ return theline;
+ }
+ pasteLine(q,r,dir,buf) {
+ let idx = (new Hex(q,r))[dir];
+ for(let i of this.cells) {
+ if(i[dir] == idx) i.state = this.defaultstate;
+ }
+ for(let i in buf) {
+ let cp = i.clone();
+ this.change(cp.state,cp.q,cp.r);
+ }
+ }
}
function gonclick(g,c,ctx,grid,xc,yc,scl,evt) {
+ //console.log(evt);
let rqcoord = getClickCoords(c, scl, xc, yc, evt);
let currst8 = g.stateAt(rqcoord.q, rqcoord.r);
let nextst8 = nextKey(currst8);
drawGrid(g, ctx, xc, yc, scl);
}
function gonrclick(g,c,ctx,grid,xc,yc,scl,evt) {
+ //console.log(evt);
let rqcoord = getClickCoords(c, scl, xc, yc, evt);
let currst8 = g.stateAt(rqcoord.q, rqcoord.r);
let nextst8 = nextKey(currst8,false);
function lc() {
c = document.getElementById('c');
ctx = c.getContext('2d');
- c.onclick = e=>gonclick(g,c,ctx,g,xcenter,ycenter,scale,e)
- c.oncontextmenu = (e) => {e.preventDefault(); gonrclick(g,c,ctx,g,xcenter,ycenter,scale,e)};
+ c.onmousedown = e=>mousedownshell(g,c,ctx,xcenter,ycenter,scale,e);
+ c.onmouseup = e=>mouseup(c);
+ c.oncontextmenu = (e)=>e.preventDefault();
drawGrid(g, ctx, xcenter,ycenter,scale);
document.addEventListener('keydown', e=>{
if(e.key == "p") pptoggle(e);
playbtn = document.getElementById('playpause');
playbtn.addEventListener('click',pptoggle);
range = document.getElementById("tempo");
- //range.addEventListener('click', function(e) {timeout=range.value});
range.onclick = (e) => rangeManage(e);
clr = document.getElementById("clear");
clr.onclick = () => {g.cells = [];
let rad = parseInt(document.getElementById('rad').value);
g.reflHex(coords.q,coords.r,rad);
drawGrid(g, ctx, xcenter,ycenter,scale);
- c.onclick = e=>wwonclick(c,ctx,g,xcenter,ycenter,scale,e);
+ c.onclick = null;
}
flipButtonHandler = function(e) {
c.onclick = e=>flipThingy(e);
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);
+ c.onclick = null;
}
rotateButtonHandler = function(e) {
c.onclick = e=>rotateThingy(e);
let rad = parseInt(document.getElementById('rad').value);
g.rotateHex(coords.q,coords.r,rad);
drawGrid(g, ctx, xcenter,ycenter,scale);
- c.onclick = e=>wwonclick(c,ctx,g,xcenter,ycenter,scale,e);
+ c.onclick = null;
}
copyHandler = function(e) {
let rad = parseInt(document.getElementById('rad').value);
copybuf = g.copyHex(coords.q, coords.r, rad)
drawGrid(g, ctx, xcenter,ycenter,scale);
- c.onclick = e=>wwonclick(c,ctx,g,xcenter,ycenter,scale,e);
+ c.onclick = null;
}
pasteHandler = function(e) {
c.onclick = e=>pastehex(e);
let rad = parseInt(document.getElementById('rad').value);
g.pasteHex(coords.q,coords.r,copybuf);
drawGrid(g, ctx, xcenter,ycenter,scale);
- c.onclick = e=>wwonclick(c,ctx,g,xcenter,ycenter,scale,e);
+ c.onclick = null;
}
exportState = function() {
q = Math.round(preq);
return {r: r, q: q};
}
+
+
+var mmLatestSpot = null;
+function mouseMover(g,c,ctx,xc,yc,scl,isLClick,evt) {
+ return function(evt) {
+ let rqcoord = getClickCoords(c,scl,xc,yc,evt);
+ if(rqcoord.q == mmLatestSpot.q && rqcoord.r == mmLatestSpot.r) {
+ return;
+ }
+ mmLatestSpot = rqcoord;
+ let currst8 = g.stateAt(rqcoord.q, rqcoord.r);
+ let nextst8 = nextKey(currst8,isLClick);
+ g.change(nextst8, rqcoord.q, rqcoord.r);
+ drawGrid(g, ctx, xc, yc, scl);
+ }
+}
+
+var currmovefn = null;
+function mousedownshell(g,c,ctx,xc,yc,scl,evt) {
+ evt.preventDefault();
+ let islclick = evt.button == 0;
+ currmovefn = mouseMover(g,c,ctx,xc,yc,scl,islclick,evt);
+ c.addEventListener('mousemove', currmovefn);
+ let rqcoord = getClickCoords(c,scl,xc,yc,evt);
+ mmLatestSpot = rqcoord;
+ let currst8 = g.stateAt(rqcoord.q, rqcoord.r);
+ let nextst8 = nextKey(currst8,islclick);
+ g.change(nextst8, rqcoord.q, rqcoord.r);
+ drawGrid(g, ctx, xc, yc, scl);
+}
+function mouseup(c) {
+ c.removeEventListener('mousemove',currmovefn);
+}