spontaneously appearing button/buttonable fixes

This commit is contained in:
Timothy Stiles 2021-02-14 22:07:20 +11:00
parent 7d36d09715
commit 86404dbc5b
2 changed files with 16 additions and 7 deletions

View File

@ -690,7 +690,7 @@ export class Level extends LevelInterface {
} }
} }
} }
return; return;
} }
// Orange buttons do a really weird diamond search // Orange buttons do a really weird diamond search
@ -704,7 +704,7 @@ export class Level extends LevelInterface {
} }
} }
if (target !== null) { if (target !== null) {
connectable.connection = target; connectable.connection = target;
break; break;
} }
} }
@ -2511,15 +2511,21 @@ export class Level extends LevelInterface {
} }
//if we made a button or something that's buttonable, update accordingly //if we made a button or something that's buttonable, update accordingly
if (new_type.connects_to) if (new_type.connects_to && (new_type.connects_to !== old_type.connects_to))
{ {
this.connect_button(tile); this.connect_button(tile);
} }
else if (new_type.connected_from) else if (new_type.connected_from && (new_type.connected_from !== old_type.connected_from))
{ {
this.connect_buttons_to(tile); this.connect_buttons_to(tile);
} }
//ready the tile
if (new_type.on_begin)
{
new_type.on_begin(tile, this);
}
//TODO: update circuit networks? //TODO: update circuit networks?
} }
} }

View File

@ -1430,13 +1430,16 @@ const TILE_TYPES = {
trap: { trap: {
layer: LAYERS.terrain, layer: LAYERS.terrain,
connected_from: 'button_brown', connected_from: 'button_brown',
on_begin(me, level) {
me.presses = 0;
},
add_press_ready(me, level, other) { add_press_ready(me, level, other) {
// Same as below, but without ejection // Same as below, but without ejection
me.presses = (me.presses ?? 0) + 1; me.presses = me.presses + 1;
}, },
// Lynx (not cc2): open traps immediately eject their contents on arrival, if possible // Lynx (not cc2): open traps immediately eject their contents on arrival, if possible
add_press(me, level, is_wire = false) { add_press(me, level, is_wire = false) {
level._set_tile_prop(me, 'presses', (me.presses ?? 0) + 1); level._set_tile_prop(me, 'presses', me.presses + 1);
// TODO weird cc2 case that may or may not be a bug: actors aren't ejected if the trap // TODO weird cc2 case that may or may not be a bug: actors aren't ejected if the trap
// opened because of wiring // opened because of wiring
if (me.presses === 1 && ! is_wire) { if (me.presses === 1 && ! is_wire) {
@ -1450,7 +1453,7 @@ const TILE_TYPES = {
} }
}, },
remove_press(me, level) { remove_press(me, level) {
level._set_tile_prop(me, 'presses', me.presses - 1); level._set_tile_prop(me, 'presses', Math.max(0, me.presses - 1));
if (me._initially_open) { if (me._initially_open) {
level._set_tile_prop(me, '_initially_open', false); level._set_tile_prop(me, '_initially_open', false);
} }