part of 'generator.dart'; class Vaults { final List _primitive = []; List randomFlight(math.Random rng) { // TODO: There are many more efficient ways to do this! List list2 = []; list2.addAll(_primitive); list2.shuffle(rng); return list2; } static Future load(String name) async { var basis = await Bitmap.load(name, colorToVaultTile); var regions = regionalize(basis.rect, (x, y) => basis.get(x, y) != null); var vs = Vaults(); for (var region in regions) { Vault v = loadVault(region, basis); vs._primitive.add(v); } return vs; } static Vault loadVault(Region r, Bitmap b) { skreek("Loading vault: $r"); var tiles = [ for (var y = r.rect.top; y < r.rect.bottom; y++) for (var x = r.rect.left; x < r.rect.right; x++) r.points.contains((x, y)) ? (b.get(x, y) ?? VaultTile.wall) : VaultTile.wall ]; DirectionSet smooth = DirectionSet( {Direction.up, Direction.left, Direction.right, Direction.down}); for (var x = r.rect.left; x < r.rect.right; x++) { if (b.get(x, r.rect.top) == null) { smooth.directions.remove(Direction.up); break; } } for (var x = r.rect.left; x < r.rect.right; x++) { if (b.get(x, r.rect.bottom - 1) == null) { smooth.directions.remove(Direction.down); break; } } for (var y = r.rect.top; y < r.rect.bottom; y++) { if (b.get(r.rect.left, y) == null) { smooth.directions.remove(Direction.left); break; } } for (var y = r.rect.top; y < r.rect.bottom; y++) { if (b.get(r.rect.right - 1, y) == null) { smooth.directions.remove(Direction.right); break; } } return Vault(r.rect.width, r.rect.height, smooth, tiles); } } enum VaultTile { exit, door, bspfloor, floor, wall, } VaultTile? colorToVaultTile(int c) { switch (c) { // RGBA case 0x000000FF: case 0x707070FF: return VaultTile.wall; case 0xFFFFFFFF: case 0xFFFF00FF: case 0xFF00FFFF: return VaultTile.floor; case 0x0087FFFF: return VaultTile.door; case 0xFF0000FF: return VaultTile.exit; case 0x007F00FF: return null; default: throw Exception("unrecognized pixel: $c"); } }