Commit vor dem Urlaub
This commit is contained in:
@@ -74,6 +74,69 @@ public final class VoxelChunkIO {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Pre-Bake-Backups ──────────────────────────────────────────────────────
|
||||
|
||||
/** Backup-Pfad der .blvc-Datei (wird vor dem Bake angelegt). */
|
||||
public static Path getPreBakePath(int cx, int cy, int cz) {
|
||||
return getPath(cx, cy, cz).resolveSibling(
|
||||
getPath(cx, cy, cz).getFileName() + ".prebake");
|
||||
}
|
||||
|
||||
public static boolean preBakeExists(int cx, int cy, int cz) {
|
||||
return Files.exists(getPreBakePath(cx, cy, cz));
|
||||
}
|
||||
|
||||
/** Kopiert die aktuelle .blvc-Datei als Pre-Bake-Backup. */
|
||||
public static void savePreBake(int cx, int cy, int cz) throws IOException {
|
||||
Path src = getPath(cx, cy, cz);
|
||||
if (!Files.exists(src)) return;
|
||||
Files.copy(src, getPreBakePath(cx, cy, cz), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
public static void deletePreBake(int cx, int cy, int cz) throws IOException {
|
||||
Files.deleteIfExists(getPreBakePath(cx, cy, cz));
|
||||
}
|
||||
|
||||
/** Stellt die .blvc-Datei aus dem Backup wieder her. */
|
||||
public static void restorePreBake(int cx, int cy, int cz) throws IOException {
|
||||
Path backup = getPreBakePath(cx, cy, cz);
|
||||
if (!Files.exists(backup)) return;
|
||||
Files.copy(backup, getPath(cx, cy, cz), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
/** true wenn mindestens ein Pre-Bake-Backup im Chunks-Verzeichnis existiert. */
|
||||
public static boolean hasAnyPreBake() {
|
||||
Path dir = ChunkTerrainIO.chunksDir();
|
||||
if (!Files.isDirectory(dir)) return false;
|
||||
try (DirectoryStream<Path> ds = Files.newDirectoryStream(dir, "voxel_*.blvc.prebake")) {
|
||||
return ds.iterator().hasNext();
|
||||
} catch (IOException e) { return false; }
|
||||
}
|
||||
|
||||
/** Alle Chunk-Koordinaten für die ein Pre-Bake-Backup existiert. */
|
||||
public static List<int[]> listPreBakeCoords() {
|
||||
List<int[]> result = new java.util.ArrayList<>();
|
||||
Path dir = ChunkTerrainIO.chunksDir();
|
||||
if (!Files.isDirectory(dir)) return result;
|
||||
try (DirectoryStream<Path> ds = Files.newDirectoryStream(dir, "voxel_*.blvc.prebake")) {
|
||||
for (Path p : ds) {
|
||||
String name = p.getFileName().toString()
|
||||
.replace("voxel_", "").replace(".blvc.prebake", "");
|
||||
String[] parts = name.split("_");
|
||||
if (parts.length != 3) continue;
|
||||
try {
|
||||
int cx = Integer.parseInt(parts[0]);
|
||||
int cy = parts[1].startsWith("m")
|
||||
? -Integer.parseInt(parts[1].substring(1))
|
||||
: Integer.parseInt(parts[1]);
|
||||
int cz = Integer.parseInt(parts[2]);
|
||||
result.add(new int[]{cx, cy, cz});
|
||||
} catch (NumberFormatException ignored) {}
|
||||
}
|
||||
} catch (IOException ignored) {}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liest alle vorhandenen VoxelChunks aus dem Chunks-Verzeichnis.
|
||||
* Gibt leere Liste zurück wenn kein Chunks-Verzeichnis existiert.
|
||||
|
||||
Reference in New Issue
Block a user