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:
@@ -21,6 +21,7 @@ public final class RoomFactory {
|
|||||||
public static Room shellFromDto(RoomDto dto) {
|
public static Room shellFromDto(RoomDto dto) {
|
||||||
Room room = new Room(dto.id(), dto.name(), dto.description());
|
Room room = new Room(dto.id(), dto.name(), dto.description());
|
||||||
room.setDark(Boolean.TRUE.equals(dto.dark()));
|
room.setDark(Boolean.TRUE.equals(dto.dark()));
|
||||||
|
room.setMusic(dto.music());
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import java.util.Map;
|
|||||||
* @param exitLocks optional condition-gates per exit direction
|
* @param exitLocks optional condition-gates per exit direction
|
||||||
* @param descriptionStates optional condition-gated description variants
|
* @param descriptionStates optional condition-gated description variants
|
||||||
* @param dark whether this room is dark; nullable
|
* @param dark whether this room is dark; nullable
|
||||||
|
* @param music optional GUI background-music track filename; null = none
|
||||||
*/
|
*/
|
||||||
public record RoomDto(
|
public record RoomDto(
|
||||||
String id,
|
String id,
|
||||||
@@ -25,11 +26,12 @@ public record RoomDto(
|
|||||||
List<String> npcs,
|
List<String> npcs,
|
||||||
List<ExitLockDto> exitLocks,
|
List<ExitLockDto> exitLocks,
|
||||||
List<DescriptionStateDto> descriptionStates,
|
List<DescriptionStateDto> descriptionStates,
|
||||||
Boolean dark
|
Boolean dark,
|
||||||
|
String music
|
||||||
) {
|
) {
|
||||||
/** Backward-compatible constructor without the optional state fields. */
|
/** Backward-compatible constructor without the optional state fields. */
|
||||||
public RoomDto(String id, String name, String description,
|
public RoomDto(String id, String name, String description,
|
||||||
Map<String, String> exits, List<String> items, List<String> npcs) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ public class Room {
|
|||||||
@Setter
|
@Setter
|
||||||
private boolean dark;
|
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
|
* Connects this room to another in the given direction. Does not
|
||||||
* create the reverse connection — callers must set that up
|
* create the reverse connection — callers must set that up
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
description: |
|
description: |
|
||||||
A dusty kitchen. Cobwebs hang from the rafters
|
A dusty kitchen. Cobwebs hang from the rafters
|
||||||
and a letter lies on the table.
|
and a letter lies on the table.
|
||||||
|
music: manor-theme.ogg
|
||||||
exits:
|
exits:
|
||||||
north: hallway
|
north: hallway
|
||||||
east: cellar
|
east: cellar
|
||||||
@@ -55,6 +56,7 @@
|
|||||||
name: Dungeon
|
name: Dungeon
|
||||||
description: |
|
description: |
|
||||||
A cramped stone room, black as pitch. A rusty generator squats in the corner.
|
A cramped stone room, black as pitch. A rusty generator squats in the corner.
|
||||||
|
music: dungeon-drone.ogg
|
||||||
dark: true
|
dark: true
|
||||||
exits:
|
exits:
|
||||||
north: kitchen
|
north: kitchen
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user