Add Garden handling for PathRegion
This commit is contained in:
@@ -70,5 +70,6 @@ public enum RegionType {
|
||||
Path,
|
||||
Water,
|
||||
Global,
|
||||
Garden,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,7 @@ import java.io.File;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static de.steamwar.bausystem.region.RegionType.ConnectionType.Global;
|
||||
import static de.steamwar.bausystem.region.RegionType.ConnectionType.Path;
|
||||
import static de.steamwar.bausystem.region.RegionType.ConnectionType.*;
|
||||
|
||||
public class PathArea implements Region.Area {
|
||||
|
||||
@@ -54,6 +53,7 @@ public class PathArea implements Region.Area {
|
||||
.Case(Global, SIDE_GLOBAL);
|
||||
|
||||
private static final SelectorCorner SELECTOR_CORNER = new SelectorCorner()
|
||||
// Path to Global!
|
||||
.Case(Path, Global, Global, SIDE_GLOBAL, RotationCorrection.WithCorrection)
|
||||
.Case(Global, Path, Path, SIDE_GLOBAL)
|
||||
.Case(Global, Path, Global, SIDE_GLOBAL)
|
||||
@@ -101,6 +101,7 @@ public class PathArea implements Region.Area {
|
||||
UsingOrdinal,
|
||||
}
|
||||
|
||||
private final PathRegion region;
|
||||
private final UUID regionIdentifier;
|
||||
private final Tile tile;
|
||||
private final Point minPoint;
|
||||
@@ -108,6 +109,7 @@ public class PathArea implements Region.Area {
|
||||
private final Point copyPoint;
|
||||
|
||||
public PathArea(Tile tile, PathRegion region) {
|
||||
this.region = region;
|
||||
this.regionIdentifier = region.getID();
|
||||
this.tile = tile;
|
||||
|
||||
@@ -138,7 +140,7 @@ public class PathArea implements Region.Area {
|
||||
|
||||
@Override
|
||||
public void reset(PasteBuilder pasteBuilder, boolean extension) {
|
||||
if (isGarden()) {
|
||||
if (region.isGarden()) {
|
||||
// TODO: Implement Garden case!
|
||||
}
|
||||
|
||||
@@ -182,28 +184,19 @@ public class PathArea implements Region.Area {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isGarden() {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
if (x == 0 && z == 0) continue;
|
||||
Tile tile = this.tile.add(x, z).orElse(null);
|
||||
if (tile == null) {
|
||||
return false;
|
||||
}
|
||||
if (!DynamicRegionSystem.INSTANCE.get(tile).getType().isPath()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static RegionType.ConnectionType getConnectionType(Tile tile, Side side, Side optionalSide) {
|
||||
Optional<Tile> optionalTile = tile.add(side.tileOffsetX, side.tileOffsetZ);
|
||||
if (optionalSide != null) {
|
||||
optionalTile = optionalTile.flatMap(t -> t.add(optionalSide.tileOffsetX, optionalSide.tileOffsetZ));
|
||||
}
|
||||
return optionalTile.map(t -> DynamicRegionSystem.INSTANCE.get(t.getCenterLocation()).getType().getConnectionType())
|
||||
.orElse(RegionType.ConnectionType.Global);
|
||||
if (optionalTile.isEmpty()) {
|
||||
return RegionType.ConnectionType.Global;
|
||||
}
|
||||
tile = optionalTile.get();
|
||||
Region region = DynamicRegionSystem.INSTANCE.get(tile.getCenterLocation());
|
||||
if (region instanceof PathRegion pathRegion) {
|
||||
return pathRegion.isGarden() ? Garden : Path;
|
||||
}
|
||||
return region.getType().getConnectionType();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.region.dynamic.path;
|
||||
|
||||
import de.steamwar.bausystem.region.RegionBackups;
|
||||
import de.steamwar.bausystem.region.RegionData;
|
||||
import de.steamwar.bausystem.region.RegionHistory;
|
||||
import de.steamwar.bausystem.region.RegionType;
|
||||
import de.steamwar.bausystem.region.*;
|
||||
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
|
||||
import de.steamwar.bausystem.region.dynamic.DynamicRegionRepository;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionConstructorData;
|
||||
@@ -41,6 +38,7 @@ import java.util.UUID;
|
||||
public class PathRegion extends DynamicRegion {
|
||||
|
||||
private PathArea area;
|
||||
private Tile tile;
|
||||
|
||||
public PathRegion(UUID id, int minX, int minZ) {
|
||||
super(id, minX, minZ);
|
||||
@@ -48,16 +46,41 @@ public class PathRegion extends DynamicRegion {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
area = new PathArea(Tile.fromXZ(minX, minZ).orElseThrow(), this);
|
||||
tile = Tile.fromXZ(minX, minZ).orElseThrow();
|
||||
area = new PathArea(tile, this);
|
||||
regionData = new PathRegionData(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(DynamicRegion updateFrom) {
|
||||
gardenCache = null;
|
||||
// TODO: Improve
|
||||
area.reset(null, false);
|
||||
}
|
||||
|
||||
private Boolean gardenCache = null;
|
||||
|
||||
public boolean isGarden() {
|
||||
if (gardenCache == null) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
if (x == 0 && z == 0) continue;
|
||||
Tile t = tile.add(x, z).orElse(null);
|
||||
if (t == null) {
|
||||
gardenCache = false;
|
||||
return false;
|
||||
}
|
||||
if (!DynamicRegionSystem.INSTANCE.get(t).getType().isPath()) {
|
||||
gardenCache = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
gardenCache = true;
|
||||
}
|
||||
return gardenCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull RegionType getType() {
|
||||
return RegionType.PATH;
|
||||
|
||||
@@ -31,8 +31,8 @@ class SelectorCorner {
|
||||
|
||||
static {
|
||||
int values = RegionType.ConnectionType.values().length;
|
||||
BITS = (int) (Math.log(values) / Math.log(2));
|
||||
SELECTOR_COUNT = (int) Math.pow(2, BITS * 3);
|
||||
BITS = (int) Math.ceil(Math.log(values) / Math.log(2));
|
||||
SELECTOR_COUNT = (int) Math.pow(2, BITS * 3D);
|
||||
}
|
||||
|
||||
private VariantSelector[] selectors = new VariantSelector[SELECTOR_COUNT];
|
||||
|
||||
Reference in New Issue
Block a user