use of games.strategy.engine.framework.ui.GameChooserEntry in project triplea by triplea-game.
the class GameSelectorPanel method selectGameFile.
private void selectGameFile(final boolean saved) {
// is to use an AWT FileDialog instead of a Swing JDialog
if (saved) {
final File file = selectGameFile();
if (file == null || !file.exists()) {
return;
}
Interruptibles.await(() -> GameRunner.newBackgroundTaskRunner().runInBackground("Loading savegame...", () -> {
model.load(file, this);
setOriginalPropertiesMap(model.getGameData());
}));
} else {
try {
final GameChooserEntry entry = GameChooser.chooseGame(JOptionPane.getFrameForComponent(this), model.getGameName());
if (entry != null) {
GameRunner.newBackgroundTaskRunner().runInBackground("Loading map...", () -> {
if (!entry.isGameDataLoaded()) {
try {
entry.fullyParseGameData();
} catch (final GameParseException e) {
// TODO remove bad entries from the underlying model
return;
}
}
model.load(entry);
});
// we'll have a null game data.
if (model.getGameData() != null) {
setOriginalPropertiesMap(model.getGameData());
// only for new games, not saved games, we set the default options, and set them only once
// (the first time it is loaded)
gamePropertiesCache.loadCachedGamePropertiesInto(model.getGameData());
}
}
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
use of games.strategy.engine.framework.ui.GameChooserEntry 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.framework.ui.GameChooserEntry 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