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);
}
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations