Fix firing arcs for squads
This commit is contained in:
parent
f6ee6e3560
commit
a042537c8e
@ -190,13 +190,14 @@ function calcPoints(e, aimLine, grid, size) {
|
||||
return { aimPt, outlinePoints, arcPoints };
|
||||
}
|
||||
|
||||
function setDataAttrs({ dataset: { allegiance, number }}, el) {
|
||||
function setDataAttrs({ dataset: { allegiance, number, squad }}, el) {
|
||||
el.dataset.allegiance = allegiance;
|
||||
el.dataset.number = number;
|
||||
el.dataset.squad = squad;
|
||||
}
|
||||
|
||||
function getClipPathId({ dataset: { allegiance, number }}) {
|
||||
return `clip-path-${allegiance}-${number}`;
|
||||
function getClipPathId({ dataset: { allegiance, number, squad }}) {
|
||||
return `clip-path-${allegiance}-${squad}-${number}`;
|
||||
}
|
||||
|
||||
function getUnclipped(svg) {
|
||||
@ -310,8 +311,11 @@ function clear(svg, allegiance) {
|
||||
svg.querySelectorAll(selector).forEach(el => el.remove());
|
||||
}
|
||||
|
||||
function get(svg, { dataset: { allegiance, number }}) {
|
||||
return svg.querySelectorAll(`#firing-arcs [data-number="${number}"][data-allegiance="${allegiance}"], #firing-arcs line`);
|
||||
function get(svg, { dataset: { allegiance, number, squad }}) {
|
||||
return svg.querySelectorAll(
|
||||
`#firing-arcs [data-number="${number}"][data-allegiance="${allegiance}"][data-squad="${squad}"],
|
||||
#firing-arcs line`
|
||||
);
|
||||
}
|
||||
|
||||
function toggleVisibility(svg, allegiance) {
|
||||
@ -322,20 +326,19 @@ function toggleVisibility(svg, allegiance) {
|
||||
firingArcVisibility[allegiance] = !vis;
|
||||
}
|
||||
|
||||
function toggleCounterVisibility(svg, { dataset: { number, allegiance }}, vis) {
|
||||
const cp = svg.querySelector(`#clip-path-${allegiance}-${number}`),
|
||||
function toggleCounterVisibility(svg, counter, vis) {
|
||||
const cp = svg.querySelector(`#${getClipPathId(counter)}`),
|
||||
display = vis ? 'none' : '';
|
||||
|
||||
if (cp) {
|
||||
cp.style.display = firingArcVisibility[allegiance] ? 'none' : display;
|
||||
cp.style.display = firingArcVisibility[counter.dataset.allegiance] ? 'none' : display;
|
||||
}
|
||||
}
|
||||
|
||||
function clipAll(svg) {
|
||||
getUnclipped(svg).forEach(el => {
|
||||
const { number, allegiance } = el.dataset,
|
||||
clipPathId = `clip-path-${allegiance}-${number}`,
|
||||
isVisible = firingArcVisibility[allegiance];
|
||||
const clipPathId = getClipPathId(el),
|
||||
isVisible = firingArcVisibility[el.dataset.allegiance];
|
||||
|
||||
if (isVisible) {
|
||||
svg.querySelector(`#${clipPathId}`).style.display = 'none';
|
||||
|
@ -3,8 +3,8 @@ import { extractWeaponFromRecord, isRecord } from '../record_sheet.js';
|
||||
|
||||
const selectedClass = 'selected';
|
||||
|
||||
function dataSelector({ dataset: { allegiance, number }}) {
|
||||
return `[data-number="${number}"][data-allegiance="${allegiance}"]`;
|
||||
function dataSelector({ dataset: { allegiance, number, squad }}) {
|
||||
return `[data-number="${number}"][data-allegiance="${allegiance}"][data-squad="${squad}"]`;
|
||||
}
|
||||
|
||||
function traceSelector(counter) {
|
||||
|
@ -207,14 +207,6 @@ function endMove() {
|
||||
}
|
||||
}
|
||||
|
||||
// Work around webkit bug https://bugs.webkit.org/show_bug.cgi?id=233432
|
||||
function workaroundForWebKitBug233432(listener) {
|
||||
return e => {
|
||||
const elUnderCursor = svg.parentNode.elementFromPoint(e.clientX, e.clientY);
|
||||
if (!e.target.contains(elUnderCursor)) listener(e);
|
||||
};
|
||||
}
|
||||
|
||||
export function start(el) {
|
||||
svg = el;
|
||||
const grid = svg.querySelector('.grid');
|
||||
@ -318,6 +310,9 @@ export function start(el) {
|
||||
clearHexDialog.addEventListener('close', e => {
|
||||
if (clearHexDialog.returnValue === 'confirm') {
|
||||
[...frontmost.children].forEach(child => {
|
||||
if (child.classList.contains('counter'))
|
||||
firingArc.get(svg, child).forEach(el => el.remove());
|
||||
|
||||
frontmostStore.delete(child);
|
||||
child.remove();
|
||||
});
|
||||
|
@ -154,8 +154,8 @@ function createRecords(units) {
|
||||
return grouped;
|
||||
}
|
||||
|
||||
function getRecord({ dataset: { allegiance: al, number: n }}) {
|
||||
const selector = `.soldier-record[data-number="${n}"][data-allegiance="${al}"]`;
|
||||
function getRecord({ dataset: { allegiance: al, number: n, squad: s }}) {
|
||||
const selector = `.soldier-record[data-number="${n}"][data-allegiance="${al}"][data-squad="${s}"]`;
|
||||
|
||||
return document.querySelector(selector);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user