Implement wire tunnel nesting

This commit is contained in:
Andrew Ekstedt 2020-12-15 20:55:15 -08:00
parent 7c82a4cdf9
commit 03553a5c27

View File

@ -1514,7 +1514,7 @@ export class Level {
let opposite_bit = DIRECTIONS[dirinfo.opposite].bit; let opposite_bit = DIRECTIONS[dirinfo.opposite].bit;
if (wire && (wire.wire_tunnel_directions & dirinfo.bit)) { if (wire && (wire.wire_tunnel_directions & dirinfo.bit)) {
// Search in the given direction until we find a matching tunnel // Search in the given direction until we find a matching tunnel
// FIXME these act like nested parens! // These act like nested parens!
let x = cell.x; let x = cell.x;
let y = cell.y; let y = cell.y;
let nesting = 0; let nesting = 0;
@ -1526,9 +1526,17 @@ export class Level {
let candidate = this.cells[y][x]; let candidate = this.cells[y][x];
neighbor_wire = candidate.get_wired_tile(); neighbor_wire = candidate.get_wired_tile();
if (neighbor_wire && ((neighbor_wire.wire_tunnel_directions ?? 0) & opposite_bit)) { if (neighbor_wire && neighbor_wire.wire_tunnel_directions) {
neighbor = candidate; if (neighbor_wire.wire_tunnel_directions & opposite_bit) {
break; if (nesting <= 0) {
neighbor = candidate;
break;
}
nesting --;
}
if (neighbor_wire.wire_tunnel_directions & dirinfo.bit) {
nesting ++;
}
} }
} }
} }