Zwischenstand

This commit is contained in:
2026-10-16 13:52:21 +02:00
parent d19538bb63
commit 93a3c266e1
18 changed files with 577 additions and 70 deletions

View File

@@ -0,0 +1,92 @@
package de.blight.common.model;
import com.google.gson.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
/**
* Lädt und speichert per-Kategorie Schild-Attachment-Konfiguration (shield_attachment.json).
*/
public final class ShieldAttachmentIO {
private static final Logger log = LoggerFactory.getLogger(ShieldAttachmentIO.class);
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private static final String CLASSPATH_FILE = "shield_attachment.json";
private static final Map<String, ShieldCategoryAttachment> CONFIGS = new HashMap<>();
private static boolean loaded = false;
private ShieldAttachmentIO() {}
public static ShieldCategoryAttachment get(ItemSubCategory cat) {
ensureLoaded();
if (cat == null) return new ShieldCategoryAttachment();
return CONFIGS.getOrDefault(cat.name(), new ShieldCategoryAttachment());
}
public static void set(ItemSubCategory cat, ShieldCategoryAttachment cfg) {
if (cat != null) CONFIGS.put(cat.name(), cfg);
}
public static synchronized void loadFromClasspath() {
try (InputStream is = ShieldAttachmentIO.class.getClassLoader()
.getResourceAsStream(CLASSPATH_FILE)) {
if (is == null) {
log.warn("[ShieldAttachmentIO] {} nicht auf Classpath – Defaults verwendet", CLASSPATH_FILE);
loaded = true;
return;
}
parse(new String(is.readAllBytes(), StandardCharsets.UTF_8));
loaded = true;
} catch (IOException e) {
log.warn("[ShieldAttachmentIO] Ladefehler: {}", e.getMessage());
loaded = true;
}
}
public static void load(Path file) {
if (!Files.exists(file)) return;
try {
parse(Files.readString(file, StandardCharsets.UTF_8));
loaded = true;
} catch (IOException e) {
log.warn("[ShieldAttachmentIO] Ladefehler: {}", e.getMessage());
}
}
public static void save(Path file) {
try {
Files.writeString(file, GSON.toJson(CONFIGS), StandardCharsets.UTF_8);
log.info("[ShieldAttachmentIO] Gespeichert: {}", file);
} catch (IOException e) {
log.warn("[ShieldAttachmentIO] Speicherfehler: {}", e.getMessage());
}
}
public static Map<String, ShieldCategoryAttachment> getAll() {
ensureLoaded();
return new HashMap<>(CONFIGS);
}
private static synchronized void ensureLoaded() {
if (!loaded) loadFromClasspath();
}
private static void parse(String json) {
CONFIGS.clear();
JsonObject obj = JsonParser.parseString(json).getAsJsonObject();
for (var entry : obj.entrySet()) {
CONFIGS.put(entry.getKey(),
GSON.fromJson(entry.getValue(), ShieldCategoryAttachment.class));
}
log.info("[ShieldAttachmentIO] {} Kategorien geladen", CONFIGS.size());
}
}

View File

@@ -0,0 +1,14 @@
package de.blight.common.model;
import lombok.Getter;
import lombok.Setter;
/** Attachment-Parameter für einen Schild-Typ (am linken Unterarm). */
@Getter
@Setter
public class ShieldCategoryAttachment {
private float rotX = -90f;
private float rotY = 0f;
private float rotZ = 0f;
private float elbowOffset = 0.25f;
}