Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/game.js')
-rw-r--r--src/modules/game.js31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/modules/game.js b/src/modules/game.js
index d60eff0..5bc1fe3 100644
--- a/src/modules/game.js
+++ b/src/modules/game.js
@@ -1,6 +1,6 @@
import * as firingArc from './game/firingArc.js';
import * as sightLine from './game/sightLine.js';
-import Counter from './game/counter.js';
+import * as counterMod from './game/counter.js';
const svgns = "http://www.w3.org/2000/svg";
@@ -113,7 +113,7 @@ function drawSightLine(sourceCell, targetCell) {
let svg, distanceCallback, proneFlagCallback, selectCallback;
-let board, counterMod,
+let board,
placing = [];
export function setDistanceCallback(callback) {
@@ -131,7 +131,6 @@ export function setSelectCallback(callback) {
export function start(el) {
svg = el;
board = svg.querySelector('.board');
- counterMod = Counter(svg, board);
getCells(svg).forEach(cell => {
cell.addEventListener('click', e => {
@@ -147,7 +146,7 @@ export function start(el) {
if (isGrenade(toPlace)) {
state.hex.after(toPlace);
} else if (toPlace && !state.occupant) {
- counterMod.place(toPlace, cell);
+ counterMod.place(svg, toPlace, cell);
placing.push(toPlace);
const lockedSl = getLockedSightLine(svg);
@@ -159,11 +158,11 @@ export function start(el) {
} else if (toPlace && state.occupant) {
if (toPlace === state.occupant) {
if ('previous' in toPlace.dataset) {
- const trace = counterMod.getTrace(toPlace);
+ const trace = counterMod.getTrace(svg, toPlace);
toPlace.remove();
toPlace = getCounterAtGridIndex(...toPlace.dataset.previous.split(','));
toPlace.classList.remove('clone');
- toPlace.classList.add(counterMod.selectedClass);
+ toPlace.classList.add(counterMod.getSelectedClass());
if (!('previous' in toPlace.dataset)) {
trace.remove();
} else {
@@ -188,11 +187,11 @@ export function start(el) {
if (isClone(state.occupant).of(toPlace)) {
if (!('previous' in state.occupant.dataset)) {
state.occupant.classList.remove('clone');
- state.occupant.classList.add(counterMod.selectedClass);
+ state.occupant.classList.add(counterMod.getSelectedClass());
toPlace.remove();
toPlace = state.occupant;
- counterMod.removeClones(toPlace);
- counterMod.getTrace(toPlace).remove();
+ counterMod.removeClones(svg, toPlace);
+ counterMod.getTrace(svg, toPlace).remove();
const lockedSl = getLockedSightLine(svg);
if (!lockedSl) {
@@ -202,7 +201,7 @@ export function start(el) {
}
} else {
const index = getGridIndex(state.occupant),
- trace = counterMod.getTrace(toPlace),
+ trace = counterMod.getTrace(svg, toPlace),
pos = getCellPosition(cell),
points = trace.getAttribute('points').split(' ').filter(p => p != `${pos.x},${pos.y}`).join(' ');;
@@ -283,18 +282,18 @@ export function start(el) {
});
// debug
- const c = counterMod.getCounter({ dataset: { allegiance: 'davion', number: '1' }});
- counterMod.place(c, getCell(17, 25));
+ const c = counterMod.getCounter(svg, { dataset: { allegiance: 'davion', number: '1' }});
+ counterMod.place(svg, c, getCell(17, 25));
select(c);
}
export function select(selected) {
- const counter = counterMod.getCounter(selected);
+ const counter = counterMod.getCounter(svg, selected);
if (counter) {
unSelect();
placing.push(counter);
- counter.classList.add(counterMod.selectedClass);
+ counter.classList.add(counterMod.getSelectedClass());
firingArc.get(svg, counter).forEach(el => el.removeAttribute('clip-path'));
selectCallback && selectCallback({ prone: counterMod.hasProne(counter), ...counter.dataset });
}
@@ -305,7 +304,7 @@ export function unSelect() {
if (selected) {
placing = [];
- getSelected().classList.remove(counterMod.selectedClass);
+ getSelected().classList.remove(counterMod.getSelectedClass());
clearSightLine();
firingArc.clipAll(svg);
}
@@ -315,7 +314,7 @@ export function endMove() {
const selected = getSelected();
if (selected) {
- counterMod.endMove(selected);
+ counterMod.endMove(svg, selected);
unSelect();
}
}