|
7 | 7 | import com.faforever.client.domain.api.Map; |
8 | 8 | import com.faforever.client.domain.api.MapType; |
9 | 9 | import com.faforever.client.domain.api.MapVersion; |
| 10 | +import com.faforever.client.domain.api.MatchmakerQueueMapPool; |
10 | 11 | import com.faforever.client.domain.server.MatchmakerQueueInfo; |
11 | 12 | import com.faforever.client.domain.server.PlayerInfo; |
12 | 13 | import com.faforever.client.exception.AssetLoadException; |
|
16 | 17 | import com.faforever.client.i18n.I18n; |
17 | 18 | import com.faforever.client.map.generator.MapGeneratorService; |
18 | 19 | import com.faforever.client.mapstruct.MapMapper; |
| 20 | +import com.faforever.client.mapstruct.MatchmakerMapper; |
19 | 21 | import com.faforever.client.notification.NotificationService; |
20 | 22 | import com.faforever.client.player.PlayerService; |
21 | 23 | import com.faforever.client.preferences.ForgedAlliancePrefs; |
|
34 | 36 | import com.faforever.commons.api.elide.ElideNavigator; |
35 | 37 | import com.faforever.commons.api.elide.ElideNavigatorOnCollection; |
36 | 38 | import com.faforever.commons.api.elide.ElideNavigatorOnId; |
37 | | -import com.github.rutledgepaulv.qbuilders.builders.QBuilder; |
38 | | -import com.github.rutledgepaulv.qbuilders.conditions.Condition; |
39 | | -import com.github.rutledgepaulv.qbuilders.visitors.RSQLVisitor; |
40 | 39 | import com.google.common.annotations.VisibleForTesting; |
41 | 40 | import javafx.beans.InvalidationListener; |
42 | 41 | import javafx.beans.WeakInvalidationListener; |
|
64 | 63 | import org.springframework.cache.annotation.Cacheable; |
65 | 64 | import org.springframework.context.annotation.Lazy; |
66 | 65 | import org.springframework.stereotype.Service; |
67 | | -import reactor.core.publisher.Flux; |
68 | 66 | import reactor.core.publisher.Mono; |
69 | 67 | import reactor.util.function.Tuple2; |
70 | 68 | import reactor.util.retry.Retry; |
|
80 | 78 | import java.nio.file.WatchService; |
81 | 79 | import java.time.Duration; |
82 | 80 | import java.util.ArrayList; |
83 | | -import java.util.Comparator; |
84 | 81 | import java.util.List; |
85 | 82 | import java.util.Locale; |
86 | 83 | import java.util.Optional; |
87 | 84 | import java.util.Set; |
88 | 85 | import java.util.concurrent.CompletableFuture; |
89 | 86 | import java.util.regex.Pattern; |
| 87 | +import java.util.stream.Collectors; |
90 | 88 | import java.util.stream.Stream; |
91 | 89 |
|
92 | 90 | import static com.faforever.client.util.LuaUtil.loadFile; |
@@ -117,6 +115,7 @@ public class MapService implements InitializingBean, DisposableBean { |
117 | 115 | private final MapGeneratorService mapGeneratorService; |
118 | 116 | private final PlayerService playerService; |
119 | 117 | private final MapMapper mapMapper; |
| 118 | + private final MatchmakerMapper matchmakerMapper; |
120 | 119 | private final FileSizeReader fileSizeReader; |
121 | 120 | private final ClientProperties clientProperties; |
122 | 121 | private final ForgedAlliancePrefs forgedAlliancePrefs; |
@@ -626,38 +625,18 @@ public Mono<Void> downloadAllMatchmakerMaps(MatchmakerQueueInfo matchmakerQueue) |
626 | 625 | } |
627 | 626 |
|
628 | 627 | @Cacheable(value = CacheNames.MATCHMAKER_POOLS, sync = true) |
629 | | - @SuppressWarnings({"rawtypes", "unchecked"}) |
630 | | - public Mono<Tuple2<List<MapVersion>, Integer>> getMatchmakerMapsWithPageCount(MatchmakerQueueInfo matchmakerQueue, |
631 | | - int count, int page) { |
632 | | - PlayerInfo player = playerService.getCurrentPlayer(); |
633 | | - double rating = Optional.ofNullable(player.getLeaderboardRatings()) |
634 | | - .map(ratings -> ratings.get(matchmakerQueue.getLeaderboard().technicalName())) |
635 | | - .map(ratingBean -> ratingBean.mean() - 3 * ratingBean.deviation()) |
636 | | - .orElse(0d); |
637 | | - ElideNavigatorOnCollection<MapPoolAssignment> navigator = ElideNavigator.of(MapPoolAssignment.class).collection(); |
638 | | - List<Condition<?>> conditions = new ArrayList<>(); |
639 | | - conditions.add(qBuilder().intNum("mapPool.matchmakerQueueMapPool.matchmakerQueue.id").eq(matchmakerQueue.getId())); |
640 | | - conditions.add(qBuilder().doubleNum("mapPool.matchmakerQueueMapPool.minRating") |
641 | | - .lte(rating) |
642 | | - .or() |
643 | | - .floatNum("mapPool.matchmakerQueueMapPool.minRating") |
644 | | - .ne(null)); |
645 | | - // The api doesn't support the ne operation so we manually replace it with isnull which rsql does not support |
646 | | - String customFilter = ((String) new QBuilder().and(conditions).query(new RSQLVisitor())).replace("ex", "isnull"); |
647 | | - Flux<MapVersion> matchmakerMapsFlux = fafApiAccessor.getMany(navigator, customFilter) |
648 | | - .map(mapMapper::mapFromPoolAssignment) |
649 | | - .distinct() |
650 | | - .sort( |
651 | | - Comparator.nullsLast(Comparator.comparing(MapVersion::size)) |
652 | | - .thenComparing(Comparator.nullsLast( |
653 | | - Comparator.comparing(MapVersion::map, |
654 | | - Comparator.nullsLast( |
655 | | - Comparator.comparing( |
656 | | - Map::displayName, |
657 | | - Comparator.nullsLast( |
658 | | - String.CASE_INSENSITIVE_ORDER))))))); |
659 | | - return Mono.zip(matchmakerMapsFlux.skip((long) (page - 1) * count).take(count).collectList(), |
660 | | - matchmakerMapsFlux.count().map(size -> (int) (size - 1) / count + 1)); |
| 628 | + public Mono <java.util.Map<MatchmakerQueueMapPool, List<MapVersion>>> getMatchmakerBrackets(MatchmakerQueueInfo matchmakerQueue) { |
| 629 | + ElideNavigatorOnCollection<MapPoolAssignment> navigator = ElideNavigator |
| 630 | + .of(MapPoolAssignment.class).collection() |
| 631 | + .setFilter(qBuilder().intNum("mapPool.matchmakerQueueMapPool.matchmakerQueue.id").eq(matchmakerQueue.getId())); |
| 632 | + |
| 633 | + return fafApiAccessor.getMany(navigator) |
| 634 | + .map(matchmakerMapper::map) |
| 635 | + .collect(Collectors.groupingBy(assignment -> assignment.mapPool().mapPool(), |
| 636 | + Collectors.mapping( |
| 637 | + com.faforever.client.domain.api.MapPoolAssignment::mapVersion, |
| 638 | + Collectors.toList()))); |
| 639 | + |
661 | 640 | } |
662 | 641 |
|
663 | 642 | public Mono<Boolean> hasPlayedMap(PlayerInfo player, MapVersion mapVersion) { |
|
0 commit comments