feat(io): MapView model (CellState, RoomCell, Connection, MapView)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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 }
|
||||
@@ -0,0 +1,4 @@
|
||||
package thb.jeanluc.adventure.io.text;
|
||||
|
||||
/** A corridor between two placed rooms. */
|
||||
public record Connection(RoomCell from, RoomCell to) {}
|
||||
@@ -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<RoomCell> cells, List<Connection> connections) {
|
||||
public MapView {
|
||||
cells = List.copyOf(cells);
|
||||
connections = List.copyOf(connections);
|
||||
}
|
||||
}
|
||||
@@ -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) {}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user