handle circuit block undoing pretty well

This commit is contained in:
Timothy Stiles 2021-02-15 15:59:28 +11:00
parent 1bd165ad35
commit 9e2575cae4
3 changed files with 17 additions and 8 deletions

View File

@ -18,7 +18,7 @@ export function trace_floor_circuit(level, start_cell, start_edge, on_wire, on_d
let actor = cell.get_actor(); let actor = cell.get_actor();
let wire_directions = terrain.wire_directions; 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; wire_directions = actor.wire_directions;
} }

View File

@ -530,6 +530,7 @@ export class Level extends LevelInterface {
} }
this.force_next_wire_phase = false; this.force_next_wire_phase = false;
this.undid_past_recalculate_circuitry = false;
this.recalculate_circuitry(true); this.recalculate_circuitry(true);
// Finally, let all tiles do custom init behavior... but backwards, to match actor order // 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 // Build circuits out of connected wires
// TODO document this idea // TODO document this idea
@ -638,7 +639,7 @@ export class Level extends LevelInterface {
let actor = cell.get_actor(); let actor = cell.get_actor();
let wire_directions = terrain.wire_directions; 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; wire_directions = actor.wire_directions;
} }
@ -743,11 +744,12 @@ export class Level extends LevelInterface {
if (!first_time) { if (!first_time) {
this.force_next_wire_phase = true; this.force_next_wire_phase = true;
if (!undoing) {
this._push_pending_undo(() => this.undid_past_recalculate_circuitry = true);
}
} }
} }
can_accept_input() { can_accept_input() {
// We can accept input anytime the player can move, i.e. when they're not already moving and // We can accept input anytime the player can move, i.e. when they're not already moving and
// not in an un-overrideable slide. // not in an un-overrideable slide.
@ -2229,6 +2231,11 @@ export class Level extends LevelInterface {
} }
this._undo_entry(this.undo_buffer[this.undo_buffer_index]); this._undo_entry(this.undo_buffer[this.undo_buffer_index]);
this.undo_buffer[this.undo_buffer_index] = null; 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 // Reverse a single undo entry

View File

@ -836,10 +836,9 @@ const TILE_TYPES = {
} }
else if (other.type.name === 'circuit_block') { else if (other.type.name === 'circuit_block') {
level.transmute_tile(me, 'floor'); level.transmute_tile(me, 'floor');
me.wire_directions = other.wire_directions; level._set_tile_prop(me, 'wire_directions', other.wire_directions);
level.recalculate_circuitry();
level.transmute_tile(other, 'splash'); level.transmute_tile(other, 'splash');
level.recalculate_circuitry();
} }
else if (other.type.is_real_player) { else if (other.type.is_real_player) {
level.fail('drowned', me, other); level.fail('drowned', me, other);
@ -2426,6 +2425,9 @@ const TILE_TYPES = {
on_clone(me, original) { on_clone(me, original) {
me.wire_directions = original.wire_directions; me.wire_directions = original.wire_directions;
}, },
on_starting_move(me, level) {
level.recalculate_circuitry();
},
on_finishing_move(me, level) { on_finishing_move(me, level) {
level.recalculate_circuitry(); level.recalculate_circuitry();
}, },