use of com.faforever.client.replay.Replay.PlayerStats in project downlords-faf-client by FAForever.
the class TeamCardControllerTest method setUp.
@Before
public void setUp() throws IOException {
instance = new TeamCardController(uiService, i18n);
playerList = new ArrayList<>();
playerList.add(player);
teams = FXCollections.observableHashMap();
when(uiService.loadFxml("theme/player_card_tooltip.fxml")).thenReturn(playerCardTooltipController);
when(uiService.loadFxml("theme/rating_change_label.fxml")).thenReturn(ratingChangeLabelController);
when(playerCardTooltipController.getRoot()).thenReturn(new Label());
when(ratingChangeLabelController.getRoot()).thenReturn(new Label());
when(player.getId()).thenReturn(1);
playerStats = new PlayerStats(1, 1000, 0, 1100d, 0d, 0);
teams.put("2", Collections.singletonList(playerStats));
loadFxml("theme/team_card.fxml", param -> instance);
}
use of com.faforever.client.replay.Replay.PlayerStats in project downlords-faf-client by FAForever.
the class ReplayDetailController method setReplay.
public void setReplay(Replay replay) {
this.replay = replay;
replayIdField.setText(i18n.get("game.idFormat", replay.getId()));
titleLabel.setText(replay.getTitle());
dateLabel.setText(timeService.asDate(replay.getStartTime()));
timeLabel.setText(timeService.asShortTime(replay.getStartTime()));
Optional<MapBean> optionalMap = Optional.ofNullable(replay.getMap());
if (optionalMap.isPresent()) {
MapBean map = optionalMap.get();
Image image = mapService.loadPreview(map, PreviewSize.LARGE);
mapThumbnailImageView.setImage(image);
onMapLabel.setText(i18n.get("game.onMapFormat", map.getDisplayName()));
} else {
onMapLabel.setText(i18n.get("game.onUnknownMap"));
}
Temporal endTime = replay.getEndTime();
if (endTime != null) {
durationLabel.setText(timeService.shortDuration(Duration.between(replay.getStartTime(), endTime)));
} else {
durationLabel.setVisible(false);
}
modLabel.setText(replay.getFeaturedMod().getDisplayName());
playerCountLabel.setText(i18n.number(replay.getTeams().values().stream().mapToInt(List::size).sum()));
qualityLabel.setText(i18n.get("percentage", (int) ratingService.calculateQuality(replay) * 100));
replay.getTeamPlayerStats().values().stream().flatMapToInt(playerStats -> playerStats.stream().mapToInt(stats -> RatingUtil.getRating(stats.getBeforeMean(), stats.getBeforeDeviation()))).average().ifPresent(averageRating -> ratingLabel.setText(i18n.number((int) averageRating)));
replayService.getSize(replay.getId()).thenAccept(replaySize -> Platform.runLater(() -> {
if (replaySize > -1) {
String humanReadableSize = Bytes.formatSize(replaySize, i18n.getUserSpecificLocale());
downloadMoreInfoButton.setText(i18n.get("game.downloadMoreInfo", humanReadableSize));
watchButton.setText(i18n.get("game.watchButtonFormat", humanReadableSize));
} else {
downloadMoreInfoButton.setText(i18n.get("game.replayFileMissing"));
downloadMoreInfoButton.setDisable(true);
watchButton.setText(i18n.get("game.replayFileMissing"));
watchButton.setDisable(true);
}
}));
Optional<Player> currentPlayer = playerService.getCurrentPlayer();
Assert.state(currentPlayer.isPresent(), "No user is logged in");
reviewsController.setOnSendReviewListener(this::onSendReview);
reviewsController.setOnDeleteReviewListener(this::onDeleteReview);
reviewsController.setReviews(replay.getReviews());
reviewsController.setOwnReview(replay.getReviews().stream().filter(review -> review.getPlayer().equals(currentPlayer.get())).findFirst());
// These items are initially empty but will be populated in #onDownloadMoreInfoClicked()
optionsTable.setItems(replay.getGameOptions());
chatTable.setItems(replay.getChatMessages());
teams = replay.getTeamPlayerStats();
populateTeamsContainer();
}
use of com.faforever.client.replay.Replay.PlayerStats in project downlords-faf-client by FAForever.
the class ReplayDetailController method populateTeamsContainer.
private void populateTeamsContainer() {
if (!replay.getValidity().equals(Validity.VALID)) {
showRatingChangeButton.setDisable(true);
showRatingChangeButton.setText(i18n.get("game.notValid"));
} else if (!replayService.replayChangedRating(replay)) {
showRatingChangeButton.setDisable(true);
showRatingChangeButton.setText(i18n.get("game.notRatedYet"));
}
Map<Integer, PlayerStats> statsByPlayerId = teams.values().stream().flatMap(Collection::stream).collect(Collectors.toMap(PlayerStats::getPlayerId, Function.identity()));
Platform.runLater(() -> teams.forEach((team, value) -> {
List<Integer> playerIds = value.stream().map(PlayerStats::getPlayerId).collect(Collectors.toList());
TeamCardController controller = uiService.loadFxml("theme/team_card.fxml");
teamCardControllers.add(controller);
playerService.getPlayersByIds(playerIds).thenAccept(players -> controller.setPlayersInTeam(team, players, player -> {
PlayerStats playerStats = statsByPlayerId.get(player.getId());
return new Rating(playerStats.getBeforeMean(), playerStats.getBeforeDeviation());
}, RatingType.EXACT));
teamsContainer.getChildren().add(controller.getRoot());
}));
}
Aggregations