Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-08-01 16:03:30 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-08-01 16:03:30 -0700
commit42af4651c2f1227b4fe9c4917a233afda7dd397d (patch)
tree94ef5de682418c8fe205aeeb59f2fe41de1beaac
parent9959b880da96e12eb8f4305c4aae38539fcd4e30 (diff)
Get mech template placement working again
-rw-r--r--src/modules/gameboard.js19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index a033a29..b1e28fa 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -278,16 +278,6 @@ export function start(el) {
// Pointer moves over a cell
if (targetCell) {
- //console.log(
- // "targetCell.classList.contains('frontmost')", targetCell.classList.contains('frontmost'),
- // "e.target.closest('.frontmost > *')", e.target.closest('.frontmost > *'),
- // "frontmostStore.get(e.target.closest('.frontmost > *'))", frontmostStore.get(e.target.closest('.frontmost > *')),
- // "frontmostStore.get(e.target.closest('.frontmost > *')).classList.contains('hover')", frontmostStore.get(e.target.closest('.frontmost > *')).classList.contains('hover')
- //);
-
- //if (
- // !(targetCell.classList.contains('frontmost') && frontmostStore.get(e.target.closest('.frontmost > *')).classList.contains('hover')) && !targetCell.classList.contains('hover')
- //) {
if ([
// that is not already highlighted
!targetCell.classList.contains('hover'),
@@ -297,6 +287,10 @@ export function start(el) {
console.log('Target cell missing hover... CLEARING HOVERS AND ADDING TO TARGET CELL');
svg.querySelectorAll('.hover').forEach(el => el.classList.remove('hover'));
+ if (placing[0]?.getAttributeNS(null, 'class') === 'mech-template') {
+ targetCell.prepend(placing[0]);
+ }
+
[...frontmost.children].forEach(child => {
const parent = frontmostStore.get(child);
parent.append(child);
@@ -481,12 +475,13 @@ export function start(el) {
if (isCounter(toPlace) || isMechTemplate(toPlace)) {
frontmostStore.set(toPlace, targetCell);
- frontmost.append(toPlace);
+ isMechTemplate(toPlace) ? frontmost.prepend(toPlace) : frontmost.append(toPlace);
if (isCounter(toPlace)) arrangeCounters(frontmost);
removeEventListener("keydown", handleMechTemplateRotation);
} else if (toPlace && !occupant) {
frontmostStore.set(toPlace, targetCell);
- frontmost.prepend(toPlace);
+ const mechTemplate = frontmost.querySelector('.mech-template');
+ mechTemplate ? mechTemplate.after(toPlace) : frontmost.prepend(toPlace);
placing.push(toPlace);
getLockedSightLine(svg) ? updateSightLine(targetCell) : clearSightLine();
} else if (toPlace && occupant) {