Get mech template placement working again

This commit is contained in:
Catalin Constantin Mititiuc 2025-06-16 22:41:33 -07:00
parent 76eb662bcd
commit b7c6cc8936

View File

@ -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) {