118 lines
2.9 KiB
Dart
118 lines
2.9 KiB
Dart
part of 'generator.dart';
|
|
|
|
class Vaults {
|
|
final List<Vault> _primitive = [];
|
|
|
|
List<Vault> randomFlight(math.Random rng) {
|
|
// TODO: There are many more efficient ways to do this!
|
|
List<Vault> list2 = [];
|
|
list2.addAll(_primitive);
|
|
list2.shuffle(rng);
|
|
return list2;
|
|
}
|
|
|
|
static Future<Vaults> 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<VaultTile?> b) {
|
|
skreek("Loading vault: $r");
|
|
var tiles = [
|
|
for (var y = r.rect.y0; y < r.rect.y1; y++)
|
|
for (var x = r.rect.x0; x < r.rect.x1; 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.x0; x < r.rect.x1; x++) {
|
|
if (b.get(x, r.rect.y0) == null) {
|
|
smooth.directions.remove(Direction.up);
|
|
break;
|
|
}
|
|
}
|
|
for (var x = r.rect.x0; x < r.rect.x1; x++) {
|
|
if (b.get(x, r.rect.y1 - 1) == null) {
|
|
smooth.directions.remove(Direction.down);
|
|
break;
|
|
}
|
|
}
|
|
for (var y = r.rect.y0; y < r.rect.y1; y++) {
|
|
if (b.get(r.rect.x0, y) == null) {
|
|
smooth.directions.remove(Direction.left);
|
|
break;
|
|
}
|
|
}
|
|
for (var y = r.rect.y0; y < r.rect.y1; y++) {
|
|
if (b.get(r.rect.x1 - 1, y) == null) {
|
|
smooth.directions.remove(Direction.right);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return Vault(Bitmap(r.rect.size, tiles), smooth);
|
|
}
|
|
}
|
|
|
|
enum VaultTile {
|
|
meta0,
|
|
|
|
exit,
|
|
door,
|
|
bspfloor,
|
|
floor,
|
|
doorpronefloor,
|
|
|
|
defaultwall, // defaultwall is in generated rooms and is overwritten by anything
|
|
archpronewall, // archpronewall cannot overwrite wall or archwall
|
|
archwall, // archwall cannot overwrite wall.
|
|
wall,
|
|
}
|
|
|
|
VaultTile? colorToVaultTile(int c) {
|
|
switch (c ~/ 256) {
|
|
// RGB (originally rgba)
|
|
// == spacers ==
|
|
case 0x007F00: // deep green
|
|
return null; // separates vaults
|
|
|
|
// == metasyntax ==
|
|
case 0x00FF00: // green
|
|
return VaultTile.meta0; // call back into BSP
|
|
|
|
// == level elements ==
|
|
case 0x000000:
|
|
case 0x707070:
|
|
return VaultTile.wall;
|
|
case 0xFF8000:
|
|
return VaultTile.archwall;
|
|
case 0x7F4000:
|
|
return VaultTile.archpronewall;
|
|
case 0xBCCFFF:
|
|
return VaultTile.doorpronefloor;
|
|
case 0xFFFFFF:
|
|
case 0xFFFF00:
|
|
case 0xFF00FF:
|
|
return VaultTile.floor;
|
|
case 0x0087FF:
|
|
return VaultTile.door;
|
|
case 0xFF0000:
|
|
return VaultTile.exit;
|
|
default:
|
|
throw Exception("unrecognized pixel: $c");
|
|
}
|
|
}
|