Remove 'reveal pattern' from sight line module
This commit is contained in:
@@ -65,7 +65,39 @@ function axial_lerp(q1, r1, q2, r2, t) {
|
||||
return { q: lerp(q1, q2, t), r: lerp(r1, r2, t) };
|
||||
}
|
||||
|
||||
function calcIndexes(x1, y1, x2, y2) {
|
||||
function lock(sightLine, cell) {
|
||||
sightLine.classList.remove(activeClassName);
|
||||
cell.classList.add(targetClassName);
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
function unlock(sightLine, lockTarget) {
|
||||
sightLine.classList.add(activeClassName);
|
||||
lockTarget.classList.remove(targetClassName);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
let sightLine, lockTarget,
|
||||
activeHexes = [];
|
||||
|
||||
export function create({ x: x1, y: y1 }, { x: x2, y: y2 }) {
|
||||
const line = document.createElementNS(svgns, 'line');
|
||||
|
||||
line.classList.add('sight-line');
|
||||
line.classList.add(activeClassName);
|
||||
line.setAttributeNS(null, 'x1', x1);
|
||||
line.setAttributeNS(null, 'y1', y1);
|
||||
line.setAttributeNS(null, 'x2', x2);
|
||||
line.setAttributeNS(null, 'y2', y2);
|
||||
|
||||
sightLine = line;
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
export function calcIndexes(x1, y1, x2, y2) {
|
||||
const axial1 = evenr_to_axial(x1, y1),
|
||||
axial2 = evenr_to_axial(x2, y2),
|
||||
n = offset_distance(x1, y1, x2, y2),
|
||||
@@ -82,77 +114,33 @@ function calcIndexes(x1, y1, x2, y2) {
|
||||
return results;
|
||||
}
|
||||
|
||||
function create({ x: x1, y: y1 }, { x: x2, y: y2 }) {
|
||||
const sightLine = document.createElementNS(svgns, 'line');
|
||||
export function clear() {
|
||||
sightLine && sightLine.remove();
|
||||
sightLine = null;
|
||||
|
||||
sightLine.classList.add('sight-line');
|
||||
sightLine.classList.add(activeClassName);
|
||||
sightLine.setAttributeNS(null, 'x1', x1);
|
||||
sightLine.setAttributeNS(null, 'y1', y1);
|
||||
sightLine.setAttributeNS(null, 'x2', x2);
|
||||
sightLine.setAttributeNS(null, 'y2', y2);
|
||||
lockTarget && lockTarget.classList.remove(targetClassName);
|
||||
lockTarget = null;
|
||||
}
|
||||
|
||||
export function update({ x, y }) {
|
||||
sightLine.setAttributeNS(null, 'x1', x);
|
||||
sightLine.setAttributeNS(null, 'y1', y);
|
||||
}
|
||||
|
||||
export function toggleLock(cell) {
|
||||
lockTarget = lockTarget ? unlock(sightLine, lockTarget) : lock(sightLine, cell);
|
||||
}
|
||||
|
||||
export function getSightLine() {
|
||||
return sightLine;
|
||||
}
|
||||
|
||||
function lock(sightLine, cell) {
|
||||
sightLine.classList.remove(activeClassName);
|
||||
cell.classList.add(targetClassName);
|
||||
|
||||
return cell;
|
||||
export function getLockTarget() {
|
||||
return lockTarget;
|
||||
}
|
||||
|
||||
function unlock(sightLine, lockTarget) {
|
||||
sightLine.classList.add(activeClassName);
|
||||
lockTarget.classList.remove(targetClassName);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function (board) {
|
||||
let sightLine,
|
||||
lockTarget,
|
||||
activeHexes = [];
|
||||
|
||||
return {
|
||||
calcIndexes,
|
||||
|
||||
drawLine: function (...positions) {
|
||||
this.clear();
|
||||
|
||||
sightLine = create(...positions);
|
||||
board.appendChild(sightLine);
|
||||
},
|
||||
|
||||
clear: function () {
|
||||
sightLine && sightLine.remove();
|
||||
sightLine = null;
|
||||
|
||||
lockTarget && lockTarget.classList.remove(targetClassName);
|
||||
lockTarget = null;
|
||||
},
|
||||
|
||||
update: function ({ x, y }) {
|
||||
sightLine.setAttributeNS(null, 'x1', x);
|
||||
sightLine.setAttributeNS(null, 'y1', y);
|
||||
},
|
||||
|
||||
toggleLock: function (cell) {
|
||||
lockTarget = lockTarget ? unlock(sightLine, lockTarget) : lock(sightLine, cell);
|
||||
},
|
||||
|
||||
get sightLine() {
|
||||
return sightLine;
|
||||
},
|
||||
|
||||
get lockTarget() {
|
||||
return lockTarget;
|
||||
},
|
||||
|
||||
set hexes(hexes) {
|
||||
activeHexes.forEach(h => h.classList.remove(activeClassName));
|
||||
hexes.forEach(h => h.classList.add(activeClassName));
|
||||
activeHexes = hexes;
|
||||
}
|
||||
};
|
||||
export function setHexes(hexes) {
|
||||
activeHexes.forEach(h => h.classList.remove(activeClassName));
|
||||
hexes.forEach(h => h.classList.add(activeClassName));
|
||||
activeHexes = hexes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user