Search in sources :

Example 1 with GameProperties

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)));
}
Also used : GameProperties(games.strategy.engine.data.properties.GameProperties) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) File(java.io.File) NumberProperty(games.strategy.engine.data.properties.NumberProperty)

Example 2 with GameProperties

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.");
    }
}
Also used : GameProperties(games.strategy.engine.data.properties.GameProperties) GameData(games.strategy.engine.data.GameData)

Example 3 with GameProperties

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");
}
Also used : GameProperties(games.strategy.engine.data.properties.GameProperties) Field(java.lang.reflect.Field) IEditableProperty(games.strategy.engine.data.properties.IEditableProperty)

Example 4 with GameProperties

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();
}
Also used : GameProperties(games.strategy.engine.data.properties.GameProperties) GameProperties(games.strategy.engine.data.properties.GameProperties) GameData(games.strategy.engine.data.GameData) List(java.util.List) JLabelBuilder(swinglib.JLabelBuilder) JLabel(javax.swing.JLabel) JPanelBuilder(swinglib.JPanelBuilder) JPanel(javax.swing.JPanel) IEditableProperty(games.strategy.engine.data.properties.IEditableProperty) JPanel(javax.swing.JPanel) JPanelBuilder(swinglib.JPanelBuilder) JLabel(javax.swing.JLabel) IEditableProperty(games.strategy.engine.data.properties.IEditableProperty)

Aggregations

GameProperties (games.strategy.engine.data.properties.GameProperties)4 GameData (games.strategy.engine.data.GameData)2 IEditableProperty (games.strategy.engine.data.properties.IEditableProperty)2 NumberProperty (games.strategy.engine.data.properties.NumberProperty)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 JLabelBuilder (swinglib.JLabelBuilder)1 JPanelBuilder (swinglib.JPanelBuilder)1