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