onNodeFocus?.(this.chunk, node);
console.log(`clicked chunk ${this.chunk.location.x} ${this.chunk.location.y} node ${node.x}, ${node.y}`);
// if nothing is selected
if (this.chunk.selectedNodes.values().length == 0) {
// select it
this.chunk.selectedNodes.put(node);
g.tint = 0xBBBBBB;
// g.alpha = 0.5;
} else if (this.chunk.selectedNodes.get(node)) {
// i was already selected, let's allocate it
this.chunk.selectedNodes.remove(node);
// try to allocate, only allow if we are connected to something already allocated
let neighbors = [node.addX(1), node.addY(1), node.addY(-1), node.addX(-1)];
let allowed = false;
for (let neighbor of neighbors) {
if (this.chunk.allocatedNodes.get(neighbor)) {
allowed = true;
break;
}
}
if (allowed) {
this.chunk.allocatedNodes.put(node);
g.tint = 0x00aaff;
} else {
g.tint = 0xFFFFFF;
window.alert('not allowed to allocate that one!');
}
// g.alpha = 0.5;
} else {
// unselect what was previously selected
for (let selected of this.chunk.selectedNodes.values()) {
this.renderedNodes.get(selected).tint = 0xFFFFFF;
this.chunk.selectedNodes.remove(selected);
}
this.chunk.selectedNodes.put(node);
g.tint = 0xBBBBBB;
}