feat(loader): load combinations.yaml; demo matches+torch -> lit_torch
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,12 +5,14 @@ import com.fasterxml.jackson.databind.type.CollectionType;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import thb.jeanluc.adventure.loader.dto.CombinationDto;
|
||||
import thb.jeanluc.adventure.loader.dto.EndingDto;
|
||||
import thb.jeanluc.adventure.loader.dto.GameDto;
|
||||
import thb.jeanluc.adventure.loader.dto.ItemDto;
|
||||
import thb.jeanluc.adventure.loader.dto.NpcDto;
|
||||
import thb.jeanluc.adventure.loader.dto.QuestDto;
|
||||
import thb.jeanluc.adventure.loader.dto.RoomDto;
|
||||
import thb.jeanluc.adventure.model.Combination;
|
||||
import thb.jeanluc.adventure.model.Ending;
|
||||
import thb.jeanluc.adventure.model.Npc;
|
||||
import thb.jeanluc.adventure.model.Player;
|
||||
@@ -75,6 +77,8 @@ public class WorldLoader {
|
||||
List<RoomDto> roomDtos = readList(basePath + "/rooms.yaml", RoomDto.class);
|
||||
List<QuestDto> questDtos = readListOptional(basePath + "/quests.yaml", QuestDto.class);
|
||||
List<EndingDto> endingDtos = readListOptional(basePath + "/endings.yaml", EndingDto.class);
|
||||
List<CombinationDto> combinationDtos =
|
||||
readListOptional(basePath + "/combinations.yaml", CombinationDto.class);
|
||||
GameDto gameDto = readSingle(basePath + "/game.yaml", GameDto.class);
|
||||
|
||||
requireUniqueIds("item", itemDtos.stream().map(ItemDto::id).toList());
|
||||
@@ -104,6 +108,16 @@ public class WorldLoader {
|
||||
endings.add(EndingFactory.fromDto(dto));
|
||||
}
|
||||
|
||||
Map<String, Combination> combinations = new HashMap<>();
|
||||
for (CombinationDto dto : combinationDtos) {
|
||||
Combination c = CombinationFactory.fromDto(dto, items);
|
||||
String key = c.key();
|
||||
if (combinations.containsKey(key)) {
|
||||
throw new WorldLoadException("Duplicate combination for pair '" + key + "'");
|
||||
}
|
||||
combinations.put(key, c);
|
||||
}
|
||||
|
||||
ReferenceResolver resolver = new ReferenceResolver(items, npcs, rooms);
|
||||
resolver.resolveRooms(roomDtos);
|
||||
resolver.resolveNpcs(npcDtos);
|
||||
@@ -115,7 +129,7 @@ public class WorldLoader {
|
||||
Player player = new Player(start, gold);
|
||||
|
||||
World world = new World(rooms, items, npcs,
|
||||
gameDto.title(), gameDto.welcomeMessage(), quests, endings);
|
||||
gameDto.title(), gameDto.welcomeMessage(), quests, endings, combinations);
|
||||
log.info("World '{}' loaded: {} rooms, {} items, {} npcs",
|
||||
gameDto.title(), rooms.size(), items.size(), npcs.size());
|
||||
return new LoadResult(world, player);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
- a: matches
|
||||
b: torch
|
||||
consume: [matches, torch]
|
||||
produce: lit_torch
|
||||
response: |
|
||||
You strike a match and touch it to the torch; it catches with a low hiss
|
||||
and burns steady. You now hold a lit torch.
|
||||
@@ -47,3 +47,19 @@
|
||||
You ease the door shut again.
|
||||
effects:
|
||||
- { setFlag: fled }
|
||||
|
||||
- type: plain
|
||||
id: matches
|
||||
name: Box of Matches
|
||||
description: A small box of dry matches. They rattle when you shake it.
|
||||
|
||||
- type: plain
|
||||
id: torch
|
||||
name: Unlit Torch
|
||||
description: A pitch-soaked torch, waiting for a flame.
|
||||
|
||||
- type: plain
|
||||
id: lit_torch
|
||||
name: Lit Torch
|
||||
description: A burning torch, throwing back the dark.
|
||||
light: true
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
exits:
|
||||
south: kitchen
|
||||
west: library
|
||||
items: []
|
||||
items: [torch]
|
||||
npcs: []
|
||||
|
||||
- id: library
|
||||
@@ -33,7 +33,7 @@
|
||||
An old chest stands in the corner.
|
||||
exits:
|
||||
east: hallway
|
||||
items: [shovel]
|
||||
items: [shovel, matches]
|
||||
npcs: []
|
||||
|
||||
- id: cellar
|
||||
|
||||
Reference in New Issue
Block a user