Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/gameboard.js')
-rw-r--r--src/modules/gameboard.js34
1 files changed, 9 insertions, 25 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index 45b2cb5..a716ca8 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -3,7 +3,7 @@ import * as sightLine from './game/sight_line.js';
import * as soldier from './game/soldier.js';
import { Observable } from "./observable";
-let svg, selected,
+let svg,
placing = [];
function getCellContents(cell) {
@@ -100,16 +100,6 @@ function getSightLineHexes(source, target) {
}
function updateSightLine(cell) {
- // const CURRENT_ELEVATION_LEVEL = 0;
- // const { q: sq, r: sr, s: ss } = cell.dataset;
- // const { q: tq, r: tr, s: ts } = sightLine.getLockTarget().dataset;
- // const sourceIndex = { q: +sq, r: +sr, s: +ss };
- // const targetIndex = { q: +tq, r: +tr, s: +ts };
-
- // const selector = sightLine.calcIndexes(sourceIndex, targetIndex)
- // .map(({ q, r, s }) => `g[data-q="${q}"][data-r="${r}"][data-s="${s}"][data-t="${CURRENT_ELEVATION_LEVEL}"] use[href="#hex"]`)
- // .join(', ');
-
const hexes = getSightLineHexes(cell, sightLine.getLockTarget());
sightLine.setHexes(hexes);
sightLine.update(getCellPosition(cell));
@@ -117,16 +107,6 @@ function updateSightLine(cell) {
}
function drawSightLine(sourceCell, targetCell) {
- // const CURRENT_ELEVATION_LEVEL = 0;
- // const { q: sq, r: sr, s: ss } = sourceCell.dataset;
- // const { q: tq, r: tr, s: ts } = targetCell.dataset;
- // const sourceIndex = { q: +sq, r: +sr, s: +ss };
- // const targetIndex = { q: +tq, r: +tr, s: +ts };
-
- // const selector = sightLine.calcIndexes(sourceIndex, targetIndex)
- // .map(({ q, r, s }) => `g[data-q="${q}"][data-r="${r}"][data-s="${s}"][data-t="${CURRENT_ELEVATION_LEVEL}"] use[href="#hex"]`)
- // .join(', ');
-
const hexes = getSightLineHexes(sourceCell, targetCell);
sightLine.setHexes(hexes);
const line = sightLine.create(getCellPosition(sourceCell), getCellPosition(targetCell));
@@ -136,10 +116,12 @@ function drawSightLine(sourceCell, targetCell) {
function moveBackOneStepInHistory(counter) {
const trace = soldier.getTrace(svg, counter);
+
counter.remove();
counter = getCounterAtGridIndex(...counter.dataset.previous.split(','));
counter.classList.remove('clone');
counter.classList.add(soldier.getSelectedClass());
+
if (!('previous' in counter.dataset)) {
trace.remove();
} else {
@@ -299,7 +281,7 @@ export function start(el) {
cell.addEventListener('pointerout', () => {
getActiveSightLine(svg) && clearSightLine();
- let occupant = getCellOccupant(cell);
+ const occupant = getCellOccupant(cell);
if (occupant) {
firingArc.toggleCounterVisibility(svg, occupant, false);
@@ -308,9 +290,11 @@ export function start(el) {
});
// debug //
- const c = soldier.createCounter({ dataset: { allegiance: 'attacker', number: 1, squad: 1 }});
- soldier.place(svg, c, svg.querySelector('[data-q="0"][data-r="0"][data-s="0"][data-t="0"]'));
- // soldier.place(svg, c, svg.querySelector('[data-q="-2"][data-r="-3"][data-s="5"][data-t="0"]'));
+ const attacker = { dataset: { allegiance: 'attacker', number: 1, squad: 1 }};
+ const defender = { dataset: { allegiance: 'defender', number: 1, squad: 2 }};
+
+ soldier.place(svg, soldier.createCounter(attacker, 'blazer'), getCell(0, 0, 0, 0));
+ soldier.place(svg, soldier.createCounter(defender, 'rifle'), getCell(-1, 0, 1, 0));
///////////
Observable.subscribe('select', select);