Search in sources :

Example 6 with Review

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();
}
Also used : Button(javafx.scene.control.Button) UiService(com.faforever.client.theme.UiService) Rating(com.faforever.client.util.Rating) TimeService(com.faforever.client.util.TimeService) ScrollPane(javafx.scene.control.ScrollPane) Duration(java.time.Duration) Map(java.util.Map) TableView(javafx.scene.control.TableView) PlayerService(com.faforever.client.player.PlayerService) Pane(javafx.scene.layout.Pane) ClientProperties(com.faforever.client.config.ClientProperties) TextField(javafx.scene.control.TextField) Collection(java.util.Collection) ObservableMap(javafx.collections.ObservableMap) MapBean(com.faforever.client.map.MapBean) Collectors(java.util.stream.Collectors) Bytes(com.faforever.commons.io.Bytes) Platform(javafx.application.Platform) Player(com.faforever.client.player.Player) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Clipboard(javafx.scene.input.Clipboard) Optional(java.util.Optional) ClipboardContent(javafx.scene.input.ClipboardContent) Temporal(java.time.temporal.Temporal) Setter(lombok.Setter) PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) MouseEvent(javafx.scene.input.MouseEvent) GameOption(com.faforever.client.replay.Replay.GameOption) Function(java.util.function.Function) Scope(org.springframework.context.annotation.Scope) ChatMessage(com.faforever.client.replay.Replay.ChatMessage) TableColumn(javafx.scene.control.TableColumn) ArrayList(java.util.ArrayList) TeamCardController(com.faforever.client.game.TeamCardController) ReviewsController(com.faforever.client.vault.review.ReviewsController) StringCell(com.faforever.client.fx.StringCell) RatingUtil(com.faforever.client.util.RatingUtil) Label(javafx.scene.control.Label) Controller(com.faforever.client.fx.Controller) JavaFxUtil(com.faforever.client.fx.JavaFxUtil) Node(javafx.scene.Node) RatingType(com.faforever.client.game.RatingType) Component(org.springframework.stereotype.Component) PlayerStats(com.faforever.client.replay.Replay.PlayerStats) ImageView(javafx.scene.image.ImageView) ReviewService(com.faforever.client.vault.review.ReviewService) RatingService(com.faforever.client.rating.RatingService) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Validity(com.faforever.client.api.dto.Validity) Image(javafx.scene.image.Image) Review(com.faforever.client.vault.review.Review) Assert(org.springframework.util.Assert) Player(com.faforever.client.player.Player) MapBean(com.faforever.client.map.MapBean) Temporal(java.time.temporal.Temporal) Image(javafx.scene.image.Image)

Example 7 with Review

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;
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) MapVersion(com.faforever.client.api.dto.MapVersion) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) URL(java.net.URL) LocalDateTime(java.time.LocalDateTime) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) Observable(javafx.beans.Observable) SimpleListProperty(javafx.beans.property.SimpleListProperty) IntegerProperty(javafx.beans.property.IntegerProperty) Collectors(java.util.stream.Collectors) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Map(java.util.Map) Optional(java.util.Optional) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) ObservableList(javafx.collections.ObservableList) ListProperty(javafx.beans.property.ListProperty) StringProperty(javafx.beans.property.StringProperty) NotNull(org.jetbrains.annotations.NotNull) Review(com.faforever.client.vault.review.Review) MapVersion(com.faforever.client.api.dto.MapVersion) Review(com.faforever.client.vault.review.Review)

Example 8 with Review

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);
}
Also used : WeakInvalidationListener(javafx.beans.WeakInvalidationListener) Review(com.faforever.client.vault.review.Review)

Example 9 with Review

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());
}
Also used : ModVersionReview(com.faforever.client.api.dto.ModVersionReview) ModVersionReview(com.faforever.client.api.dto.ModVersionReview) MapVersionReview(com.faforever.client.api.dto.MapVersionReview) GameReview(com.faforever.client.api.dto.GameReview) Review(com.faforever.client.vault.review.Review) Test(org.junit.Test)

Example 10 with Review

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;
}
Also used : Player(com.faforever.client.api.dto.Player) ModVersionReview(com.faforever.client.api.dto.ModVersionReview) MapVersionReview(com.faforever.client.api.dto.MapVersionReview) GameReview(com.faforever.client.api.dto.GameReview) Review(com.faforever.client.vault.review.Review)

Aggregations

Review (com.faforever.client.vault.review.Review)10 GameReview (com.faforever.client.api.dto.GameReview)4 MapVersionReview (com.faforever.client.api.dto.MapVersionReview)4 ModVersionReview (com.faforever.client.api.dto.ModVersionReview)4 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Test (org.junit.Test)3 Controller (com.faforever.client.fx.Controller)2 I18n (com.faforever.client.i18n.I18n)2 MapBean (com.faforever.client.map.MapBean)2 MapService (com.faforever.client.map.MapService)2 PreviewSize (com.faforever.client.map.MapServiceImpl.PreviewSize)2 Player (com.faforever.client.player.Player)2 RatingService (com.faforever.client.rating.RatingService)2 RatingUtil (com.faforever.client.util.RatingUtil)2 TimeService (com.faforever.client.util.TimeService)2 Duration (java.time.Duration)2 Map (java.util.Map)2 WeakInvalidationListener (javafx.beans.WeakInvalidationListener)2 Image (javafx.scene.image.Image)2