Search in sources :

Example 1 with Player

use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.

the class Ladder1V1ControllerTest method setUp.

@Before
public void setUp() throws Exception {
    instance = new Ladder1v1Controller(gameService, preferencesService, playerService, leaderboardService, i18n, new ClientProperties(), eventBus);
    Player player = new Player(USERNAME);
    player.setId(PLAYER_ID);
    currentPlayerProperty = new SimpleObjectProperty<>(player);
    factionList = FXCollections.observableArrayList();
    LeaderboardEntry leaderboardEntry = new LeaderboardEntry();
    leaderboardEntry.setRating(500);
    leaderboardEntry.setWinLossRatio(12.23f);
    leaderboardEntry.setRank(100);
    leaderboardEntry.setGamesPlayed(412);
    leaderboardEntry.setUsername(USERNAME);
    when(leaderboardService.getLadder1v1Stats()).thenReturn(CompletableFuture.completedFuture(new ArrayList<>()));
    when(leaderboardService.getEntryForPlayer(PLAYER_ID)).thenReturn(CompletableFuture.completedFuture(leaderboardEntry));
    when(gameService.searching1v1Property()).thenReturn(searching1v1Property);
    when(preferencesService.getPreferences()).thenReturn(preferences);
    when(preferences.getLadder1v1Prefs()).thenReturn(ladder1V1Prefs);
    when(ladder1V1Prefs.getFactions()).thenReturn(factionList);
    when(preferences.getForgedAlliance()).thenReturn(forgedAlliancePrefs);
    when(playerService.getCurrentPlayer()).thenReturn(Optional.ofNullable(currentPlayerProperty.get()));
    when(playerService.currentPlayerProperty()).thenReturn(currentPlayerProperty);
    loadFxml("theme/play/ranked_1v1.fxml", clazz -> instance);
}
Also used : ClientProperties(com.faforever.client.config.ClientProperties) Player(com.faforever.client.player.Player) ArrayList(java.util.ArrayList) LeaderboardEntry(com.faforever.client.leaderboard.LeaderboardEntry) Before(org.junit.Before)

Example 2 with Player

use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.

the class ReplayDetailControllerTest method onDownloadMoreInfoClicked.

@Test
public void onDownloadMoreInfoClicked() throws Exception {
    when(replayService.getSize(anyInt())).thenReturn(CompletableFuture.completedFuture(1024));
    Replay replay = new Replay();
    Review review = new Review();
    review.setPlayer(new Player("junit"));
    replay.getReviews().setAll(FXCollections.observableArrayList(review));
    replay.setValidity(Validity.VALID);
    replay.setFeaturedMod(new FeaturedMod());
    instance.setReplay(replay);
    Path tmpPath = Paths.get("foo.tmp");
    when(replayService.downloadReplay(replay.getId())).thenReturn(CompletableFuture.completedFuture(tmpPath));
    instance.onDownloadMoreInfoClicked();
    verify(replayService).enrich(replay, tmpPath);
    assertThat(instance.optionsTable.isVisible(), is(true));
    assertThat(instance.chatTable.isVisible(), is(true));
}
Also used : Path(java.nio.file.Path) Player(com.faforever.client.player.Player) Review(com.faforever.client.vault.review.Review) FeaturedMod(com.faforever.client.mod.FeaturedMod) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 3 with Player

use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.

the class GameServiceImpl method onGameInfo.

private void onGameInfo(GameInfoMessage gameInfoMessage) {
    // Since all game updates are usually reflected on the UI and to prevent deadlocks
    JavaFxUtil.assertApplicationThread();
    if (gameInfoMessage.getGames() != null) {
        gameInfoMessage.getGames().forEach(this::onGameInfo);
        return;
    }
    Player currentPlayer = playerService.getCurrentPlayer().orElseThrow(() -> new IllegalStateException("Player has not been set"));
    Game game = createOrUpdateGame(gameInfoMessage);
    if (GameStatus.CLOSED == game.getStatus()) {
        if (currentPlayer.getGame() == game) {
            // Don't remove the game until the current player closed it. TODO: Why?
            currentPlayer.gameProperty().addListener((observable, oldValue, newValue) -> {
                if (newValue == null && oldValue.getStatus() == GameStatus.CLOSED) {
                    removeGame(gameInfoMessage);
                }
            });
        } else {
            removeGame(gameInfoMessage);
        }
        return;
    }
    // TODO the following can be removed as soon as the server tells us which game a player is in.
    boolean currentPlayerInGame = gameInfoMessage.getTeams().values().stream().anyMatch(team -> team.contains(currentPlayer.getUsername()));
    if (currentPlayerInGame && GameStatus.OPEN == gameInfoMessage.getState()) {
        synchronized (currentGame) {
            currentGame.set(game);
        }
    }
    game.statusProperty().addListener((observable, oldValue, newValue) -> {
        if (oldValue == GameStatus.OPEN && newValue == GameStatus.PLAYING && game.getTeams().values().stream().anyMatch(team -> team.contains(currentPlayer.getUsername())) && !platformService.isWindowFocused(faWindowTitle)) {
            platformService.focusWindow(faWindowTitle);
        }
    });
}
Also used : Player(com.faforever.client.player.Player)

