Search in sources :

Example 1 with Review

use of com.faforever.client.vault.review.Review 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 2 with Review

use of com.faforever.client.vault.review.Review in project downlords-faf-client by FAForever.

the class FafServiceImplTest method createMapVersionReview.

@Test
public void createMapVersionReview() throws Exception {
    Review review = createReview(null, "something", 3, 42);
    when(fafApiAccessor.createMapVersionReview(any())).thenReturn((MapVersionReview) new MapVersionReview().setPlayer(player()).setId("1").setScore((byte) 1));
    instance.saveMapVersionReview(review, "5");
    verify(fafApiAccessor).createMapVersionReview(any());
}
Also used : MapVersionReview(com.faforever.client.api.dto.MapVersionReview) 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 3 with Review

use of com.faforever.client.vault.review.Review in project downlords-faf-client by FAForever.

the class FafServiceImplTest method createGameReview.

@Test
public void createGameReview() throws Exception {
    Review review = createReview(null, "something", 3, 42);
    when(fafApiAccessor.createGameReview(any())).thenReturn((GameReview) new GameReview().setPlayer(player()).setId("1").setScore((byte) 1));
    instance.saveGameReview(review, 5);
    verify(fafApiAccessor).createGameReview(any());
}
Also used : 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) GameReview(com.faforever.client.api.dto.GameReview) Test(org.junit.Test)

Example 4 with Review

use of com.faforever.client.vault.review.Review in project downlords-faf-client by FAForever.

the class MapCardController method setMap.

public void setMap(MapBean map) {
    this.map = map;
    Image image;
    if (map.getSmallThumbnailUrl() != null) {
        image = mapService.loadPreview(map, PreviewSize.SMALL);
    } else {
        image = IdenticonUtil.createIdenticon(map.getId());
    }
    thumbnailImageView.setImage(image);
    nameLabel.setText(map.getDisplayName());
    authorLabel.setText(Optional.ofNullable(map.getAuthor()).orElse(i18n.get("map.unknownAuthor")));
    numberOfPlaysLabel.setText(i18n.number(map.getNumberOfPlays()));
    MapSize size = map.getSize();
    sizeLabel.setText(i18n.get("mapPreview.size", size.getWidthInKm(), size.getHeightInKm()));
    maxPlayersLabel.setText(i18n.number(map.getPlayers()));
    ObservableList<MapBean> installedMaps = mapService.getInstalledMaps();
    synchronized (installedMaps) {
        installedMaps.addListener(new WeakListChangeListener<>(installedMapsChangeListener));
    }
    ObservableList<Review> reviews = map.getReviews();
    reviews.addListener(new WeakInvalidationListener(reviewsChangedListener));
    reviewsChangedListener.invalidated(reviews);
}
Also used : WeakInvalidationListener(javafx.beans.WeakInvalidationListener) Review(com.faforever.client.vault.review.Review) Image(javafx.scene.image.Image)

Example 5 with Review

use of com.faforever.client.vault.review.Review in project downlords-faf-client by FAForever.

the class ReplayCardController method setReplay.

public void setReplay(Replay replay) {
    this.replay = replay;
    Optional<MapBean> optionalMap = Optional.ofNullable(replay.getMap());
    if (optionalMap.isPresent()) {
        MapBean map = optionalMap.get();
        Image image = mapService.loadPreview(map, PreviewSize.SMALL);
        mapThumbnailImageView.setImage(image);
        onMapLabel.setText(i18n.get("game.onMapFormat", map.getDisplayName()));
    } else {
        onMapLabel.setText(i18n.get("game.onUnknownMap"));
    }
    gameTitleLabel.setText(replay.getTitle());
    dateLabel.setText(timeService.asDate(replay.getStartTime()));
    timeLabel.setText(timeService.asShortTime(replay.getStartTime()));
    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)));
    durationLabel.setText(Optional.ofNullable(replay.getEndTime()).map(endTime -> timeService.shortDuration(Duration.between(replay.getStartTime(), endTime))).orElse(i18n.get("notAvailable")));
    String players = replay.getTeams().values().stream().map(team -> Joiner.on(i18n.get("textSeparator")).join(team)).collect(Collectors.joining(i18n.get("vsSeparator")));
    playerListLabel.setText(players);
    ObservableList<Review> reviews = replay.getReviews();
    reviews.addListener(new WeakInvalidationListener(reviewsChangedListener));
    reviewsChangedListener.invalidated(reviews);
}
Also used : PreviewSize(com.faforever.client.map.MapServiceImpl.PreviewSize) Scope(org.springframework.context.annotation.Scope) InvalidationListener(javafx.beans.InvalidationListener) Inject(javax.inject.Inject) TimeService(com.faforever.client.util.TimeService) Duration(java.time.Duration) StarsController(com.faforever.client.vault.review.StarsController) RatingUtil(com.faforever.client.util.RatingUtil) Label(javafx.scene.control.Label) Controller(com.faforever.client.fx.Controller) Node(javafx.scene.Node) MapBean(com.faforever.client.map.MapBean) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) Consumer(java.util.function.Consumer) WeakInvalidationListener(javafx.beans.WeakInvalidationListener) Component(org.springframework.stereotype.Component) List(java.util.List) ImageView(javafx.scene.image.ImageView) RatingService(com.faforever.client.rating.RatingService) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Image(javafx.scene.image.Image) Review(com.faforever.client.vault.review.Review) Joiner(com.google.common.base.Joiner) MapBean(com.faforever.client.map.MapBean) WeakInvalidationListener(javafx.beans.WeakInvalidationListener) Review(com.faforever.client.vault.review.Review) Image(javafx.scene.image.Image)

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