Minor refactor
This commit is contained in:
parent
6f510c9383
commit
de9bdbc83a
@ -272,7 +272,7 @@ function create(x, y, size, counter, { arcContainer, arcLayer, outlineLayer }) {
|
||||
|
||||
export default function (svg) {
|
||||
function set(size, counter, { x, y }) {
|
||||
get(counter).forEach(fa => fa.remove());
|
||||
get(counter).forEach(el => el.remove());
|
||||
|
||||
const { grid, containers } = queryContainers(svg),
|
||||
{ aimLine, firingArc, firingArcOutline } = create(x, y, size, counter, containers);
|
||||
@ -287,16 +287,16 @@ export default function (svg) {
|
||||
}
|
||||
|
||||
function placementListener() {
|
||||
grid.removeAttribute('style');
|
||||
aimLine.remove();
|
||||
svg.querySelectorAll('.firing-arc.active').forEach(el => el.classList.remove('active'));
|
||||
firingArc.classList.remove('active');
|
||||
grid.removeAttribute('style');
|
||||
svg.removeEventListener('mousemove', positionListener);
|
||||
}
|
||||
|
||||
function cancelPlacementListener(e) {
|
||||
e.preventDefault();
|
||||
|
||||
get(counter).forEach(fa => fa.remove());
|
||||
get(counter).forEach(el => el.remove());
|
||||
grid.removeAttribute('style');
|
||||
svg.removeEventListener('mousemove', positionListener);
|
||||
}
|
||||
@ -305,16 +305,16 @@ export default function (svg) {
|
||||
firingArc.addEventListener('click', placementListener, { once: true });
|
||||
firingArc.addEventListener('contextmenu', cancelPlacementListener, { once: true });
|
||||
svg.addEventListener('mousemove', positionListener);
|
||||
};
|
||||
}
|
||||
|
||||
function clear(allegiance) {
|
||||
const selector = `#firing-arcs [data-allegiance="${allegiance}"]`;
|
||||
svg.querySelectorAll(selector).forEach(el => el.remove());
|
||||
};
|
||||
}
|
||||
|
||||
function get({ dataset: { allegiance, number }}) {
|
||||
return svg.querySelectorAll(`#firing-arcs [data-number="${number}"][data-allegiance="${allegiance}"], #firing-arcs line`);
|
||||
};
|
||||
}
|
||||
|
||||
function toggleVisibility(allegiance) {
|
||||
const vis = firingArcVisibility[allegiance],
|
||||
@ -322,7 +322,7 @@ export default function (svg) {
|
||||
|
||||
clipPaths.forEach(cp => cp.style.display = !vis ? 'none' : '');
|
||||
firingArcVisibility[allegiance] = !vis;
|
||||
};
|
||||
}
|
||||
|
||||
function toggleCounterVisibility({ dataset: { number, allegiance }}, vis) {
|
||||
const cp = svg.querySelector(`#clip-path-${allegiance}-${number}`),
|
||||
@ -331,12 +331,10 @@ export default function (svg) {
|
||||
if (cp) {
|
||||
cp.style.display = firingArcVisibility[allegiance] ? 'none' : display;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function clipAll() {
|
||||
const unclipped = getUnclipped(svg);
|
||||
|
||||
unclipped.forEach(el => {
|
||||
getUnclipped(svg).forEach(el => {
|
||||
const { number, allegiance } = el.dataset,
|
||||
clipPathId = `clip-path-${allegiance}-${number}`,
|
||||
isVisible = firingArcVisibility[allegiance];
|
||||
@ -347,7 +345,7 @@ export default function (svg) {
|
||||
|
||||
el.setAttributeNS(null, 'clip-path', `url(#${clipPathId})`);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return { set, clear, get, toggleVisibility, toggleCounterVisibility, clipAll };
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ function create({ x: x1, y: y1 }, { x: x2, y: y2 }) {
|
||||
return sightLine;
|
||||
}
|
||||
|
||||
function lock(cell, sightLine, lockTarget) {
|
||||
function lock(sightLine, cell) {
|
||||
sightLine.classList.remove(activeClassName);
|
||||
cell.classList.add(targetClassName);
|
||||
|
||||
@ -138,7 +138,7 @@ export default function (board) {
|
||||
},
|
||||
|
||||
toggleLock: function (cell) {
|
||||
lockTarget = lockTarget ? unlock(sightLine, lockTarget) : lock(cell, sightLine, lockTarget);
|
||||
lockTarget = lockTarget ? unlock(sightLine, lockTarget) : lock(sightLine, cell);
|
||||
},
|
||||
|
||||
get sightLine() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user