|
|
|
@@ -211,6 +211,16 @@ export function start(el) {
|
|
|
|
top.container = svg.querySelector('.grid-top > .container');
|
|
|
|
top.container = svg.querySelector('.grid-top > .container');
|
|
|
|
const topHex = svg.querySelector('.grid-top > use[href="#hex"]');
|
|
|
|
const topHex = svg.querySelector('.grid-top > use[href="#hex"]');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const clearHexDialog = document.querySelector('#clear-hex');
|
|
|
|
|
|
|
|
clearHexDialog.addEventListener('close', e => {
|
|
|
|
|
|
|
|
if (clearHexDialog.returnValue === 'confirm') {
|
|
|
|
|
|
|
|
[...top.container.children].forEach(child => {
|
|
|
|
|
|
|
|
top.collection.delete(child);
|
|
|
|
|
|
|
|
child.remove();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
gridTop.addEventListener('pointerleave', e => {
|
|
|
|
gridTop.addEventListener('pointerleave', e => {
|
|
|
|
// Work around webkit bug https://bugs.webkit.org/show_bug.cgi?id=233432
|
|
|
|
// Work around webkit bug https://bugs.webkit.org/show_bug.cgi?id=233432
|
|
|
|
const elUnderCursor = svg.parentNode.elementFromPoint(e.clientX, e.clientY);
|
|
|
|
const elUnderCursor = svg.parentNode.elementFromPoint(e.clientX, e.clientY);
|
|
|
|
@@ -227,6 +237,11 @@ export function start(el) {
|
|
|
|
|
|
|
|
|
|
|
|
topHex.addEventListener('click', clickHandler);
|
|
|
|
topHex.addEventListener('click', clickHandler);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
topHex.addEventListener('contextmenu', e => {
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
getSelected() ? sightLine.toggleLock(top.cell) : clearHexDialog.showModal();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const startingLocations = svg.querySelector('.start-locations');
|
|
|
|
const startingLocations = svg.querySelector('.start-locations');
|
|
|
|
startingLocations && getUnits(startingLocations).forEach(unit => unit.addEventListener('click', selectOffBoard));
|
|
|
|
startingLocations && getUnits(startingLocations).forEach(unit => unit.addEventListener('click', selectOffBoard));
|
|
|
|
|
|
|
|
|
|
|
|
@@ -237,10 +252,8 @@ export function start(el) {
|
|
|
|
let toPlace = placing.pop();
|
|
|
|
let toPlace = placing.pop();
|
|
|
|
|
|
|
|
|
|
|
|
if (isCounter(toPlace) || isMechTemplate(toPlace)) {
|
|
|
|
if (isCounter(toPlace) || isMechTemplate(toPlace)) {
|
|
|
|
//getHex(this).after(toPlace);
|
|
|
|
|
|
|
|
top.collection.set(toPlace, { parent: top.cell });
|
|
|
|
top.collection.set(toPlace, { parent: top.cell });
|
|
|
|
top.container.append(toPlace);
|
|
|
|
top.container.append(toPlace);
|
|
|
|
//if (isCounter(toPlace)) arrangeCounters(this);
|
|
|
|
|
|
|
|
if (isCounter(toPlace)) arrangeCounters(top.container);
|
|
|
|
if (isCounter(toPlace)) arrangeCounters(top.container);
|
|
|
|
removeEventListener("keydown", handleMechTemplateRotation);
|
|
|
|
removeEventListener("keydown", handleMechTemplateRotation);
|
|
|
|
} else if (toPlace && !occupant) {
|
|
|
|
} else if (toPlace && !occupant) {
|
|
|
|
@@ -249,7 +262,7 @@ export function start(el) {
|
|
|
|
top.container.prepend(toPlace);
|
|
|
|
top.container.prepend(toPlace);
|
|
|
|
//toPlace.removeEventListener('click', selectOffBoard);
|
|
|
|
//toPlace.removeEventListener('click', selectOffBoard);
|
|
|
|
placing.push(toPlace);
|
|
|
|
placing.push(toPlace);
|
|
|
|
//getLockedSightLine(svg) ? updateSightLine(this) : clearSightLine();
|
|
|
|
getLockedSightLine(svg) ? updateSightLine(top.cell) : clearSightLine();
|
|
|
|
} else if (toPlace && occupant) {
|
|
|
|
} else if (toPlace && occupant) {
|
|
|
|
if (toPlace === occupant) {
|
|
|
|
if (toPlace === occupant) {
|
|
|
|
Observable.notify('select');
|
|
|
|
Observable.notify('select');
|
|
|
|
@@ -316,25 +329,18 @@ export function start(el) {
|
|
|
|
const selected = getSelected();
|
|
|
|
const selected = getSelected();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
cell.addEventListener('dblclick', e => {
|
|
|
|
//cell.addEventListener('dblclick', e => {
|
|
|
|
const toPlace = placing.pop(),
|
|
|
|
// const toPlace = placing.pop(),
|
|
|
|
occupant = getCellOccupant(cell);
|
|
|
|
// occupant = getCellOccupant(cell);
|
|
|
|
|
|
|
|
//
|
|
|
|
if (toPlace && occupant && toPlace === occupant) {
|
|
|
|
// if (toPlace && occupant && toPlace === occupant) {
|
|
|
|
const { number, allegiance } = toPlace.dataset,
|
|
|
|
// const { number, allegiance } = toPlace.dataset,
|
|
|
|
selector = `[data-allegiance="${allegiance}"][data-number="${number}"]`;
|
|
|
|
// selector = `[data-allegiance="${allegiance}"][data-number="${number}"]`;
|
|
|
|
|
|
|
|
//
|
|
|
|
svg.querySelectorAll(selector).forEach(el => el.remove());
|
|
|
|
// svg.querySelectorAll(selector).forEach(el => el.remove());
|
|
|
|
Observable.notify('select');
|
|
|
|
// Observable.notify('select');
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
});
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
|
|
cell.addEventListener('contextmenu', e => {
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sightLine.toggleLock(cell);
|
|
|
|
|
|
|
|
cell.dispatchEvent(new MouseEvent('pointerover'));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cell.addEventListener('pointerover', () => {
|
|
|
|
cell.addEventListener('pointerover', () => {
|
|
|
|
console.log(['pointerenter', cell]);
|
|
|
|
console.log(['pointerenter', cell]);
|
|
|
|
@@ -371,27 +377,6 @@ export function start(el) {
|
|
|
|
firingArc.toggleCounterVisibility(svg, occupant, true);
|
|
|
|
firingArc.toggleCounterVisibility(svg, occupant, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//cell.addEventListener('pointerout', e => {
|
|
|
|
|
|
|
|
// console.log('pointerout');
|
|
|
|
|
|
|
|
// If pointerout was not triggered by hovering over an element on that
|
|
|
|
|
|
|
|
// game hex
|
|
|
|
|
|
|
|
//if (!e.relatedTarget || top.collection.get(e.relatedTarget)?.parent !== cell) {
|
|
|
|
|
|
|
|
// [...top.container.children].forEach(child => {
|
|
|
|
|
|
|
|
// top.collection.get(child).parent.append(child);
|
|
|
|
|
|
|
|
// top.collection.delete(child);
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// cell.classList.remove('hover');
|
|
|
|
|
|
|
|
// getActiveSightLine(svg) && clearSightLine();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// const occupant = getCellOccupant(cell);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (occupant) {
|
|
|
|
|
|
|
|
// firingArc.toggleCounterVisibility(svg, occupant, false);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//const cell = document.querySelector('[data-q="0"][data-r="0"][data-s="0"][data-t="0"]');
|
|
|
|
//const cell = document.querySelector('[data-q="0"][data-r="0"][data-s="0"][data-t="0"]');
|
|
|
|
@@ -402,14 +387,14 @@ export function start(el) {
|
|
|
|
|
|
|
|
|
|
|
|
// debug //
|
|
|
|
// debug //
|
|
|
|
// Add a trooper counter
|
|
|
|
// Add a trooper counter
|
|
|
|
const attacker = { dataset: { allegiance: 'attacker', number: 1, squad: 1 }};
|
|
|
|
//const attacker = { dataset: { allegiance: 'attacker', number: 1, squad: 1 }};
|
|
|
|
// const defender = { dataset: { allegiance: 'defender', number: 1, squad: 2 }};
|
|
|
|
// const defender = { dataset: { allegiance: 'defender', number: 1, squad: 2 }};
|
|
|
|
const cell = getCell(0, 0, 0, 0);
|
|
|
|
//const cell = getCell(0, 0, 0, 0);
|
|
|
|
const trooper = soldier.createCounter(attacker, 'blazer');
|
|
|
|
//const trooper = soldier.createCounter(attacker, 'blazer');
|
|
|
|
//const trooperSack = document.createElementNS(svgns, 'g');
|
|
|
|
//const trooperSack = document.createElementNS(svgns, 'g');
|
|
|
|
//trooperSack.classList.add('cell-contents');
|
|
|
|
//trooperSack.classList.add('cell-contents');
|
|
|
|
//trooperSack.append(trooper);
|
|
|
|
//trooperSack.append(trooper);
|
|
|
|
soldier.place(svg, trooper, cell);
|
|
|
|
//soldier.place(svg, trooper, cell);
|
|
|
|
|
|
|
|
|
|
|
|
// Add some counters in an unoccupied cell
|
|
|
|
// Add some counters in an unoccupied cell
|
|
|
|
//const countersCell = getCell(-1, 1, 0, 0);
|
|
|
|
//const countersCell = getCell(-1, 1, 0, 0);
|
|
|
|
|