use of com.faforever.client.vault.review.Review 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.vault.review.Review in project downlords-faf-client by FAForever.
the class MapBean method fromMapDto.
public static MapBean fromMapDto(com.faforever.client.api.dto.Map map) {
MapVersion mapVersion = map.getLatestVersion();
MapBean mapBean = new MapBean();
Optional.ofNullable(map.getAuthor()).ifPresent(author -> mapBean.setAuthor(author.getLogin()));
mapBean.setDescription(mapVersion.getDescription());
mapBean.setDisplayName(map.getDisplayName());
mapBean.setFolderName(mapVersion.getFolderName());
mapBean.setSize(MapSize.valueOf(mapVersion.getWidth(), mapVersion.getHeight()));
mapBean.setDownloads(map.getStatistics().getDownloads());
mapBean.setId(mapVersion.getId());
mapBean.setPlayers(mapVersion.getMaxPlayers());
mapBean.setVersion(mapVersion.getVersion());
mapBean.setDownloadUrl(mapVersion.getDownloadUrl());
mapBean.setSmallThumbnailUrl(mapVersion.getThumbnailUrlSmall());
mapBean.setLargeThumbnailUrl(mapVersion.getThumbnailUrlLarge());
mapBean.setCreateTime(mapVersion.getCreateTime().toLocalDateTime());
mapBean.setNumberOfPlays(map.getStatistics().getPlays());
mapBean.getReviews().setAll(map.getVersions().stream().filter(v -> v.getReviews() != null).flatMap(v -> v.getReviews().parallelStream()).map(Review::fromDto).collect(Collectors.toList()));
return mapBean;
}
use of com.faforever.client.vault.review.Review in project downlords-faf-client by FAForever.
the class ModCardController method setModVersion.
public void setModVersion(ModVersion modVersion) {
this.modVersion = modVersion;
thumbnailImageView.setImage(modService.loadThumbnail(modVersion));
nameLabel.setText(modVersion.getDisplayName());
authorLabel.setText(modVersion.getUploader());
createdLabel.setText(timeService.asDate(modVersion.getCreateTime()));
typeLabel.setText(modVersion.getModType() != null ? i18n.get(modVersion.getModType().getI18nKey()) : "");
ObservableList<ModVersion> installedModVersions = modService.getInstalledModVersions();
synchronized (installedModVersions) {
installedModVersions.addListener(new WeakListChangeListener<>(installStatusChangeListener));
}
ObservableList<Review> reviews = modVersion.getReviews();
reviews.addListener(new WeakInvalidationListener(reviewsChangedListener));
reviewsChangedListener.invalidated(reviews);
}
use of com.faforever.client.vault.review.Review in project downlords-faf-client by FAForever.
the class FafServiceImplTest method createModVersion.
@Test
public void createModVersion() throws Exception {
Review review = createReview(null, "something", 3, 42);
when(fafApiAccessor.createModVersionReview(any())).thenReturn((ModVersionReview) new ModVersionReview().setPlayer(player()).setId("1").setScore((byte) 1));
instance.saveModVersionReview(review, "5");
verify(fafApiAccessor).createModVersionReview(any());
}
use of com.faforever.client.vault.review.Review in project downlords-faf-client by FAForever.
the class FafServiceImplTest method createReview.
private Review createReview(String id, String text, int rating, Integer playerId) {
Review review = new Review();
review.setId(id);
review.setText(text);
review.setScore(rating);
Optional.ofNullable(playerId).map(String::valueOf).ifPresent(s -> {
com.faforever.client.player.Player player = new com.faforever.client.player.Player(s);
player.setId(playerId);
review.setPlayer(player);
});
return review;
}
Aggregations