From 03553a5c27a1fe4042c96510aa4144e499eb3ef7 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Tue, 15 Dec 2020 20:55:15 -0800 Subject: [PATCH] Implement wire tunnel nesting --- js/game.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/js/game.js b/js/game.js index ffb41fa..8e2a7de 100644 --- a/js/game.js +++ b/js/game.js @@ -1514,7 +1514,7 @@ export class Level { let opposite_bit = DIRECTIONS[dirinfo.opposite].bit; if (wire && (wire.wire_tunnel_directions & dirinfo.bit)) { // 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 y = cell.y; let nesting = 0; @@ -1526,9 +1526,17 @@ export class Level { let candidate = this.cells[y][x]; neighbor_wire = candidate.get_wired_tile(); - if (neighbor_wire && ((neighbor_wire.wire_tunnel_directions ?? 0) & opposite_bit)) { - neighbor = candidate; - break; + if (neighbor_wire && neighbor_wire.wire_tunnel_directions) { + if (neighbor_wire.wire_tunnel_directions & opposite_bit) { + if (nesting <= 0) { + neighbor = candidate; + break; + } + nesting --; + } + if (neighbor_wire.wire_tunnel_directions & dirinfo.bit) { + nesting ++; + } } } }