diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/save/SaveCodec.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/save/SaveCodec.java index 3cce28b..0f27340 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/save/SaveCodec.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/save/SaveCodec.java @@ -95,9 +95,9 @@ public final class SaveCodec { } // 3. Player position + visited + gold. - p.setCurrentRoom(requireRoom(w, data.currentRoomId())); p.getVisitedRoomIds().clear(); p.getVisitedRoomIds().addAll(data.visitedRoomIds()); + p.setCurrentRoom(requireRoom(w, data.currentRoomId())); p.setGold(data.gold()); // 4. Flags, quests, turn. diff --git a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/save/SaveCodecTest.java b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/save/SaveCodecTest.java index ed1b1ca..569589e 100644 --- a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/save/SaveCodecTest.java +++ b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/save/SaveCodecTest.java @@ -101,5 +101,7 @@ class SaveCodecTest { GameSession dst = freshWorld("slot-a"); // Should not throw NPE; world items remain in their default positions or cleared org.junit.jupiter.api.Assertions.assertDoesNotThrow(() -> SaveCodec.apply(data, dst)); + // Post-condition: applying a save with null/empty roomItemIds clears all room item tables. + assertThat(dst.getWorld().getRooms().get("kitchen").findItem("lamp")).isEmpty(); } }