Finish removing 'doomed'; remove Cell.each
This commit is contained in:
parent
0ba5ecc7e3
commit
8d89f7d9dd
68
js/main.js
68
js/main.js
@ -176,30 +176,9 @@ class Cell extends Array {
|
|||||||
throw new Error("Asked to remove tile that doesn't seem to exist");
|
throw new Error("Asked to remove tile that doesn't seem to exist");
|
||||||
|
|
||||||
this.splice(layer, 1);
|
this.splice(layer, 1);
|
||||||
|
tile.cell = null;
|
||||||
return layer;
|
return layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
each(f) {
|
|
||||||
let copy = Array.from(this);
|
|
||||||
for (let i = 0, l = copy.length; i < l; i++) {
|
|
||||||
if (f(copy[i]) === false)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_gc() {
|
|
||||||
let p = 0;
|
|
||||||
for (let i = 0, l = this.length; i < l; i++) {
|
|
||||||
let cell = this[i];
|
|
||||||
if (! cell.doomed) {
|
|
||||||
if (p !== i) {
|
|
||||||
this[p] = cell;
|
|
||||||
}
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.length = p;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Level {
|
class Level {
|
||||||
@ -361,10 +340,6 @@ class Level {
|
|||||||
|
|
||||||
// XXX this entire turn order is rather different in ms rules
|
// XXX this entire turn order is rather different in ms rules
|
||||||
for (let actor of this.actors) {
|
for (let actor of this.actors) {
|
||||||
// TODO strip these out maybe??
|
|
||||||
if (actor.doomed)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (actor.movement_cooldown > 0) {
|
if (actor.movement_cooldown > 0) {
|
||||||
this._set_prop(actor, 'movement_cooldown', actor.movement_cooldown - 1);
|
this._set_prop(actor, 'movement_cooldown', actor.movement_cooldown - 1);
|
||||||
if (actor.movement_cooldown > 0)
|
if (actor.movement_cooldown > 0)
|
||||||
@ -539,37 +514,42 @@ class Level {
|
|||||||
let blocked;
|
let blocked;
|
||||||
if (goal_x >= 0 && goal_x < this.width && goal_y >= 0 && goal_y < this.height) {
|
if (goal_x >= 0 && goal_x < this.width && goal_y >= 0 && goal_y < this.height) {
|
||||||
// Check for a thin wall in our current cell first
|
// Check for a thin wall in our current cell first
|
||||||
original_cell.each(tile => {
|
for (let tile of original_cell) {
|
||||||
if (tile !== actor && tile.type.thin_walls &&
|
if (tile !== actor && tile.type.thin_walls &&
|
||||||
tile.type.thin_walls.has(direction))
|
tile.type.thin_walls.has(direction))
|
||||||
{
|
{
|
||||||
blocked = true;
|
blocked = true;
|
||||||
return;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// Only bother touching the goal cell if we're not already trapped in this one
|
// Only bother touching the goal cell if we're not already trapped
|
||||||
|
// in this one
|
||||||
|
// (Note that here, and anywhere else that has any chance of
|
||||||
|
// altering the cell's contents, we iterate over a copy of the cell
|
||||||
|
// to insulate ourselves from tiles appearing or disappearing
|
||||||
|
// mid-iteration.)
|
||||||
// FIXME actually, this prevents flicking!
|
// FIXME actually, this prevents flicking!
|
||||||
if (! blocked) {
|
if (! blocked) {
|
||||||
let goal_cell = this.cells[goal_y][goal_x];
|
let goal_cell = this.cells[goal_y][goal_x];
|
||||||
goal_cell.each(tile => {
|
for (let tile of Array.from(goal_cell)) {
|
||||||
if (! tile.blocks(actor, direction))
|
if (! tile.blocks(actor, direction))
|
||||||
return;
|
continue;
|
||||||
|
|
||||||
if (actor.type.pushes && actor.type.pushes[tile.type.name]) {
|
if (actor.type.pushes && actor.type.pushes[tile.type.name]) {
|
||||||
if (this.attempt_step(tile, direction))
|
if (this.attempt_step(tile, direction))
|
||||||
// It moved out of the way!
|
// It moved out of the way!
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
if (tile.type.on_bump) {
|
if (tile.type.on_bump) {
|
||||||
tile.type.on_bump(tile, this, actor);
|
tile.type.on_bump(tile, this, actor);
|
||||||
if (! tile.blocks(actor, direction))
|
if (! tile.blocks(actor, direction))
|
||||||
// It became something non-blocking!
|
// It became something non-blocking!
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
blocked = true;
|
blocked = true;
|
||||||
// XXX should i break here, or bump everything?
|
// XXX should i break here, or bump everything?
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -604,27 +584,27 @@ class Level {
|
|||||||
this.add_tile(actor, goal_cell);
|
this.add_tile(actor, goal_cell);
|
||||||
|
|
||||||
// Announce we're leaving, for the handful of tiles that care about it
|
// Announce we're leaving, for the handful of tiles that care about it
|
||||||
original_cell.each(tile => {
|
for (let tile of Array.from(original_cell)) {
|
||||||
if (tile === actor)
|
if (tile === actor)
|
||||||
return;
|
continue;
|
||||||
if (actor.ignores(tile.type.name))
|
if (actor.ignores(tile.type.name))
|
||||||
return;
|
continue;
|
||||||
|
|
||||||
if (tile.type.on_depart) {
|
if (tile.type.on_depart) {
|
||||||
tile.type.on_depart(tile, this, actor);
|
tile.type.on_depart(tile, this, actor);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// Step on all the tiles in the new cell
|
// Step on all the tiles in the new cell
|
||||||
if (actor === this.player) {
|
if (actor === this.player) {
|
||||||
this._set_prop(this, 'hint_shown', null);
|
this._set_prop(this, 'hint_shown', null);
|
||||||
}
|
}
|
||||||
let teleporter;
|
let teleporter;
|
||||||
goal_cell.each(tile => {
|
for (let tile of Array.from(goal_cell)) {
|
||||||
if (tile === actor)
|
if (tile === actor)
|
||||||
return;
|
continue;
|
||||||
if (actor.ignores(tile.type.name))
|
if (actor.ignores(tile.type.name))
|
||||||
return;
|
continue;
|
||||||
|
|
||||||
if (actor === this.player && tile.type.is_hint) {
|
if (actor === this.player && tile.type.is_hint) {
|
||||||
this._set_prop(this, 'hint_shown', tile.specific_hint ?? this.stored_level.hint);
|
this._set_prop(this, 'hint_shown', tile.specific_hint ?? this.stored_level.hint);
|
||||||
@ -646,7 +626,7 @@ class Level {
|
|||||||
// TODO ooh, obituaries
|
// TODO ooh, obituaries
|
||||||
this.fail("Oops! Watch out for creatures!");
|
this.fail("Oops! Watch out for creatures!");
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// Handle teleporting, now that the dust has cleared
|
// Handle teleporting, now that the dust has cleared
|
||||||
let current_cell = goal_cell;
|
let current_cell = goal_cell;
|
||||||
@ -1466,14 +1446,12 @@ class Game {
|
|||||||
let tile = cell[i];
|
let tile = cell[i];
|
||||||
if (tile) {
|
if (tile) {
|
||||||
any_drawn = true;
|
any_drawn = true;
|
||||||
if (! tile.doomed) {
|
|
||||||
this.tileset.draw(tile, this.level, ctx, dx, dy);
|
this.tileset.draw(tile, this.level, ctx, dx, dy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Auto-size the game canvas to fit the screen, if possible
|
// Auto-size the game canvas to fit the screen, if possible
|
||||||
adjust_scale() {
|
adjust_scale() {
|
||||||
|
|||||||
@ -368,7 +368,7 @@ const TILE_TYPES = {
|
|||||||
connects_to: 'trap',
|
connects_to: 'trap',
|
||||||
connect_order: 'forward',
|
connect_order: 'forward',
|
||||||
on_arrive(me, level, other) {
|
on_arrive(me, level, other) {
|
||||||
if (me.connection && ! me.connection.doomed) {
|
if (me.connection && me.connection.cell) {
|
||||||
let trap = me.connection;
|
let trap = me.connection;
|
||||||
trap.open = true;
|
trap.open = true;
|
||||||
for (let tile of trap.cell) {
|
for (let tile of trap.cell) {
|
||||||
@ -379,7 +379,7 @@ const TILE_TYPES = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
on_depart(me, level, other) {
|
on_depart(me, level, other) {
|
||||||
if (me.connection && ! me.connection.doomed) {
|
if (me.connection && me.connection.cell) {
|
||||||
let trap = me.connection;
|
let trap = me.connection;
|
||||||
trap.open = false;
|
trap.open = false;
|
||||||
for (let tile of trap.cell) {
|
for (let tile of trap.cell) {
|
||||||
@ -394,7 +394,7 @@ const TILE_TYPES = {
|
|||||||
connects_to: 'cloner',
|
connects_to: 'cloner',
|
||||||
connect_order: 'forward',
|
connect_order: 'forward',
|
||||||
on_arrive(me, level, other) {
|
on_arrive(me, level, other) {
|
||||||
if (me.connection && ! me.connection.doomed) {
|
if (me.connection && me.connection.cell) {
|
||||||
me.connection.type.activate(me.connection, level);
|
me.connection.type.activate(me.connection, level);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user