use of games.strategy.engine.data.gameparser.XmlGameElementMapper in project triplea by triplea-game.
the class GameParser method parseDelegates.
private void parseDelegates(final List<Element> delegateList) throws GameParseException {
final DelegateList delegates = data.getDelegateList();
for (final Element current : delegateList) {
// load the class
final String className = current.getAttribute("javaClass");
final XmlGameElementMapper elementMapper = new XmlGameElementMapper();
final IDelegate delegate = elementMapper.getDelegate(className).orElseThrow(() -> newGameParseException("Class <" + className + "> is not a delegate."));
final String name = current.getAttribute("name");
String displayName = current.getAttribute("display");
if (displayName == null) {
displayName = name;
}
delegate.initialize(name, displayName);
delegates.addDelegate(delegate);
}
}
use of games.strategy.engine.data.gameparser.XmlGameElementMapper in project triplea by triplea-game.
the class GameParser method parseAttachments.
private void parseAttachments(final Element root) throws GameParseException {
for (final Element current : getChildren("attachment", root)) {
final String className = current.getAttribute("javaClass");
final Attachable attachable = findAttachment(current, current.getAttribute("type"));
final String name = current.getAttribute("name");
final List<Element> options = getChildren("option", current);
final IAttachment attachment = new XmlGameElementMapper().getAttachment(className, name, attachable, data).orElseThrow(() -> newGameParseException("Attachment of type " + className + " could not be instantiated"));
attachable.addAttachment(name, attachment);
final ArrayList<Tuple<String, String>> attachmentOptionValues = setValues(attachment, options);
// keep a list of attachment references in the order they were added
data.addToAttachmentOrderAndValues(Tuple.of(attachment, attachmentOptionValues));
}
}
Aggregations