Search in sources :

Example 1 with XmlGameElementMapper

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);
    }
}
Also used : Element(org.w3c.dom.Element) XmlGameElementMapper(games.strategy.engine.data.gameparser.XmlGameElementMapper) IDelegate(games.strategy.engine.delegate.IDelegate)

Example 2 with XmlGameElementMapper

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));
    }
}
Also used : Element(org.w3c.dom.Element) XmlGameElementMapper(games.strategy.engine.data.gameparser.XmlGameElementMapper) Tuple(games.strategy.util.Tuple)

Aggregations

XmlGameElementMapper (games.strategy.engine.data.gameparser.XmlGameElementMapper)2 Element (org.w3c.dom.Element)2 IDelegate (games.strategy.engine.delegate.IDelegate)1 Tuple (games.strategy.util.Tuple)1