diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/loader/RoomFactory.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/loader/RoomFactory.java index 5742eb9..38d3d24 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/loader/RoomFactory.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/loader/RoomFactory.java @@ -21,6 +21,7 @@ public final class RoomFactory { public static Room shellFromDto(RoomDto dto) { Room room = new Room(dto.id(), dto.name(), dto.description()); room.setDark(Boolean.TRUE.equals(dto.dark())); + room.setMusic(dto.music()); return room; } } diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/loader/dto/RoomDto.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/loader/dto/RoomDto.java index e069351..53a351c 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/loader/dto/RoomDto.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/loader/dto/RoomDto.java @@ -15,6 +15,7 @@ import java.util.Map; * @param exitLocks optional condition-gates per exit direction * @param descriptionStates optional condition-gated description variants * @param dark whether this room is dark; nullable + * @param music optional GUI background-music track filename; null = none */ public record RoomDto( String id, @@ -25,11 +26,12 @@ public record RoomDto( List npcs, List exitLocks, List descriptionStates, - Boolean dark + Boolean dark, + String music ) { /** Backward-compatible constructor without the optional state fields. */ public RoomDto(String id, String name, String description, Map exits, List items, List npcs) { - this(id, name, description, exits, items, npcs, null, null, null); + this(id, name, description, exits, items, npcs, null, null, null, null); } } diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/model/Room.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/model/Room.java index dcd9e8c..4cc61fa 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/model/Room.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/model/Room.java @@ -55,6 +55,10 @@ public class Room { @Setter private boolean dark; + /** Optional GUI background-music track filename for this room; null = none. */ + @Setter + private String music; + /** * Connects this room to another in the given direction. Does not * create the reverse connection — callers must set that up diff --git a/Semesterprojekt/src/main/resources/world/rooms.yaml b/Semesterprojekt/src/main/resources/world/rooms.yaml index c6d06e0..9eb5078 100644 --- a/Semesterprojekt/src/main/resources/world/rooms.yaml +++ b/Semesterprojekt/src/main/resources/world/rooms.yaml @@ -3,6 +3,7 @@ description: | A dusty kitchen. Cobwebs hang from the rafters and a letter lies on the table. + music: manor-theme.ogg exits: north: hallway east: cellar @@ -55,6 +56,7 @@ name: Dungeon description: | A cramped stone room, black as pitch. A rusty generator squats in the corner. + music: dungeon-drone.ogg dark: true exits: north: kitchen diff --git a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/loader/RoomMusicTest.java b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/loader/RoomMusicTest.java new file mode 100644 index 0000000..7bd8977 --- /dev/null +++ b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/loader/RoomMusicTest.java @@ -0,0 +1,28 @@ +package thb.jeanluc.adventure.loader; + +import org.junit.jupiter.api.Test; +import thb.jeanluc.adventure.loader.dto.RoomDto; +import thb.jeanluc.adventure.model.Room; + +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +class RoomMusicTest { + + @Test + void musicFieldIsCarriedOntoRoom() { + RoomDto dto = new RoomDto("r", "Room", "d", + Map.of(), List.of(), List.of(), null, null, null, "theme.ogg"); + Room room = RoomFactory.shellFromDto(dto); + assertThat(room.getMusic()).isEqualTo("theme.ogg"); + } + + @Test + void absentMusicIsNull() { + RoomDto dto = new RoomDto("r", "Room", "d", Map.of(), List.of(), List.of()); + Room room = RoomFactory.shellFromDto(dto); + assertThat(room.getMusic()).isNull(); + } +}