index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <Catalin.Mititiuc@gmail.com> | 2024-04-06 10:46:56 -0700 |
---|---|---|
committer | Catalin Mititiuc <Catalin.Mititiuc@gmail.com> | 2024-04-06 10:46:56 -0700 |
commit | f73241afb8d80ac942935eb0769c03568b5eb4e7 (patch) | |
tree | 700cade15799bd9ace3483b6ac7325c8303d1596 /index.js | |
parent | 16672db15a7ef7e27bfbd8a080cd03740a26d13a (diff) |
Sight line logic; I think it works but this conditional is gnarly
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 69 |
1 files changed, 19 insertions, 50 deletions
@@ -584,7 +584,7 @@ const Counter = new function() { this.endMove = function(el) { let { troopNumber, troopAllegiance } = el.dataset; - let trace = container.querySelector(traceSelector(troopNumber, troopAllegiance)); + let trace = grid.querySelector(traceSelector(troopNumber, troopAllegiance)); if (trace) { trace.remove(); @@ -719,29 +719,21 @@ POINTS.forEach((row, index) => row.forEach(([x, y]) => { }); group.addEventListener('click', e => { - console.log('group click fires'); let cl = e.target.classList, - sl = grid.querySelector('line.sight-line'); + sl = grid.querySelector('line.sight-line'), + targetIsSomeOtherUnitCounter = cl.contains('counter') && !cl.contains('clone'), + selected = RecordSheet.getSelected(); + // maybe we should start with, "are we clicking on a counter?" - // if you click on someone else's counter (but not their clone), - // then you're selecting another soldier, so you should clear the sightline - // if it's locked, and you click on an intermediate clone, nothing should change - // if it's locked and you click on your own counter or your last clone - // it should redraw from your counter to the locked target hex because in - // both cases your counter just moved - - console.log('target', e.target); if (sl) { - let selected = RecordSheet.getSelected(), - { troopNumber: sTn, troopAllegiance: sTa} = selected.dataset, - { troopNumber: tTn, troopAllegiance: tTa} = e.target.dataset; - - console.log('selected', selected); - console.log(cl.contains('counter'), sTn == tTn, sTa == tTa); + let { troopNumber: sTn, troopAllegiance: sTa} = selected.dataset, + { troopNumber: tTn, troopAllegiance: tTa} = e.target.dataset, + sightLineInLockedPosition = !sl.classList.contains('active'), + targetIsCounterOrCloneOfSelected = cl.contains('counter') && sTn == tTn && sTa == tTa; - if (!sl.classList.contains('active') && (cl.contains('counter') && sTn == tTn && sTa == tTa)) { + if (sightLineInLockedPosition && targetIsCounterOrCloneOfSelected) { let counterParent = Counter.get(tTn, tTa).parentElement, [x, y] = counterParent.getAttribute('transform').match(/-?\d+\.?\d*/g), target = ptGrp.querySelector(`g[transform="translate(${sl.getAttribute('x2')} ${sl.getAttribute('y2')})"]`), @@ -752,41 +744,18 @@ POINTS.forEach((row, index) => row.forEach(([x, y]) => { sl.setAttributeNS(null, 'y1', y); SightLine.drawHexes(...[x1, y1, x2, y2].map(n => parseInt(n))); - } else if ((cl.contains('counter') && sTn == tTn && sTa == tTa) || (cl.contains('counter') && !cl.contains('clone'))) { - RecordSheet.select(e.target); - Counter.select(e.target); + } else if (targetIsCounterOrCloneOfSelected || targetIsSomeOtherUnitCounter) { + if (targetIsSomeOtherUnitCounter) { + RecordSheet.select(e.target); + Counter.select(e.target); + } + SightLine.clear(); } + } else if (targetIsSomeOtherUnitCounter) { + RecordSheet.select(e.target); + Counter.select(e.target); } - - // if (cl.contains('counter') && !cl.contains('clone') && !cl.contains('selected')) { - // RecordSheet.select(e.target); - // Counter.select(e.target); - // SightLine.clear(); - // } else if (sl && !sl.classList.contains('active') && cl.contains('counter')) { - // let selected = RecordSheet.getSelected(), - // { troopNumber: tTn, troopAllegiance: tTa} = e.target.dataset; - - // console.log('selected', selected); - - // if (selected && selected.dataset.troopNumber == tTn && selected.dataset.troopAllegiance == tTa) { - // let counterParent = Counter.get(tTn, tTa).parentElement, - // [x, y] = counterParent.getAttribute('transform').match(/-?\d+\.?\d*/g), - // target = ptGrp.querySelector(`g[transform="translate(${sl.getAttribute('x2')} ${sl.getAttribute('y2')})"]`), - // { x: x1, y: y1 } = counterParent.dataset, - // { x: x2, y: y2 } = target.dataset; - - // console.log('group', group); - - // console.log('sl', sl); - // console.log('x1, y1, x2, y2', x1, y1, x2, y2); - - // sl.setAttributeNS(null, 'x1', x); - // sl.setAttributeNS(null, 'y1', y); - - // SightLine.drawHexes(...[x1, y1, x2, y2].map(n => parseInt(n))); - // } - // } }); point.addEventListener('click', e => { |