Move diamond iteration to algorithms so the editor can (eventually) use it
This commit is contained in:
parent
4077bd0de3
commit
f2366be039
@ -118,3 +118,28 @@ export function find_matching_wire_tunnel(level, x, y, direction) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO make this guy work generically for orange, red, brown buttons? others...?
|
||||
export function find_implicit_connection() {
|
||||
}
|
||||
|
||||
// Iterates over a grid in a diamond pattern, spreading out from the given start cell (but not
|
||||
// including it). Only used for connecting orange buttons.
|
||||
export function* iter_cells_in_diamond(levelish, x0, y0) {
|
||||
let max_search_radius = Math.max(levelish.size_x, levelish.size_y) + 1;
|
||||
for (let dist = 1; dist <= max_search_radius; dist++) {
|
||||
// Start east and move counterclockwise
|
||||
let sx = x0 + dist;
|
||||
let sy = y0;
|
||||
for (let direction of [[-1, -1], [-1, 1], [1, 1], [1, -1]]) {
|
||||
for (let i = 0; i < dist; i++) {
|
||||
let cell = levelish.cell(sx, sy);
|
||||
if (cell) {
|
||||
yield cell;
|
||||
}
|
||||
sx += direction[0];
|
||||
sy += direction[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
25
js/game.js
25
js/game.js
@ -660,7 +660,9 @@ export class Level extends LevelInterface {
|
||||
|
||||
// Orange buttons do a really weird diamond search
|
||||
if (connectable.type.connect_order === 'diamond') {
|
||||
for (let cell of this.iter_cells_in_diamond(connectable.cell)) {
|
||||
for (let cell of algorithms.iter_cells_in_diamond(
|
||||
this, connectable.cell.x, connectable.cell.y))
|
||||
{
|
||||
let target = null;
|
||||
for (let tile of cell) {
|
||||
if (tile && goals.has(tile.type.name)) {
|
||||
@ -2355,27 +2357,6 @@ export class Level extends LevelInterface {
|
||||
}
|
||||
}
|
||||
|
||||
// Iterates over the grid in a diamond pattern, spreading out from the given start cell (but not
|
||||
// including it). Only used for connecting orange buttons.
|
||||
*iter_cells_in_diamond(start_cell) {
|
||||
let max_search_radius = Math.max(this.size_x, this.size_y) + 1;
|
||||
for (let dist = 1; dist <= max_search_radius; dist++) {
|
||||
// Start east and move counterclockwise
|
||||
let sx = start_cell.x + dist;
|
||||
let sy = start_cell.y;
|
||||
for (let direction of [[-1, -1], [-1, 1], [1, 1], [1, -1]]) {
|
||||
for (let i = 0; i < dist; i++) {
|
||||
let cell = this.cell(sx, sy);
|
||||
if (cell) {
|
||||
yield cell;
|
||||
}
|
||||
sx += direction[0];
|
||||
sy += direction[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME require_stub should really just care whether we ourselves /can/ contain wire, and also
|
||||
// we should check that on our neighbor
|
||||
is_tile_wired(tile, require_stub = true) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user