Search in sources :

Example 61 with GameParseException

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

the class UnitSupportAttachment method setUnitType.

private void setUnitType(final String names) throws GameParseException {
    if (names == null) {
        m_unitType = null;
        return;
    }
    m_unitType = new HashSet<>();
    for (final String element : names.split(":")) {
        final UnitType type = getData().getUnitTypeList().getUnitType(element);
        if (type == null) {
            throw new GameParseException("Could not find unitType. name:" + element + thisErrorMsg());
        }
        m_unitType.add(type);
    }
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException)

Example 62 with GameParseException

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

the class UnitSupportAttachment method setSide.

private void setSide(final String side) throws GameParseException {
    if (side == null) {
        resetSide();
        return;
    }
    m_defence = false;
    m_offence = false;
    for (final String element : side.split(":")) {
        if (element.equalsIgnoreCase("defence")) {
            m_defence = true;
        } else if (element.equalsIgnoreCase("offence")) {
            m_offence = true;
        } else {
            throw new GameParseException(side + " side must be defence or offence" + thisErrorMsg());
        }
    }
    m_side = side;
}
Also used : GameParseException(games.strategy.engine.data.GameParseException)

Example 63 with GameParseException

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

the class UnitSupportAttachment method setPlayers.

private void setPlayers(final String names) throws GameParseException {
    final String[] s = names.split(":");
    for (final String element : s) {
        final PlayerID player = getData().getPlayerList().getPlayerId(element);
        if (player == null) {
            throw new GameParseException("Could not find player. name:" + element + thisErrorMsg());
        }
        m_players.add(player);
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameParseException(games.strategy.engine.data.GameParseException)

Example 64 with GameParseException

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

the class GameSelectorModel method loadDefaultGameSameThread.

/**
 * Runs the load default game logic in same thread. Default game is the one that we loaded
 * on startup.
 */
public void loadDefaultGameSameThread() {
    final String userPreferredDefaultGameUri = ClientSetting.DEFAULT_GAME_URI_PREF.value();
    // we don't want to load a game file by default that is not within the map folders we can load. (ie: if a previous
    // version of triplea
    // was using running a game within its root folder, we shouldn't open it)
    GameChooserEntry selectedGame;
    final String user = ClientFileSystemHelper.getUserRootFolder().toURI().toString();
    if (!userPreferredDefaultGameUri.isEmpty() && userPreferredDefaultGameUri.contains(user)) {
        // game model list
        try {
            final URI defaultUri = new URI(userPreferredDefaultGameUri);
            selectedGame = new GameChooserEntry(defaultUri);
        } catch (final Exception e) {
            resetToFactoryDefault();
            selectedGame = selectByName();
            if (selectedGame == null) {
                return;
            }
        }
        if (!selectedGame.isGameDataLoaded()) {
            try {
                selectedGame.fullyParseGameData();
            } catch (final GameParseException e) {
                resetToFactoryDefault();
                loadDefaultGameSameThread();
                return;
            }
        }
    } else {
        resetToFactoryDefault();
        selectedGame = selectByName();
        if (selectedGame == null) {
            return;
        }
    }
    load(selectedGame);
}
Also used : GameChooserEntry(games.strategy.engine.framework.ui.GameChooserEntry) GameParseException(games.strategy.engine.data.GameParseException) URI(java.net.URI) GameParseException(games.strategy.engine.data.GameParseException) EngineVersionException(games.strategy.engine.data.EngineVersionException) IOException(java.io.IOException)

Example 65 with GameParseException

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

the class GameSelectorModel method selectByName.

private GameChooserEntry selectByName() {
    final String userPreferredDefaultGameName = ClientSetting.DEFAULT_GAME_NAME_PREF.value();
    final GameChooserModel model = new GameChooserModel();
    GameChooserEntry selectedGame = model.findByName(userPreferredDefaultGameName).orElse(null);
    if (selectedGame == null && model.size() > 0) {
        selectedGame = model.get(0);
    }
    if (selectedGame == null) {
        return null;
    }
    if (!selectedGame.isGameDataLoaded()) {
        try {
            selectedGame.fullyParseGameData();
        } catch (final GameParseException e) {
            model.removeEntry(selectedGame);
            resetToFactoryDefault();
            return null;
        }
    }
    return selectedGame;
}
Also used : GameChooserEntry(games.strategy.engine.framework.ui.GameChooserEntry) GameChooserModel(games.strategy.engine.framework.ui.GameChooserModel) GameParseException(games.strategy.engine.data.GameParseException)

Aggregations

GameParseException (games.strategy.engine.data.GameParseException)66 UnitType (games.strategy.engine.data.UnitType)29 PlayerID (games.strategy.engine.data.PlayerID)13 Territory (games.strategy.engine.data.Territory)7 Resource (games.strategy.engine.data.Resource)6 GameChooserEntry (games.strategy.engine.framework.ui.GameChooserEntry)3 TechAdvance (games.strategy.triplea.delegate.TechAdvance)3 IntegerMap (games.strategy.util.IntegerMap)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 EngineVersionException (games.strategy.engine.data.EngineVersionException)2 IOException (java.io.IOException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 GameMap (games.strategy.engine.data.GameMap)1 PlayerList (games.strategy.engine.data.PlayerList)1 ProductionFrontier (games.strategy.engine.data.ProductionFrontier)1 RelationshipType (games.strategy.engine.data.RelationshipType)1 ResourceCollection (games.strategy.engine.data.ResourceCollection)1 TerritoryEffect (games.strategy.engine.data.TerritoryEffect)1 InternalDoNotExport (games.strategy.engine.data.annotations.InternalDoNotExport)1