Search in sources :

Example 1 with IRemoteDiceServer

use of games.strategy.engine.random.IRemoteDiceServer in project triplea by triplea-game.

the class PbemSetupPanel method loadDiceServer.

/**
 * Load the dice rollers from cache, if the game was a save game, the dice roller store is selected.
 *
 * @param data
 *        the game data
 */
private void loadDiceServer(final GameData data) {
    final List<IRemoteDiceServer> diceRollers = new ArrayList<>(PropertiesDiceRoller.loadFromFile());
    diceRollers.add(new InternalDiceServer());
    for (final IRemoteDiceServer diceRoller : diceRollers) {
        final IRemoteDiceServer cached = (IRemoteDiceServer) LocalBeanCache.INSTANCE.getSerializable(diceRoller.getDisplayName());
        if (cached != null) {
            diceRoller.setCcAddress(cached.getCcAddress());
            diceRoller.setToAddress(cached.getToAddress());
            diceRoller.setGameId(cached.getGameId());
        }
    }
    diceServerEditor.setBeans(diceRollers);
    if (gameSelectorModel.isSavedGame()) {
        // get the dice roller from the save game, if any
        final IRemoteDiceServer roller = (IRemoteDiceServer) data.getProperties().get(DICE_ROLLER);
        if (roller != null) {
            diceServerEditor.setSelectedBean(roller);
        }
    }
}
Also used : InternalDiceServer(games.strategy.engine.random.InternalDiceServer) ArrayList(java.util.ArrayList) IRemoteDiceServer(games.strategy.engine.random.IRemoteDiceServer)

Example 2 with IRemoteDiceServer

use of games.strategy.engine.random.IRemoteDiceServer in project triplea by triplea-game.

the class PbemSetupPanel method getLauncher.

/**
 * Called when the user hits play.
 */
@Override
public Optional<ILauncher> getLauncher() {
    // update local cache and write to disk before game starts
    final IForumPoster poster = (IForumPoster) forumPosterEditor.getBean();
    if (poster != null) {
        LocalBeanCache.INSTANCE.storeSerializable(poster.getClass().getCanonicalName(), poster);
    }
    final IEmailSender sender = (IEmailSender) emailSenderEditor.getBean();
    if (sender != null) {
        LocalBeanCache.INSTANCE.storeSerializable(sender.getClass().getCanonicalName(), sender);
    }
    final IRemoteDiceServer server = (IRemoteDiceServer) diceServerEditor.getBean();
    LocalBeanCache.INSTANCE.storeSerializable(server.getDisplayName(), server);
    LocalBeanCache.INSTANCE.writeToDisk();
    // create local launcher
    final String gameUuid = (String) gameSelectorModel.getGameData().getProperties().get(GameData.GAME_UUID);
    final PbemDiceRoller randomSource = new PbemDiceRoller((IRemoteDiceServer) diceServerEditor.getBean(), gameUuid);
    final Map<String, String> playerTypes = new HashMap<>();
    final Map<String, Boolean> playersEnabled = new HashMap<>();
    for (final PlayerSelectorRow player : this.playerTypes) {
        playerTypes.put(player.getPlayerName(), player.getPlayerType());
        playersEnabled.put(player.getPlayerName(), player.isPlayerEnabled());
    }
    // we don't need the playerToNode list, the
    // disable-able players, or the alliances
    // list, for a local game
    final PlayerListing pl = new PlayerListing(null, playersEnabled, playerTypes, gameSelectorModel.getGameData().getGameVersion(), gameSelectorModel.getGameName(), gameSelectorModel.getGameRound(), null, null);
    return Optional.of(new LocalLauncher(gameSelectorModel, randomSource, pl));
}
Also used : LocalLauncher(games.strategy.engine.framework.startup.launcher.LocalLauncher) HashMap(java.util.HashMap) IEmailSender(games.strategy.engine.pbem.IEmailSender) PlayerListing(games.strategy.engine.framework.message.PlayerListing) IForumPoster(games.strategy.engine.pbem.IForumPoster) PbemDiceRoller(games.strategy.engine.random.PbemDiceRoller) IRemoteDiceServer(games.strategy.engine.random.IRemoteDiceServer)

Aggregations

IRemoteDiceServer (games.strategy.engine.random.IRemoteDiceServer)2 PlayerListing (games.strategy.engine.framework.message.PlayerListing)1 LocalLauncher (games.strategy.engine.framework.startup.launcher.LocalLauncher)1 IEmailSender (games.strategy.engine.pbem.IEmailSender)1 IForumPoster (games.strategy.engine.pbem.IForumPoster)1 InternalDiceServer (games.strategy.engine.random.InternalDiceServer)1 PbemDiceRoller (games.strategy.engine.random.PbemDiceRoller)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1