diff --git a/js/algorithms.js b/js/algorithms.js index fe44fd0..2736a11 100644 --- a/js/algorithms.js +++ b/js/algorithms.js @@ -18,7 +18,7 @@ export function trace_floor_circuit(level, start_cell, start_edge, on_wire, on_d let actor = cell.get_actor(); let wire_directions = terrain.wire_directions; - if (actor?.wire_directions ?? null !== null) + if ((actor?.wire_directions ?? null !== null) && (actor.movement_cooldown === 0 || level.compat.tiles_react_instantly)) { wire_directions = actor.wire_directions; } diff --git a/js/game.js b/js/game.js index 5668258..1a83a59 100644 --- a/js/game.js +++ b/js/game.js @@ -530,6 +530,7 @@ export class Level extends LevelInterface { } this.force_next_wire_phase = false; + this.undid_past_recalculate_circuitry = false; this.recalculate_circuitry(true); // Finally, let all tiles do custom init behavior... but backwards, to match actor order @@ -606,7 +607,7 @@ export class Level extends LevelInterface { } } - recalculate_circuitry(first_time = false) { + recalculate_circuitry(first_time = false, undoing = false) { // Build circuits out of connected wires // TODO document this idea @@ -638,7 +639,7 @@ export class Level extends LevelInterface { let actor = cell.get_actor(); let wire_directions = terrain.wire_directions; - if (actor?.wire_directions ?? null !== null) + if ((actor?.wire_directions ?? null !== null) && (actor.movement_cooldown === 0 || this.compat.tiles_react_instantly)) { wire_directions = actor.wire_directions; } @@ -743,10 +744,11 @@ export class Level extends LevelInterface { if (!first_time) { this.force_next_wire_phase = true; + if (!undoing) { + this._push_pending_undo(() => this.undid_past_recalculate_circuitry = true); + } } } - - can_accept_input() { // We can accept input anytime the player can move, i.e. when they're not already moving and @@ -2229,6 +2231,11 @@ export class Level extends LevelInterface { } this._undo_entry(this.undo_buffer[this.undo_buffer_index]); this.undo_buffer[this.undo_buffer_index] = null; + + if (this.undid_past_recalculate_circuitry) { + this.recalculate_circuitry(false, true); + this.undid_past_recalculate_circuitry = false; + } } // Reverse a single undo entry diff --git a/js/tiletypes.js b/js/tiletypes.js index 0e26e7b..c5f8949 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -836,10 +836,9 @@ const TILE_TYPES = { } else if (other.type.name === 'circuit_block') { level.transmute_tile(me, 'floor'); - me.wire_directions = other.wire_directions; - level.recalculate_circuitry(); + level._set_tile_prop(me, 'wire_directions', other.wire_directions); level.transmute_tile(other, 'splash'); - + level.recalculate_circuitry(); } else if (other.type.is_real_player) { level.fail('drowned', me, other); @@ -2426,6 +2425,9 @@ const TILE_TYPES = { on_clone(me, original) { me.wire_directions = original.wire_directions; }, + on_starting_move(me, level) { + level.recalculate_circuitry(); + }, on_finishing_move(me, level) { level.recalculate_circuitry(); },