This repository has been archived on 2022-12-21. You can view files and clone it, but cannot push or open issues or pull requests.
sdm03/src/main/java/com/github/dtschust/zork/parser/strategies/ZorkRoomParseStrategy.java

51 lines
1.9 KiB
Java

package com.github.dtschust.zork.parser.strategies;
import com.github.dtschust.zork.ZorkTrigger;
import com.github.dtschust.zork.objects.ZorkRoom;
import com.github.dtschust.zork.parser.Property;
import com.github.dtschust.zork.parser.PropertyParseStrategy;
import com.github.dtschust.zork.parser.TriggerPropertyParseStrategy;
import com.github.dtschust.zork.types.ZorkDirection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ZorkRoomParseStrategy implements PropertyParseStrategy<ZorkRoom> {
private final TriggerPropertyParseStrategy triggerStrategy;
public ZorkRoomParseStrategy(final TriggerPropertyParseStrategy triggerStrategy) {
this.triggerStrategy = triggerStrategy;
}
@Override
public ZorkRoom parse(final Property source) {
// Get all possible Room attributes
final String name = source.subPropertyValue("name", "");
final String description = source.subPropertyValue("description", "");
final String type = source.subPropertyValue("type", "regular");
final List<ZorkTrigger> triggers = source.subPropertiesByName("trigger").stream()
.map(triggerStrategy.parse(source))
.collect(Collectors.toList());
final String status = source.subPropertyValue("status", "");
final List<String> items = source.subPropertyValues("item");
final List<String> creatures = source.subPropertyValues("creature");
final List<String> containers = source.subPropertyValues("container");
final Map<ZorkDirection, String> borders = source.subPropertiesByName("border").stream()
.collect(Collectors.toMap(
e -> ZorkDirection.fromLong(e.subPropertyValue("direction")),
e -> e.subPropertyValue("name")
));
return new ZorkRoom(name, description, type, status, triggers, borders, containers, items, creatures);
}
}