Weiter daran gearbeitet, die welt aus dem editor ins game zu bringen
This commit is contained in:
@@ -8,9 +8,12 @@ plugins {
|
||||
group = 'de.blight'
|
||||
version = '0.1.0'
|
||||
|
||||
// Explizite Toolchain für standalone-Import (Eclipse ohne Root-Build).
|
||||
// Im Full-Build wird dies durch die Root-Konfiguration überschrieben.
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.zip.*;
|
||||
/**
|
||||
* Liest und schreibt {@link MapData} als komprimierte Binärdatei.
|
||||
*
|
||||
* Speicherort: {@code world/blight_map.blm} relativ zum Arbeitsverzeichnis.
|
||||
* Speicherort: {@code blight-map/src/main/map/blight_map.blm} relativ zum Arbeitsverzeichnis.
|
||||
* Beide Projekte setzen {@code workingDir = rootDir} im Gradle-Run-Task,
|
||||
* zeigen also auf dasselbe Verzeichnis.
|
||||
*
|
||||
@@ -19,7 +19,32 @@ import java.util.zip.*;
|
||||
*/
|
||||
public final class MapIO {
|
||||
|
||||
private static final Path MAP_PATH = Paths.get("world", "blight_map.blm");
|
||||
private static final Path PROJECT_ROOT = findProjectRoot();
|
||||
private static final Path MAP_PATH = PROJECT_ROOT.resolve(
|
||||
Paths.get("blight-map", "src", "main", "map", "blight_map.blm"));
|
||||
private static final Path MAP_PATH_OLD = PROJECT_ROOT.resolve(
|
||||
Paths.get("world", "blight_map.blm"));
|
||||
|
||||
/**
|
||||
* Ermittelt den Projekt-Root einmalig beim Classload:
|
||||
* 1. System-Property {@code blight.project.root} (vom Editor-Subprocess gesetzt)
|
||||
* 2. Aufwärtssuche im Verzeichnisbaum nach {@code gradlew}
|
||||
* 3. Fallback: aktuelles Arbeitsverzeichnis
|
||||
*/
|
||||
private static Path findProjectRoot() {
|
||||
String prop = System.getProperty("blight.project.root");
|
||||
if (prop != null) return Paths.get(prop);
|
||||
|
||||
// blight-editor/ UND blight-game/ als Kinder → eindeutig der echte Root
|
||||
File dir = Paths.get(".").toAbsolutePath().normalize().toFile();
|
||||
while (dir != null) {
|
||||
if (new File(dir, "blight-editor").isDirectory()
|
||||
&& new File(dir, "blight-game").isDirectory())
|
||||
return dir.toPath();
|
||||
dir = dir.getParentFile();
|
||||
}
|
||||
return Paths.get(".").toAbsolutePath().normalize();
|
||||
}
|
||||
|
||||
private static final int MAGIC = 0x424C4947; // "BLIG"
|
||||
private static final int VERSION = 3;
|
||||
@@ -29,7 +54,20 @@ public final class MapIO {
|
||||
// ── Public API ────────────────────────────────────────────────────────────
|
||||
|
||||
public static boolean exists() {
|
||||
return Files.exists(MAP_PATH);
|
||||
System.out.println("[MapIO] Suche Karte: " + MAP_PATH.toAbsolutePath());
|
||||
if (Files.exists(MAP_PATH)) return true;
|
||||
// Einmalige Migration vom alten Speicherort (world/blight_map.blm)
|
||||
if (Files.exists(MAP_PATH_OLD)) {
|
||||
try {
|
||||
Files.createDirectories(MAP_PATH.getParent());
|
||||
Files.move(MAP_PATH_OLD, MAP_PATH);
|
||||
System.out.println("[MapIO] Karte migriert: " + MAP_PATH_OLD + " → " + MAP_PATH);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
System.err.println("[MapIO] Migration fehlgeschlagen: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Path getMapPath() {
|
||||
|
||||
Reference in New Issue
Block a user