Search in sources :

Example 1 with BooleanProperty

use of games.strategy.engine.data.properties.BooleanProperty in project triplea by triplea-game.

the class GameParser method parseEditableProperty.

private void parseEditableProperty(final Element property, final String name, final String defaultValue) throws GameParseException {
    // what type
    final List<Node> children = getNonTextNodes(property);
    if (children.size() != 1) {
        throw newGameParseException("Editable properties must have exactly 1 child specifying the type. Number of children found:" + children.size() + " for node:" + property.getNodeName());
    }
    final Element child = (Element) children.get(0);
    final String childName = child.getNodeName();
    final IEditableProperty editableProperty;
    if (childName.equals("boolean")) {
        editableProperty = new BooleanProperty(name, null, Boolean.valueOf(defaultValue));
    } else if (childName.equals("file")) {
        editableProperty = new FileProperty(name, null, defaultValue);
    } else if (childName.equals("list") || childName.equals("combo")) {
        final StringTokenizer tokenizer = new StringTokenizer(child.getAttribute("values"), ",");
        final Collection<String> values = new ArrayList<>();
        while (tokenizer.hasMoreElements()) {
            values.add(tokenizer.nextToken());
        }
        editableProperty = new ComboProperty<>(name, null, defaultValue, values);
    } else if (childName.equals("number")) {
        final int max = Integer.valueOf(child.getAttribute("max"));
        final int min = Integer.valueOf(child.getAttribute("min"));
        final int def = Integer.valueOf(defaultValue);
        editableProperty = new NumberProperty(name, null, max, min, def);
    } else if (childName.equals("color")) {
        // Parse the value as a hexidecimal number
        final int def = Integer.valueOf(defaultValue, 16);
        editableProperty = new ColorProperty(name, null, def);
    } else if (childName.equals("string")) {
        editableProperty = new StringProperty(name, null, defaultValue);
    } else {
        throw newGameParseException("Unrecognized property type:" + childName);
    }
    data.getProperties().addEditableProperty(editableProperty);
}
Also used : BooleanProperty(games.strategy.engine.data.properties.BooleanProperty) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) StringProperty(games.strategy.engine.data.properties.StringProperty) IEditableProperty(games.strategy.engine.data.properties.IEditableProperty) StringTokenizer(java.util.StringTokenizer) FileProperty(games.strategy.engine.data.properties.FileProperty) NumberProperty(games.strategy.engine.data.properties.NumberProperty) ColorProperty(games.strategy.engine.data.properties.ColorProperty)

Aggregations

BooleanProperty (games.strategy.engine.data.properties.BooleanProperty)1 ColorProperty (games.strategy.engine.data.properties.ColorProperty)1 FileProperty (games.strategy.engine.data.properties.FileProperty)1 IEditableProperty (games.strategy.engine.data.properties.IEditableProperty)1 NumberProperty (games.strategy.engine.data.properties.NumberProperty)1 StringProperty (games.strategy.engine.data.properties.StringProperty)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1