part of 'generator.dart'; class Vault { final int vx, vy; final DirectionSet smooth; final List tiles; Vault(this.vx, this.vy, this.smooth, this.tiles) { assert(tiles.length == vx * vy); } // TODO: We should be assessing this based on whether the pattern in the input // PNG had right-angled borders on this side, not based on the literal // presence or absence of walls // // In other words, this is wrong. static Vault fromVaultData(int vx, int vy, List tiles) { assert(tiles.length == vx * vy); var smooth = { Direction.up, Direction.left, Direction.down, Direction.right }; for (var x = 0; x < vx; x++) { if (tiles[x + 0 * vx] == VaultTile.wall) { smooth.remove(Direction.up); break; } } for (var x = 0; x < vx; x++) { if (tiles[x + (vy - 1) * vx] == VaultTile.wall) { smooth.remove(Direction.down); break; } } for (var y = 0; y < vy; y++) { if (tiles[0 + y * vx] == VaultTile.wall) { smooth.remove(Direction.left); break; } } for (var y = 0; y < vy; y++) { if (tiles[vx - 1 + y * vx] == VaultTile.wall) { smooth.remove(Direction.right); break; } } return Vault(vx, vy, DirectionSet(smooth), tiles); } void clear(VaultTile lt) { for (var y = 0; y < vy; y++) { for (var x = 0; x < vx; x++) { tiles[y * vx + x] = lt; } } } void blitFrom(Vault other, int dx, int dy) { assert(dx >= 0); assert(dy >= 0); assert(dx + other.vx <= vx); assert(dy + other.vy <= vy); for (var x = 0; x < other.vx; x++) { for (var y = 0; y < other.vy; y++) { tiles[(y + dy) * vx + x + dx] = other.tiles[y * other.vx + x]; } } } Vault flip() { List tiles2 = [ for (var y = 0; y < vy; y++) for (var x = vx - 1; x >= 0; x--) tiles[y * vx + x] ]; return Vault(vx, vy, smooth.flip(), tiles2); } // TODO: Actually test this logic. // This worked in Python, so it might even be right! Vault rotateRight() { List tiles2 = [ for (var x = 0; x < vx; x++) for (var y = 0; y < vy; y++) tiles[(vy - 1 - y) * vx + x] ]; return Vault(vy, vx, smooth.rotateRight(), tiles2); } Vault rotateLeft() { List tiles2 = [ for (var x = vx - 1; x >= 0; x++) for (var y = vy - 1; y >= 0; y++) tiles[y * vx + (vx - 1 - x)] ]; return Vault(vy, vx, smooth.rotateLeft(), tiles2); } static Vault blank(int vx, int vy, DirectionSet smooth, VaultTile lt) { var tiles = [ for (var y = 0; y < vy; y++) for (var x = 0; x < vx; x++) lt ]; return Vault(vx, vy, smooth, tiles); } }