use of games.strategy.engine.data.properties.StringProperty 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);
}
Aggregations