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