forked from SteamWar/SteamWar
Use VariantSelector
This commit is contained in:
+3
-2
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.region.dynamic.variants;
|
||||
package de.steamwar.bausystem.region.dynamic;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
@@ -52,8 +52,9 @@ public interface VariantSelector {
|
||||
|
||||
static VariantSelector StableVariants(@NonNull File directory) {
|
||||
File[] files = directory.listFiles();
|
||||
Random rand = new Random();
|
||||
return (minX, minZ) -> {
|
||||
Random rand = new Random(Objects.hash(minX, minZ));
|
||||
rand.setSeed(Objects.hash(minX, minZ));
|
||||
return Optional.of(files[rand.nextInt(files.length)]);
|
||||
};
|
||||
}
|
||||
+3
-2
@@ -22,6 +22,7 @@ package de.steamwar.bausystem.region.dynamic.normal;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.dynamic.VariantSelector;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@@ -30,7 +31,7 @@ import java.util.function.BiConsumer;
|
||||
|
||||
public abstract class NormalArea implements Region.Area {
|
||||
|
||||
public abstract NormalArea setResetFile(File resetFile);
|
||||
public abstract NormalArea setResetFile(VariantSelector variantSelector);
|
||||
|
||||
public static final NormalArea EMPTY = new NormalArea() {
|
||||
@Override
|
||||
@@ -64,7 +65,7 @@ public abstract class NormalArea implements Region.Area {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NormalArea setResetFile(File resetFile) {
|
||||
public NormalArea setResetFile(VariantSelector variantSelector) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+7
-6
@@ -23,6 +23,7 @@ import com.sk89q.worldedit.EditSession;
|
||||
import de.steamwar.bausystem.region.FlagStorage;
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.dynamic.VariantSelector;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import lombok.NonNull;
|
||||
@@ -39,21 +40,21 @@ public class WorkArea extends NormalArea {
|
||||
private final int widthX;
|
||||
private final int widthY;
|
||||
private final int widthZ;
|
||||
private File resetFile;
|
||||
private VariantSelector variantSelector;
|
||||
private final Point minPoint;
|
||||
private final Point maxPoint;
|
||||
private final Point copyPoint;
|
||||
private final boolean rotate;
|
||||
private final Region region;
|
||||
|
||||
public WorkArea(int minX, int minY, int minZ, int widthX, int widthY, int widthZ, File resetFile, boolean rotate, Region region) {
|
||||
public WorkArea(int minX, int minY, int minZ, int widthX, int widthY, int widthZ, VariantSelector variantSelector, boolean rotate, Region region) {
|
||||
this.minX = minX;
|
||||
this.minY = minY;
|
||||
this.minZ = minZ;
|
||||
this.widthX = widthX;
|
||||
this.widthY = widthY;
|
||||
this.widthZ = widthZ;
|
||||
this.resetFile = resetFile;
|
||||
this.variantSelector = variantSelector;
|
||||
this.rotate = rotate;
|
||||
this.region = region;
|
||||
|
||||
@@ -78,15 +79,15 @@ public class WorkArea extends NormalArea {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NormalArea setResetFile(File resetFile) {
|
||||
this.resetFile = resetFile;
|
||||
public NormalArea setResetFile(VariantSelector variantSelector) {
|
||||
this.variantSelector = variantSelector;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public File getResetFile() {
|
||||
return resetFile;
|
||||
return variantSelector.selectVariant(minX, minZ).orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-4
@@ -25,13 +25,12 @@ import de.steamwar.bausystem.region.RegionHistory;
|
||||
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionConstructorData;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionDataRepository;
|
||||
import de.steamwar.bausystem.region.dynamic.VariantSelector;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.TestblockMode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public abstract class WorkRegion extends DynamicRegion {
|
||||
|
||||
@Getter
|
||||
@@ -42,8 +41,8 @@ public abstract class WorkRegion extends DynamicRegion {
|
||||
protected NormalArea northArea = NormalArea.EMPTY;
|
||||
protected NormalArea southArea = NormalArea.EMPTY;
|
||||
|
||||
protected File frame;
|
||||
protected File testblock;
|
||||
protected VariantSelector frame;
|
||||
protected VariantSelector testblock;
|
||||
|
||||
@Getter
|
||||
private final RegionHistory history = new RegionHistory.Impl(20);
|
||||
|
||||
+7
-6
@@ -22,6 +22,7 @@ package de.steamwar.bausystem.region.dynamic.normal.work;
|
||||
import de.steamwar.bausystem.region.GameModeConfig;
|
||||
import de.steamwar.bausystem.region.RegionType;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionConstructorData;
|
||||
import de.steamwar.bausystem.region.dynamic.VariantSelector;
|
||||
import de.steamwar.bausystem.region.dynamic.normal.WorkArea;
|
||||
import de.steamwar.bausystem.region.dynamic.normal.WorkRegion;
|
||||
import lombok.Getter;
|
||||
@@ -45,20 +46,20 @@ public class MicroWarGear21WorkRegion extends WorkRegion {
|
||||
|
||||
public MicroWarGear21WorkRegion(int minX, int minZ) {
|
||||
super(minX, minZ);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, REGION_FILE, false, this);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, VariantSelector.File(REGION_FILE), false, this);
|
||||
northArea = new WorkArea(minX + 25, 32, minZ + 25, 7, 7, 7, null, false, this);
|
||||
southArea = new WorkArea(minX + 25, 32, minZ + 82, 7, 7, 7, null, true, this);
|
||||
frame = FRAME_FILE;
|
||||
testblock = TESTBLOCK_FILE;
|
||||
frame = VariantSelector.File(FRAME_FILE);
|
||||
testblock = VariantSelector.File(TESTBLOCK_FILE);
|
||||
}
|
||||
|
||||
public MicroWarGear21WorkRegion(RegionConstructorData regionConstructorData) {
|
||||
super(regionConstructorData);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, REGION_FILE, false, this);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, VariantSelector.File(REGION_FILE), false, this);
|
||||
northArea = new WorkArea(minX + 25, 32, minZ + 25, 7, 7, 7, null, false, this);
|
||||
southArea = new WorkArea(minX + 25, 32, minZ + 82, 7, 7, 7, null, true, this);
|
||||
frame = FRAME_FILE;
|
||||
testblock = TESTBLOCK_FILE;
|
||||
frame = VariantSelector.File(FRAME_FILE);
|
||||
testblock = VariantSelector.File(TESTBLOCK_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-6
@@ -22,6 +22,7 @@ package de.steamwar.bausystem.region.dynamic.normal.work;
|
||||
import de.steamwar.bausystem.region.GameModeConfig;
|
||||
import de.steamwar.bausystem.region.RegionType;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionConstructorData;
|
||||
import de.steamwar.bausystem.region.dynamic.VariantSelector;
|
||||
import de.steamwar.bausystem.region.dynamic.normal.WorkArea;
|
||||
import de.steamwar.bausystem.region.dynamic.normal.WorkRegion;
|
||||
import lombok.Getter;
|
||||
@@ -45,20 +46,20 @@ public class MiniWarGear21WorkRegion extends WorkRegion {
|
||||
|
||||
public MiniWarGear21WorkRegion(int minX, int minZ) {
|
||||
super(minX, minZ);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, REGION_FILE, false, this);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, VariantSelector.File(REGION_FILE), false, this);
|
||||
northArea = new WorkArea(minX + 29, 32, minZ + 29, 37, 26, 22, null, false, this);
|
||||
southArea = new WorkArea(minX + 29, 32, minZ + 101, 37, 26, 22, null, true, this);
|
||||
frame = FRAME_FILE;
|
||||
testblock = TESTBLOCK_FILE;
|
||||
frame = VariantSelector.File(FRAME_FILE);
|
||||
testblock = VariantSelector.File(TESTBLOCK_FILE);
|
||||
}
|
||||
|
||||
public MiniWarGear21WorkRegion(RegionConstructorData regionConstructorData) {
|
||||
super(regionConstructorData);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, REGION_FILE, false, this);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, VariantSelector.File(REGION_FILE), false, this);
|
||||
northArea = new WorkArea(minX + 29, 32, minZ + 29, 37, 26, 22, null, false, this);
|
||||
southArea = new WorkArea(minX + 29, 32, minZ + 101, 37, 26, 22, null, true, this);
|
||||
frame = FRAME_FILE;
|
||||
testblock = TESTBLOCK_FILE;
|
||||
frame = VariantSelector.File(FRAME_FILE);
|
||||
testblock = VariantSelector.File(TESTBLOCK_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-6
@@ -22,6 +22,7 @@ package de.steamwar.bausystem.region.dynamic.normal.work;
|
||||
import de.steamwar.bausystem.region.GameModeConfig;
|
||||
import de.steamwar.bausystem.region.RegionType;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionConstructorData;
|
||||
import de.steamwar.bausystem.region.dynamic.VariantSelector;
|
||||
import de.steamwar.bausystem.region.dynamic.normal.WorkArea;
|
||||
import de.steamwar.bausystem.region.dynamic.normal.WorkRegion;
|
||||
import lombok.Getter;
|
||||
@@ -45,20 +46,20 @@ public class WarGear21WorkRegion extends WorkRegion {
|
||||
|
||||
public WarGear21WorkRegion(int minX, int minZ) {
|
||||
super(minX, minZ);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, REGION_FILE, false, this);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, VariantSelector.File(REGION_FILE), false, this);
|
||||
northArea = new WorkArea(minX + 33, 32, minZ + 42, 67, 41, 47, null, false, this);
|
||||
southArea = new WorkArea(minX + 33, 32, minZ + 139, 67, 41, 47, null, true, this);
|
||||
frame = FRAME_FILE;
|
||||
testblock = TESTBLOCK_FILE;
|
||||
frame = VariantSelector.File(FRAME_FILE);
|
||||
testblock = VariantSelector.File(TESTBLOCK_FILE);
|
||||
}
|
||||
|
||||
public WarGear21WorkRegion(RegionConstructorData regionConstructorData) {
|
||||
super(regionConstructorData);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, REGION_FILE, false, this);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, VariantSelector.File(REGION_FILE), false, this);
|
||||
northArea = new WorkArea(minX + 33, 32, minZ + 42, 67, 41, 47, null, false, this);
|
||||
southArea = new WorkArea(minX + 33, 32, minZ + 139, 67, 41, 47, null, true, this);
|
||||
frame = FRAME_FILE;
|
||||
testblock = TESTBLOCK_FILE;
|
||||
frame = VariantSelector.File(FRAME_FILE);
|
||||
testblock = VariantSelector.File(TESTBLOCK_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-6
@@ -22,6 +22,7 @@ package de.steamwar.bausystem.region.dynamic.normal.work;
|
||||
import de.steamwar.bausystem.region.GameModeConfig;
|
||||
import de.steamwar.bausystem.region.RegionType;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionConstructorData;
|
||||
import de.steamwar.bausystem.region.dynamic.VariantSelector;
|
||||
import de.steamwar.bausystem.region.dynamic.normal.WorkArea;
|
||||
import de.steamwar.bausystem.region.dynamic.normal.WorkRegion;
|
||||
import lombok.Getter;
|
||||
@@ -45,20 +46,20 @@ public class WarShip21WorkRegion extends WorkRegion {
|
||||
|
||||
public WarShip21WorkRegion(int minX, int minZ) {
|
||||
super(minX, minZ);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, REGION_FILE, false, this);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, VariantSelector.File(REGION_FILE), false, this);
|
||||
// northArea = new WorkArea(minX + 33, 32, minZ + 42, 67, 41, 47, null, false, this);
|
||||
// southArea = new WorkArea(minX + 33, 32, minZ + 139, 67, 41, 47, null, true, this);
|
||||
frame = FRAME_FILE;
|
||||
testblock = TESTBLOCK_FILE;
|
||||
frame = VariantSelector.File(FRAME_FILE);
|
||||
testblock = VariantSelector.File(TESTBLOCK_FILE);
|
||||
}
|
||||
|
||||
public WarShip21WorkRegion(RegionConstructorData regionConstructorData) {
|
||||
super(regionConstructorData);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, REGION_FILE, false, this);
|
||||
area = new WorkArea(minX, 0, minZ, widthX, 255, widthZ, VariantSelector.File(REGION_FILE), false, this);
|
||||
// northArea = new WorkArea(minX + 33, 32, minZ + 42, 67, 41, 47, null, false, this);
|
||||
// southArea = new WorkArea(minX + 33, 32, minZ + 139, 67, 41, 47, null, true, this);
|
||||
frame = FRAME_FILE;
|
||||
testblock = TESTBLOCK_FILE;
|
||||
frame = VariantSelector.File(FRAME_FILE);
|
||||
testblock = VariantSelector.File(TESTBLOCK_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class PathAreaTile implements Region.Area {
|
||||
public class PathAreaTile implements Region.Area { // TODO: Change to VariantSelector
|
||||
|
||||
private static final File PATH_DIR = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections/path");
|
||||
private static final File PATH_CENTER = new File(PATH_DIR, "PathCenter.schem");
|
||||
|
||||
+3
-6
@@ -23,10 +23,7 @@ import de.steamwar.bausystem.region.FlagStorage;
|
||||
import de.steamwar.bausystem.region.GameModeConfig;
|
||||
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.NonNormalFlagStorage;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionConstructorData;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionDataRepository;
|
||||
import de.steamwar.bausystem.region.dynamic.*;
|
||||
import de.steamwar.bausystem.region.dynamic.spawn.SpawnAreaTile;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -46,7 +43,7 @@ public class PathRegion extends DynamicRegion {
|
||||
super(minX, minZ);
|
||||
RegionDataRepository.loadFlagStorage(this, flagStorage);
|
||||
if (minX >= -28 && minX <= 10 && minZ >= -28 && minZ <= 10) {
|
||||
area = new SpawnAreaTile(minX, minZ, RESET_FILE, this);
|
||||
area = new SpawnAreaTile(minX, minZ, VariantSelector.File(RESET_FILE), this);
|
||||
} else {
|
||||
area = new PathAreaTile(minX, minZ, this);
|
||||
}
|
||||
@@ -56,7 +53,7 @@ public class PathRegion extends DynamicRegion {
|
||||
super(regionConstructorData);
|
||||
RegionDataRepository.loadFlagStorage(this, flagStorage);
|
||||
if (minX >= -28 && minX <= 10 && minZ >= -28 && minZ <= 10) {
|
||||
area = new SpawnAreaTile(minX, minZ, RESET_FILE, this);
|
||||
area = new SpawnAreaTile(minX, minZ, VariantSelector.File(RESET_FILE), this);
|
||||
} else {
|
||||
area = new PathAreaTile(minX, minZ, this);
|
||||
}
|
||||
|
||||
+5
-4
@@ -21,6 +21,7 @@ package de.steamwar.bausystem.region.dynamic.spawn;
|
||||
|
||||
import de.steamwar.bausystem.region.Point;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.dynamic.VariantSelector;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import lombok.NonNull;
|
||||
|
||||
@@ -31,16 +32,16 @@ public class SpawnAreaTile implements Region.Area {
|
||||
|
||||
private final int minX;
|
||||
private final int minZ;
|
||||
private final File resetFile;
|
||||
private final VariantSelector variantSelector;
|
||||
private final Point minPoint;
|
||||
private final Point maxPoint;
|
||||
private final Point copyPoint;
|
||||
private final Region region;
|
||||
|
||||
public SpawnAreaTile(int minX, int minZ, File resetFile, Region region) {
|
||||
public SpawnAreaTile(int minX, int minZ, VariantSelector variantSelector, Region region) {
|
||||
this.minX = minX;
|
||||
this.minZ = minZ;
|
||||
this.resetFile = resetFile;
|
||||
this.variantSelector = variantSelector;
|
||||
|
||||
minPoint = new Point(minX, 0, minZ);
|
||||
maxPoint = new Point(minX + 18, 255, minZ + 18);
|
||||
@@ -67,7 +68,7 @@ public class SpawnAreaTile implements Region.Area {
|
||||
@Nullable
|
||||
@Override
|
||||
public File getResetFile() {
|
||||
return resetFile;
|
||||
return variantSelector.selectVariant(minX, minZ).orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+10
-10
@@ -19,11 +19,11 @@
|
||||
|
||||
package de.steamwar.bausystem.region.dynamic.spawn;
|
||||
|
||||
import de.steamwar.bausystem.region.*;
|
||||
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
|
||||
import de.steamwar.bausystem.region.dynamic.NonNormalFlagStorage;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionConstructorData;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionDataRepository;
|
||||
import de.steamwar.bausystem.region.FlagStorage;
|
||||
import de.steamwar.bausystem.region.GameModeConfig;
|
||||
import de.steamwar.bausystem.region.RegionHistory;
|
||||
import de.steamwar.bausystem.region.RegionType;
|
||||
import de.steamwar.bausystem.region.dynamic.*;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@@ -53,15 +53,15 @@ public class SpawnPathRegion extends DynamicRegion {
|
||||
area = new SpawnAreaTile(minX, minZ, getResetFile(minX, minZ), this);
|
||||
}
|
||||
|
||||
private static File getResetFile(int minX, int minZ) {
|
||||
private static VariantSelector getResetFile(int minX, int minZ) {
|
||||
if (minX == -28) {
|
||||
return RESET_FILE_WEST;
|
||||
return VariantSelector.File(RESET_FILE_WEST);
|
||||
} else if (minX == 10) {
|
||||
return RESET_FILE_EAST;
|
||||
return VariantSelector.File(RESET_FILE_EAST);
|
||||
} else if (minZ == -28) {
|
||||
return RESET_FILE_NORTH;
|
||||
return VariantSelector.File(RESET_FILE_NORTH);
|
||||
} else if (minZ == 10) {
|
||||
return RESET_FILE_SOUTH;
|
||||
return VariantSelector.File(RESET_FILE_SOUTH);
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid minX: " + minX + ", minZ: " + minZ);
|
||||
}
|
||||
|
||||
+3
-6
@@ -23,10 +23,7 @@ import de.steamwar.bausystem.region.FlagStorage;
|
||||
import de.steamwar.bausystem.region.GameModeConfig;
|
||||
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.NonNormalFlagStorage;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionConstructorData;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionDataRepository;
|
||||
import de.steamwar.bausystem.region.dynamic.*;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@@ -44,13 +41,13 @@ public class SpawnRegion extends DynamicRegion {
|
||||
public SpawnRegion(int minX, int minZ) {
|
||||
super(minX, minZ);
|
||||
RegionDataRepository.loadFlagStorage(this, flagStorage);
|
||||
area = new SpawnAreaTile(minX, minZ, RESET_FILE, this);
|
||||
area = new SpawnAreaTile(minX, minZ, VariantSelector.File(RESET_FILE), this);
|
||||
}
|
||||
|
||||
public SpawnRegion(RegionConstructorData regionConstructorData) {
|
||||
super(regionConstructorData);
|
||||
RegionDataRepository.loadFlagStorage(this, flagStorage);
|
||||
area = new SpawnAreaTile(minX, minZ, RESET_FILE, this);
|
||||
area = new SpawnAreaTile(minX, minZ, VariantSelector.File(RESET_FILE), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user