Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/modules/gameboard.js24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index 4d6790a..693c783 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -90,33 +90,39 @@ function clearSightLine() {
Observable.notify('distance');
}
-function getSightLineHexes(source, target) {
+function calcSightLineIndexes(source, target) {
const { q: sq, r: sr, s: ss } = source.dataset;
const { q: tq, r: tr, s: ts } = target.dataset;
const sourceIndex = { q: +sq, r: +sr, s: +ss };
const targetIndex = { q: +tq, r: +tr, s: +ts };
- const selector = sightLine
- .calcIndexes(sourceIndex, targetIndex)
+ return sightLine.calcIndexes(sourceIndex, targetIndex);
+}
+
+function getSightLineHexes(indexes) {
+ const selector = indexes
.map(({ q, r, s }) => `g[data-q="${q}"][data-r="${r}"][data-s="${s}"] use[href="#hex"]`)
.join(', ');
return svg.querySelectorAll(selector);
}
-function updateSightLine(cell) {
- const hexes = getSightLineHexes(cell, sightLine.getLockTarget());
+function calcSightLine(source, target) {
+ const indexes = calcSightLineIndexes(source, target);
+ const hexes = getSightLineHexes(indexes);
sightLine.setHexes(hexes);
+ Observable.notify('distance', indexes.length - 1);
+}
+
+function updateSightLine(cell) {
+ calcSightLine(cell, sightLine.getLockTarget());
sightLine.update(getCellPosition(cell));
- Observable.notify('distance', hexes.length - 1);
}
function drawSightLine(sourceCell, targetCell) {
- const hexes = getSightLineHexes(sourceCell, targetCell);
- sightLine.setHexes(hexes);
+ calcSightLine(sourceCell, targetCell)
const line = sightLine.create(getCellPosition(sourceCell), getCellPosition(targetCell));
svg.querySelector('.gameboard').appendChild(line);
- Observable.notify('distance', hexes.length - 1);
}
function moveBackOneStepInHistory(counter) {