forked from SteamWar/SteamWar
Add CArea, RInteractionCallback
Add DynamicRegionEditor, DynamicRegionVisualizer
This commit is contained in:
+22
-14
@@ -56,12 +56,14 @@ public class DynamicRegionSystem implements RegionSystem {
|
||||
regionCache.clear();
|
||||
regionMap.put(region.getID(), region);
|
||||
regionTypeMap.computeIfAbsent(region.getType(), __ -> new HashSet<>()).add(region);
|
||||
DynamicRegionVisualizer.INSTANCE.addRegion(region);
|
||||
}
|
||||
|
||||
public void remove(DynamicRegion region) {
|
||||
regionCache.clear();
|
||||
regionMap.remove(region.getID());
|
||||
regionTypeMap.getOrDefault(region.getType(), Collections.emptySet()).remove(region);
|
||||
DynamicRegionVisualizer.INSTANCE.removeRegion(region);
|
||||
}
|
||||
|
||||
public static Map<Class<? extends DynamicRegion>, RegionConstructorData> constructorDataMap = new HashMap<>();
|
||||
@@ -197,31 +199,37 @@ public class DynamicRegionSystem implements RegionSystem {
|
||||
Set<Neighbour<Region>> neighbours = new HashSet<>();
|
||||
|
||||
if (!noCorners) {
|
||||
neighbours.add(new Neighbour<>(get(minTile.add(-1, -1).orElseThrow(), fastCache, regions), minTile, NeighbourDirection.NorthWest));
|
||||
neighbours.add(new Neighbour<>(get(minTile.add(-1, -1).orElse(null), fastCache, regions), minTile, NeighbourDirection.NorthWest));
|
||||
|
||||
Tile cornerMinMaxSelf = Tile.fromTile(minTile.getTileX(), maxTile.getTileZ()).orElseThrow();
|
||||
neighbours.add(new Neighbour<>(get(cornerMinMaxSelf.add(-1, 1).orElseThrow(), fastCache, regions), cornerMinMaxSelf, NeighbourDirection.SouthWest));
|
||||
Tile.fromTile(minTile.getTileX(), maxTile.getTileZ()).ifPresent(cornerMinMaxSelf -> {
|
||||
neighbours.add(new Neighbour<>(get(cornerMinMaxSelf.add(-1, 1).orElse(null), fastCache, regions), cornerMinMaxSelf, NeighbourDirection.SouthWest));
|
||||
});
|
||||
|
||||
Tile cornerMaxMinSelf = Tile.fromTile(maxTile.getTileX(), minTile.getTileZ()).orElseThrow();
|
||||
neighbours.add(new Neighbour<>(get(cornerMaxMinSelf.add(1, -1).orElseThrow(), fastCache, regions), cornerMaxMinSelf, NeighbourDirection.NorthEast));
|
||||
Tile.fromTile(maxTile.getTileX(), minTile.getTileZ()).ifPresent(cornerMaxMinSelf -> {
|
||||
neighbours.add(new Neighbour<>(get(cornerMaxMinSelf.add(1, -1).orElse(null), fastCache, regions), cornerMaxMinSelf, NeighbourDirection.NorthEast));
|
||||
});
|
||||
|
||||
neighbours.add(new Neighbour<>(get(maxTile.add(1, 1).orElseThrow(), fastCache, regions), maxTile, NeighbourDirection.SouthEast));
|
||||
neighbours.add(new Neighbour<>(get(maxTile.add(1, 1).orElse(null), fastCache, regions), maxTile, NeighbourDirection.SouthEast));
|
||||
}
|
||||
|
||||
for (int x = minTile.getTileX(); x <= maxTile.getTileX(); x++) {
|
||||
Tile tileMinZSelf = Tile.fromTile(x, minTile.getTileZ()).orElseThrow();
|
||||
neighbours.add(new Neighbour<>(get(tileMinZSelf.add(0, -1).orElseThrow(), fastCache, regions), tileMinZSelf, NeighbourDirection.North));
|
||||
Tile.fromTile(x, minTile.getTileZ()).ifPresent(tileMinZSelf -> {
|
||||
neighbours.add(new Neighbour<>(get(tileMinZSelf.add(0, -1).orElse(null), fastCache, regions), tileMinZSelf, NeighbourDirection.North));
|
||||
});
|
||||
|
||||
Tile tileMaxZSelf = Tile.fromTile(x, maxTile.getTileZ()).orElseThrow();
|
||||
neighbours.add(new Neighbour<>(get(tileMaxZSelf.add(0, 1).orElseThrow(), fastCache, regions), tileMaxZSelf, NeighbourDirection.South));
|
||||
Tile.fromTile(x, maxTile.getTileZ()).ifPresent(tileMaxZSelf -> {
|
||||
neighbours.add(new Neighbour<>(get(tileMaxZSelf.add(0, 1).orElse(null), fastCache, regions), tileMaxZSelf, NeighbourDirection.South));
|
||||
});
|
||||
}
|
||||
|
||||
for (int z = minTile.getTileZ(); z <= maxTile.getTileZ(); z++) {
|
||||
Tile tileMinXSelf = Tile.fromTile(minTile.getTileX(), z).orElseThrow();
|
||||
neighbours.add(new Neighbour<>(get(tileMinXSelf.add(-1, 0).orElseThrow(), fastCache, regions), tileMinXSelf, NeighbourDirection.West));
|
||||
Tile.fromTile(minTile.getTileX(), z).ifPresent(tileMinXSelf -> {
|
||||
neighbours.add(new Neighbour<>(get(tileMinXSelf.add(-1, 0).orElse(null), fastCache, regions), tileMinXSelf, NeighbourDirection.West));
|
||||
});
|
||||
|
||||
Tile tileMaxXSelf = Tile.fromTile(maxTile.getTileX(), z).orElseThrow();
|
||||
neighbours.add(new Neighbour<>(get(tileMaxXSelf.add(1, 0).orElseThrow(), fastCache, regions), tileMaxXSelf, NeighbourDirection.East));
|
||||
Tile.fromTile(maxTile.getTileX(), z).ifPresent(tileMaxXSelf -> {
|
||||
neighbours.add(new Neighbour<>(get(tileMaxXSelf.add(1, 0).orElse(null), fastCache, regions), tileMaxXSelf, NeighbourDirection.East));
|
||||
});
|
||||
}
|
||||
|
||||
neighbours.removeIf(neighbour -> neighbour.region.getType().isGlobal());
|
||||
|
||||
Reference in New Issue
Block a user