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