aboutsummaryrefslogtreecommitdiff
path: root/internal/validate
diff options
context:
space:
mode:
Diffstat (limited to 'internal/validate')
-rw-r--r--internal/validate/checks.go17
-rw-r--r--internal/validate/grid_test.go46
2 files changed, 51 insertions, 12 deletions
diff --git a/internal/validate/checks.go b/internal/validate/checks.go
index 87c078e..a41ad86 100644
--- a/internal/validate/checks.go
+++ b/internal/validate/checks.go
@@ -45,12 +45,14 @@ func validateRooms(s Source) []Issue {
for dir, exit := range room.Exits {
switch dir {
- case world.North, world.South, world.East, world.West, world.Up, world.Down:
+ case world.North, world.South, world.East, world.West,
+ world.Northeast, world.Northwest, world.Southeast, world.Southwest,
+ world.Up, world.Down:
default:
issues = append(issues, Issue{
Level: "ERROR",
Type: "reference",
- Message: fmt.Sprintf("Room %d: invalid exit direction %q (only north/south/east/west/up/down supported)", id, dir),
+ Message: fmt.Sprintf("Room %d: invalid exit direction %q (only n/s/e/w/ne/nw/se/sw/up/down supported)", id, dir),
})
continue
}
@@ -867,15 +869,6 @@ func validateRoomWiring(s Source) []Issue {
return issues
}
-// gridDeltas maps the horizontal exits to their grid movement. Up/Down are
-// intentionally excluded: they connect separate horizontal planes rather than
-// moving within one.
-var gridDeltas = map[world.ExitDir][2]int{
- world.North: {0, -1},
- world.South: {0, 1},
- world.East: {1, 0},
- world.West: {-1, 0},
-}
// validateRoomGrid lays each reachable horizontal plane on a 2D grid starting
// from the configured root rooms and reports when the exit layout cannot be
@@ -933,7 +926,7 @@ func validateRoomGrid(s Source) []Issue {
continue
}
- d := gridDeltas[dir]
+ d := world.DirectionDeltas[dir]
want := [2]int{c[0] + d[0], c[1] + d[1]}
if existing, ok := coordOf[target]; ok {
diff --git a/internal/validate/grid_test.go b/internal/validate/grid_test.go
index 9a8ef02..b3f834a 100644
--- a/internal/validate/grid_test.go
+++ b/internal/validate/grid_test.go
@@ -103,3 +103,49 @@ func TestGridMultiPlaneViaUpDown(t *testing.T) {
t.Errorf("expected an overlap in plane origin 10, got: %+v", issues)
}
}
+
+func TestGridDiagonalClean(t *testing.T) {
+ // Room 1 -> NE -> Room 2 (at 1,-1). Clean diagonal placement.
+ rooms := map[int]string{
+ 1: "exits:\n northeast: 2\n",
+ 2: "name: two\n exits:\n southwest: 1\n",
+ }
+ if issues := runGridCheck(t, rooms, 1); len(issues) != 0 {
+ t.Errorf("expected no grid issues, got: %+v", issues)
+ }
+}
+
+func TestGridDiagonalOverlap(t *testing.T) {
+ // Two different rooms both resolve to (2,1):
+ // 1→SE→2→E→4 lands 4 at (2,1).
+ // 1→E→3→SE→5 lands 5 at (2,1). Room 4 != 5 → overlap.
+ rooms := map[int]string{
+ 1: "exits:\n southeast: 2\n east: 3\n",
+ 2: "exits:\n east: 4\n",
+ 3: "exits:\n southeast: 5\n",
+ 4: "name: four\n",
+ 5: "name: five\n",
+ }
+ issues := runGridCheck(t, rooms, 1)
+ if !containsMsg(issues, "Grid overlap") {
+ t.Errorf("expected a grid overlap via diagonal, got: %+v", issues)
+ }
+}
+
+func TestGridDiagonalTwist(t *testing.T) {
+ // Room 4 forced onto two different cells:
+ // path1: 1→E→2 (2 at 1,0). 2→NE→4 places 4 at (2,-1).
+ // path2: 1→N→3 (3 at 0,-1). 3→E→5 (5 at 1,-1). 5→N→4 wants 4 at (1,-2).
+ // 4 already placed at (2,-1) but wanted at (1,-2) → twist.
+ rooms := map[int]string{
+ 1: "exits:\n east: 2\n north: 3\n",
+ 2: "exits:\n northeast: 4\n",
+ 3: "exits:\n east: 5\n",
+ 4: "name: four\n",
+ 5: "exits:\n north: 4\n",
+ }
+ issues := runGridCheck(t, rooms, 1)
+ if !containsMsg(issues, "Grid twist") {
+ t.Errorf("expected a grid twist via diagonal, got: %+v", issues)
+ }
+}