From e10ff2cf99132d7c65b772d2b1a992d43762d4a4 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sun, 31 May 2026 20:58:58 +0200 Subject: [PATCH] feat(io): MapView model (CellState, RoomCell, Connection, MapView) Co-Authored-By: Claude Opus 4.8 (1M context) --- .../jeanluc/adventure/io/text/CellState.java | 4 ++++ .../jeanluc/adventure/io/text/Connection.java | 4 ++++ .../thb/jeanluc/adventure/io/text/MapView.java | 11 +++++++++++ .../thb/jeanluc/adventure/io/text/RoomCell.java | 4 ++++ .../jeanluc/adventure/io/text/MapViewTest.java | 17 +++++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/CellState.java create mode 100644 Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/Connection.java create mode 100644 Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/MapView.java create mode 100644 Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/RoomCell.java create mode 100644 Semesterprojekt/src/test/java/thb/jeanluc/adventure/io/text/MapViewTest.java diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/CellState.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/CellState.java new file mode 100644 index 0000000..b486940 --- /dev/null +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/CellState.java @@ -0,0 +1,4 @@ +package thb.jeanluc.adventure.io.text; + +/** Fog-of-war state of a room on the map. */ +public enum CellState { CURRENT, VISITED, KNOWN } diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/Connection.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/Connection.java new file mode 100644 index 0000000..decf156 --- /dev/null +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/Connection.java @@ -0,0 +1,4 @@ +package thb.jeanluc.adventure.io.text; + +/** A corridor between two placed rooms. */ +public record Connection(RoomCell from, RoomCell to) {} diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/MapView.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/MapView.java new file mode 100644 index 0000000..82c249e --- /dev/null +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/MapView.java @@ -0,0 +1,11 @@ +package thb.jeanluc.adventure.io.text; + +import java.util.List; + +/** Frontend-agnostic snapshot of the visible map: placed cells + connections. */ +public record MapView(List cells, List connections) { + public MapView { + cells = List.copyOf(cells); + connections = List.copyOf(connections); + } +} diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/RoomCell.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/RoomCell.java new file mode 100644 index 0000000..06ec898 --- /dev/null +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/text/RoomCell.java @@ -0,0 +1,4 @@ +package thb.jeanluc.adventure.io.text; + +/** A room placed on the map grid at integer coords, with its fog-of-war state. */ +public record RoomCell(String id, String name, int x, int y, CellState state) {} diff --git a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/io/text/MapViewTest.java b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/io/text/MapViewTest.java new file mode 100644 index 0000000..d8a6ade --- /dev/null +++ b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/io/text/MapViewTest.java @@ -0,0 +1,17 @@ +package thb.jeanluc.adventure.io.text; + +import org.junit.jupiter.api.Test; +import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; + +class MapViewTest { + @Test + void mapViewIsImmutableAndHoldsCellsAndConnections() { + RoomCell a = new RoomCell("kitchen", "Kitchen", 0, 0, CellState.CURRENT); + RoomCell b = new RoomCell("hallway", "Hallway", 0, -1, CellState.VISITED); + MapView v = new MapView(List.of(a, b), List.of(new Connection(a, b))); + assertThat(v.cells()).hasSize(2); + assertThat(v.connections()).hasSize(1); + assertThat(v.connections().getFirst().from().id()).isEqualTo("kitchen"); + } +}