feat(model): World.combinations field + backward-compatible constructors

This commit is contained in:
2026-06-01 17:13:05 +02:00
parent 022973dc75
commit c91bc3afea
2 changed files with 42 additions and 4 deletions

View File

@@ -37,15 +37,24 @@ public class World {
/** Ordered list of endings (first matching one wins). */
private final List<Ending> endings;
/** Backward-compatible constructor for worlds without quests or endings. */
/** Global lookup of combination recipes by canonical pair key. */
private final Map<String, Combination> combinations;
/** Backward-compatible constructor for worlds without quests, endings, or combinations. */
public World(Map<String, Room> rooms, Map<String, Item> items, Map<String, Npc> 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<String, Room> rooms, Map<String, Item> items, Map<String, Npc> npcs,
String title, String welcomeMessage, Map<String, Quest> 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<String, Room> rooms, Map<String, Item> items, Map<String, Npc> npcs,
String title, String welcomeMessage, Map<String, Quest> quests, List<Ending> endings) {
this(rooms, items, npcs, title, welcomeMessage, quests, endings, Map.of());
}
}

View File

@@ -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");
}
}