feat(loader): per-room music field + demo rooms.yaml entries

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-01 22:58:13 +02:00
parent 66e43830be
commit fa7851b6e0
5 changed files with 39 additions and 2 deletions

View File

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

View File

@@ -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<String> npcs,
List<ExitLockDto> exitLocks,
List<DescriptionStateDto> descriptionStates,
Boolean dark
Boolean dark,
String music
) {
/** Backward-compatible constructor without the optional state fields. */
public RoomDto(String id, String name, String description,
Map<String, String> exits, List<String> items, List<String> npcs) {
this(id, name, description, exits, items, npcs, null, null, null);
this(id, name, description, exits, items, npcs, null, null, null, null);
}
}

View File

@@ -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

View File

@@ -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

View File

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