use of games.strategy.engine.data.properties.GameProperties in project triplea by triplea-game.
the class GameParser method parseProperties.
private void parseProperties(final Node root) throws GameParseException {
final Collection<String> runningList = new ArrayList<>();
final GameProperties properties = data.getProperties();
for (final Element current : getChildren("property", root)) {
final String editable = current.getAttribute("editable");
final String property = current.getAttribute("name");
String value = current.getAttribute("value");
runningList.add(property);
if (value == null || value.length() == 0) {
final List<Element> valueChildren = getChildren("value", current);
if (!valueChildren.isEmpty()) {
final Element valueNode = valueChildren.get(0);
if (valueNode != null) {
value = valueNode.getTextContent();
}
}
}
if (editable != null && editable.equalsIgnoreCase("true")) {
parseEditableProperty(current, property, value);
} else {
final List<Node> children2 = getNonTextNodesIgnoring(current, "value");
if (children2.size() == 0) {
// definition
try {
// test if it is an integer
final int integer = Integer.parseInt(value);
properties.set(property, integer);
} catch (final NumberFormatException e) {
// then it must be a string
properties.set(property, value);
}
} else {
final String type = children2.get(0).getNodeName();
if (type.equals("boolean")) {
properties.set(property, Boolean.valueOf(value));
} else if (type.equals("file")) {
properties.set(property, new File(value));
} else if (type.equals("number")) {
int intValue = 0;
if (value != null) {
try {
intValue = Integer.parseInt(value);
} catch (final NumberFormatException e) {
// value already 0
}
}
properties.set(property, intValue);
} else {
properties.set(property, value);
}
}
}
}
data.getPlayerList().forEach(playerId -> data.getProperties().addPlayerProperty(new NumberProperty(Constants.getIncomePercentageFor(playerId), null, 999, 0, 100)));
data.getPlayerList().forEach(playerId -> data.getProperties().addPlayerProperty(new NumberProperty(Constants.getPuIncomeBonus(playerId), null, 999, 0, 0)));
}
use of games.strategy.engine.data.properties.GameProperties in project triplea by triplea-game.
the class HeadlessGameServer method loadGameOptions.
public synchronized void loadGameOptions(final byte[] bytes) {
// don't change mid-game
if (setupPanelModel.getPanel() != null && game == null) {
if (bytes == null || bytes.length == 0) {
return;
}
final GameData data = gameSelectorModel.getGameData();
if (data == null) {
return;
}
final GameProperties props = data.getProperties();
if (props == null) {
return;
}
GameProperties.applyByteMapToChangeProperties(bytes, props);
System.out.println("Changed to user game options.");
}
}
use of games.strategy.engine.data.properties.GameProperties in project triplea by triplea-game.
the class GameDataExporter method propertyList.
@SuppressWarnings("unchecked")
private void propertyList(final GameData data) {
// TODO: Unchecked Reflection
xmlfile.append(" <propertyList>\n");
final GameProperties gameProperties = data.getProperties();
try {
// TODO: unchecked reflection below.. this is bad stuff.. find ways to remove
final Field conPropField = GameProperties.class.getDeclaredField(GameProperties.CONSTANT_PROPERTIES_FIELD_NAME);
conPropField.setAccessible(true);
final Field edPropField = GameProperties.class.getDeclaredField(GameProperties.EDITABLE_PROPERTIES_FIELD_NAME);
edPropField.setAccessible(true);
printConstantProperties((Map<String, Object>) conPropField.get(gameProperties));
printEditableProperties((Map<String, IEditableProperty>) edPropField.get(gameProperties));
} catch (final NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
ClientLogger.logError("An Error occured whilst trying trying to setup the Property List", e);
}
xmlfile.append(" </propertyList>\n");
}
use of games.strategy.engine.data.properties.GameProperties in project triplea by triplea-game.
the class MapOptionsPanel method build.
static JPanel build(final GameData gameData, final StagingScreen screen) {
final GameProperties properties = gameData.getProperties();
final List<IEditableProperty> props = properties.getEditableProperties();
final JPanelBuilder panelBuilder = JPanelBuilder.builder().gridBagLayout(2).add(new JLabel("<html><h2>Map Options</h2></html>")).add(new JPanel());
props.stream().filter(prop -> !prop.getName().contains("bid")).forEach(prop -> {
panelBuilder.add(JLabelBuilder.builder().textWithMaxLength(prop.getName(), 25).tooltip(prop.getName()).build());
panelBuilder.add(screen != StagingScreen.NETWORK_CLIENT ? prop.getEditorComponent() : prop.getEditorComponentDisabled());
});
return panelBuilder.build();
}
Aggregations