Example 4 with Player

use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.

the class IceAdapterImpl method start.

@Override
public CompletableFuture<Integer> start() {
    iceAdapterClientFuture = new CompletableFuture<>();
    Thread thread = new Thread(() -> {
        String nativeDir = System.getProperty("nativeDir", "lib");
        int adapterPort = SocketUtils.findAvailableTcpPort();
        int gpgPort = SocketUtils.findAvailableTcpPort();
        Player currentPlayer = playerService.getCurrentPlayer().orElseThrow(() -> new IllegalStateException("Player has not been set"));
        Path workDirectory = Paths.get(nativeDir);
        String[] cmd = new String[] { // FIXME make linux compatible
        workDirectory.resolve("faf-ice-adapter.exe").toString(), "--id", String.valueOf(currentPlayer.getId()), "--login", currentPlayer.getUsername(), "--rpc-port", String.valueOf(adapterPort), "--gpgnet-port", String.valueOf(gpgPort) };
        try {
            ProcessBuilder processBuilder = new ProcessBuilder();
            processBuilder.directory(workDirectory.toFile());
            processBuilder.command(cmd);
            log.debug("Starting ICE adapter with command: {}", asList(cmd));
            process = processBuilder.start();
            Logger logger = LoggerFactory.getLogger("faf-ice-adapter");
            gobbleLines(process.getInputStream(), logger::debug);
            gobbleLines(process.getErrorStream(), logger::error);
            IceAdapterCallbacks iceAdapterCallbacks = applicationContext.getBean(IceAdapterCallbacks.class);
            for (int attempt = 0; attempt < CONNECTION_ATTEMPTS; attempt++) {
                try {
                    TcpClient tcpClient = new TcpClient("localhost", adapterPort, iceAdapterCallbacks);
                    peer = tcpClient.getPeer();
                    setIceServers();
                    setLobbyInitMode();
                    break;
                } catch (ConnectException e) {
                    logger.debug("Could not connect to ICE adapter (attempt {}/{})", attempt, CONNECTION_ATTEMPTS);
                }
            }
            iceAdapterClientFuture.complete(gpgPort);
            int exitCode = process.waitFor();
            if (exitCode == 0) {
                logger.debug("ICE adapter terminated normally");
            } else {
                logger.warn("ICE adapter terminated with exit code: {}", exitCode);
            }
        } catch (Exception e) {
            iceAdapterClientFuture.completeExceptionally(e);
        }
    });
    thread.setDaemon(true);
    thread.start();
    return iceAdapterClientFuture;
}
Also used : Path(java.nio.file.Path) Player(com.faforever.client.player.Player) Logger(org.slf4j.Logger) ConnectException(java.net.ConnectException) TcpClient(com.nbarraille.jjsonrpc.TcpClient) ConnectException(java.net.ConnectException)

Example 5 with Player

use of com.faforever.client.player.Player in project downlords-faf-client by FAForever.

the class ReviewsControllerTest method setUp.

@Before
public void setUp() throws Exception {
    instance = new ReviewsController(i18n, uiService, playerService);
    when(reviewController.getRoot()).thenReturn(new Pane());
    when(playerService.getCurrentPlayer()).thenReturn(Optional.of(new Player("junit")));
    loadFxml("theme/vault/review/reviews.fxml", param -> {
        if (param == ReviewController.class) {
            return reviewController;
        }
        if (param == StarsController.class) {
            return starsController;
        }
        if (param == StarController.class) {
            return starController;
        }
        return instance;
    });
}
Also used : Player(com.faforever.client.player.Player) Pane(javafx.scene.layout.Pane) Before(org.junit.Before)

Aggregations

Player (com.faforever.client.player.Player)51 AbstractPlainJavaFxTest (com.faforever.client.test.AbstractPlainJavaFxTest)17 Test (org.junit.Test)17 Pane (javafx.scene.layout.Pane)8 I18n (com.faforever.client.i18n.I18n)7 PlayerService (com.faforever.client.player.PlayerService)7 UiService (com.faforever.client.theme.UiService)7 ClientProperties (com.faforever.client.config.ClientProperties)6 Controller (com.faforever.client.fx.Controller)6 ArrayList (java.util.ArrayList)6 Platform (javafx.application.Platform)6 Node (javafx.scene.Node)6 Scope (org.springframework.context.annotation.Scope)6 Component (org.springframework.stereotype.Component)6 JavaFxUtil (com.faforever.client.fx.JavaFxUtil)5 NotificationService (com.faforever.client.notification.NotificationService)5 TimeService (com.faforever.client.util.TimeService)5 Collection (java.util.Collection)5 List (java.util.List)5 Map (java.util.Map)5