Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-06-01 17:50:58 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-06-01 17:50:58 -0700
commit163e3a9de59f5d6a8df38fa32a1e7dc4db1ad024 (patch)
tree8ae679d3059d8ee8c69a3d45994bc74e4388f76b /src
parente8fae51b32b6ebc4ec4e16338467b7fcc41edd11 (diff)
Fix/refactor tests
Diffstat (limited to 'src')
-rw-r--r--src/index.js21
-rw-r--r--src/modules/gameboard.js8
-rw-r--r--src/modules/record_sheet.js5
3 files changed, 27 insertions, 7 deletions
diff --git a/src/index.js b/src/index.js
index e638910..7f914d4 100644
--- a/src/index.js
+++ b/src/index.js
@@ -80,11 +80,20 @@ function loadScenario(data) {
async function buildScenario(req) {
console.log('req', req);
+ console.log('fresh template', scenarioTemplate.querySelector('svg'));
+
const svg = scenarioTemplate.querySelector('svg').cloneNode(true);
- document.querySelector('object').contentDocument.querySelector('svg').replaceWith(svg);
- const startLocs = svg.querySelector('.start-locations');
+ // console.log('document', document.querySelector('object').contentDocument);
+
+ document.querySelector('object').contentDocument.querySelector('svg').remove();
+ document.querySelector('object').contentDocument.append(svg);
+
+ gameboard.stop();
+ recordSheet.stop();
+
const scenario = await req;
+ const startLocs = scenario.querySelector('.start-locations');
console.log(scenario);
@@ -119,17 +128,15 @@ async function buildScenario(req) {
});
const refsQuery = [...refs[filename]].join(', ');
- external.querySelectorAll(refsQuery).forEach(node => defs.append(node));
+ external.querySelectorAll(refsQuery).forEach(node => defs.append(svg.ownerDocument.importNode(node, true)));
});
});
- scenario.querySelectorAll('use.mapsheet').forEach(el => gb.prepend(el));
- grid.before(scenario.querySelector('.start-locations'));
+ scenario.querySelectorAll('use.mapsheet').forEach(el => gb.prepend(svg.ownerDocument.importNode(el, true)));
+ if (startLocs) grid.before(svg.ownerDocument.importNode(startLocs, true));
const scenarioGrid = scenario.querySelector('.grid');
- console.log('scenarioGrid', scenarioGrid);
-
if (scenarioGrid) {
grid.replaceWith(svg.ownerDocument.importNode(scenarioGrid, true));
}
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index 38a9a9a..97538cd 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -175,6 +175,7 @@ function selectOffBoard() {
}
function select(data) {
+ console.log('select', data);
const counter = data && (soldier.getCounter(svg, data) || soldier.createCounter(data));
const isSelected = counter?.classList.contains(soldier.getSelectedClass());
@@ -204,6 +205,8 @@ export function start(el) {
startingLocations && getUnits(startingLocations).forEach(unit => unit.addEventListener('click', selectOffBoard));
getCells(svg).forEach(cell => {
+ if (cell.dataset.x === '0' && cell.parentElement.dataset.y === '0') console.log('cell', cell);
+
cell.addEventListener('click', e => {
const occupant = getCellOccupant(cell);
let toPlace = placing.pop();
@@ -300,6 +303,11 @@ export function start(el) {
console.log('gameboard.js loaded');
}
+export function stop() {
+ Observable.unsubscribe('select', select);
+ Observable.unsubscribe('endmove', endMove);
+}
+
export function getUnits() {
return soldier.getAllCounters(svg);
}
diff --git a/src/modules/record_sheet.js b/src/modules/record_sheet.js
index 33a21fe..53f6d83 100644
--- a/src/modules/record_sheet.js
+++ b/src/modules/record_sheet.js
@@ -195,3 +195,8 @@ export function start(startLoc, units) {
Observable.subscribe('select', select);
Observable.subscribe('endmove', endMove);
}
+
+export function stop() {
+ Observable.unsubscribe('select', select);
+ Observable.unsubscribe('endmove', endMove);
+}