From c91bc3afea5f5e98db632e52732e356e1fbcf2f4 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 1 Jun 2026 17:13:05 +0200 Subject: [PATCH] feat(model): World.combinations field + backward-compatible constructors --- .../thb/jeanluc/adventure/model/World.java | 17 ++++++++--- .../model/WorldCombinationsTest.java | 29 +++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 Semesterprojekt/src/test/java/thb/jeanluc/adventure/model/WorldCombinationsTest.java diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/model/World.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/model/World.java index 56dffb1..c8c9054 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/model/World.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/model/World.java @@ -37,15 +37,24 @@ public class World { /** Ordered list of endings (first matching one wins). */ private final List endings; - /** Backward-compatible constructor for worlds without quests or endings. */ + /** Global lookup of combination recipes by canonical pair key. */ + private final Map combinations; + + /** Backward-compatible constructor for worlds without quests, endings, or combinations. */ public World(Map rooms, Map items, Map npcs, String title, String welcomeMessage) { - this(rooms, items, npcs, title, welcomeMessage, Map.of(), List.of()); + this(rooms, items, npcs, title, welcomeMessage, Map.of(), List.of(), Map.of()); } - /** Backward-compatible constructor for worlds with quests but no endings. */ + /** Backward-compatible constructor for worlds with quests but no endings/combinations. */ public World(Map rooms, Map items, Map npcs, String title, String welcomeMessage, Map quests) { - this(rooms, items, npcs, title, welcomeMessage, quests, List.of()); + this(rooms, items, npcs, title, welcomeMessage, quests, List.of(), Map.of()); + } + + /** Backward-compatible constructor for worlds with quests + endings but no combinations. */ + public World(Map rooms, Map items, Map npcs, + String title, String welcomeMessage, Map quests, List endings) { + this(rooms, items, npcs, title, welcomeMessage, quests, endings, Map.of()); } } diff --git a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/model/WorldCombinationsTest.java b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/model/WorldCombinationsTest.java new file mode 100644 index 0000000..84f22e7 --- /dev/null +++ b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/model/WorldCombinationsTest.java @@ -0,0 +1,29 @@ +package thb.jeanluc.adventure.model; + +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +class WorldCombinationsTest { + + @Test + void legacyConstructorsDefaultToEmptyCombinations() { + World w5 = new World(Map.of(), Map.of(), Map.of(), "t", "w"); + World w6 = new World(Map.of(), Map.of(), Map.of(), "t", "w", Map.of()); + World w7 = new World(Map.of(), Map.of(), Map.of(), "t", "w", Map.of(), List.of()); + assertThat(w5.getCombinations()).isEmpty(); + assertThat(w6.getCombinations()).isEmpty(); + assertThat(w7.getCombinations()).isEmpty(); + } + + @Test + void fullConstructorStoresCombinations() { + Combination c = new Combination("a", "b", List.of(), List.of(), null, List.of(), "r", null); + World w = new World(Map.of(), Map.of(), Map.of(), "t", "w", + Map.of(), List.of(), Map.of(c.key(), c)); + assertThat(w.getCombinations()).containsKey("a|b"); + } +}