feat(save): SaveData/SaveSlotInfo/SaveException model

This commit is contained in:
2026-06-01 14:29:55 +02:00
parent 310ee65285
commit c92c143058
4 changed files with 81 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package thb.jeanluc.adventure.save;
import java.util.List;
import java.util.Map;
/**
* JSON-serialised snapshot of the mutable game state — a delta laid over the
* world freshly loaded from YAML. Header fields ({@code slotName}, room,
* {@code turn}, {@code savedAtEpochMillis}) double as the slot-list metadata.
*/
public record SaveData(
int schemaVersion,
String worldTitle,
String slotName,
long savedAtEpochMillis,
int turn,
String currentRoomId,
List<String> visitedRoomIds,
int gold,
List<String> inventoryItemIds,
List<String> flags,
Map<String, Integer> questStages,
List<String> questCompleted,
Map<String, List<String>> roomItemIds,
Map<String, Boolean> switchStates
) {
/** Current on-disk schema version. */
public static final int CURRENT_VERSION = 1;
}

View File

@@ -0,0 +1,18 @@
package thb.jeanluc.adventure.save;
/** Thrown when a save cannot be written/read; carries a player-facing message. */
public class SaveException extends RuntimeException {
public SaveException(String message, Throwable cause) {
super(message, cause);
}
public SaveException(String message) {
super(message);
}
/** Player-facing message (the constructor message is already user-friendly). */
public String getUserMessage() {
return getMessage();
}
}

View File

@@ -0,0 +1,6 @@
package thb.jeanluc.adventure.save;
/** Lightweight metadata for one save slot, shown in the Load menu. */
public record SaveSlotInfo(String slug, String slotName, String roomId,
int turn, long savedAtEpochMillis) {
}