use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.
the class ClientService method toPlayerInformationResponse.
private PlayerResponse toPlayerInformationResponse(Player player) {
Optional<PlayerResponse.Player.Avatar> avatar = player.getAvailableAvatars().stream().filter(AvatarAssociation::isSelected).findFirst().map(association -> {
com.faforever.server.entity.Avatar avatarEntity = association.getAvatar();
return new PlayerResponse.Player.Avatar(avatarEntity.getUrl(), avatarEntity.getDescription());
});
Optional<Rating> globalRating = Optional.ofNullable(player.getGlobalRating()).map(rating -> new Rating(rating.getMean(), rating.getDeviation()));
Optional<Rating> ladder1v1Rating = Optional.ofNullable(player.getLadder1v1Rating()).map(rating -> new Rating(rating.getMean(), rating.getDeviation()));
return new PlayerResponse(player.getId(), player.getLogin(), player.getCountry(), new PlayerResponse.Player(globalRating.orElse(null), ladder1v1Rating.orElse(null), Optional.ofNullable(player.getGlobalRating()).map(GlobalRating::getNumGames).orElse(0), avatar.orElse(null), Optional.ofNullable(player.getClan()).map(Clan::getTag).orElse(null)));
}
use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.
the class V2ServerMessageTransformerTest method player.
@Test
public void player() throws Exception {
String response = instance.transform(new PlayerResponse(1, "A", "CH", new PlayerResponse.Player(new Rating(900, 120), new Rating(600, 50), 12, new Avatar("http://localhost/avatar.png", "Avatar"), "AA")));
assertThat(response, is("{\"data\":{\"playerId\":1,\"username\":\"A\",\"country\":\"CH\",\"player\":{\"globalRating\":{\"mean\":900.0,\"deviation\":120.0},\"ladder1v1Rating\":{\"mean\":600.0,\"deviation\":50.0},\"numberOfGames\":12,\"avatar\":{\"url\":\"http://localhost/avatar.png\",\"description\":\"Avatar\"},\"clanTag\":\"AA\"}},\"type\":\"player\"}"));
}
use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.
the class V2ServerMessageTransformerTest method loginDetails.
@Test
public void loginDetails() throws Exception {
String response = instance.transform(new LoginDetailsResponse(new PlayerResponse(1, "A", "CH", new PlayerResponse.Player(new Rating(900, 120), new Rating(600, 50), 12, new Avatar("http://localhost/avatar.png", "Avatar"), "AA"))));
assertThat(response, is("{\"data\":{\"playerId\":1,\"username\":\"A\",\"country\":\"CH\",\"player\":{\"globalRating\":{\"mean\":900.0,\"deviation\":120.0},\"ladder1v1Rating\":{\"mean\":600.0,\"deviation\":50.0},\"numberOfGames\":12,\"avatar\":{\"url\":\"http://localhost/avatar.png\",\"description\":\"Avatar\"},\"clanTag\":\"AA\"}},\"type\":\"loginDetails\"}"));
}
use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.
the class LoginDetailsServerMessageTransformerTest method transformFull.
@Test
@SuppressWarnings("unchecked")
public void transformFull() throws Exception {
Map<String, Serializable> result = LoginDetailsResponseTransformer.INSTANCE.transform(new LoginDetailsResponse(new PlayerResponse(1, TEST_USERNAME, "CH", new PlayerResponse.Player(new Rating(1200d, 200d), new Rating(900d, 100d), 12, new Avatar("http://example.com", "Tooltip"), "FOO"))));
assertThat(result.get("command"), is("welcome"));
assertThat(result.get("id"), is(1));
assertThat(result.get("login"), is(TEST_USERNAME));
Map<String, Object> me = (Map<String, Object>) result.get("me");
assertThat(me.get("id"), is(1));
assertThat(me.get("login"), is(TEST_USERNAME));
assertThat(me.get("login"), is(TEST_USERNAME));
assertThat(me.get("global_rating"), is(new double[] { 1200, 200 }));
assertThat(me.get("ladder_rating"), is(new double[] { 900, 100 }));
assertThat(me.get("number_of_games"), is(12));
Map<String, Serializable> avatarMap = (Map<String, Serializable>) me.get("avatar");
assertThat(avatarMap.get("url"), is("http://example.com"));
assertThat(avatarMap.get("tooltip"), is("Tooltip"));
assertThat(me.get("country"), is("CH"));
assertThat(me.get("clan"), is("FOO"));
}
use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.
the class LoginDetailsServerMessageTransformerTest method transformHandleLadder1v1RatingNull.
@Test
@SuppressWarnings("unchecked")
public void transformHandleLadder1v1RatingNull() throws Exception {
Map<String, Serializable> result = LoginDetailsResponseTransformer.INSTANCE.transform(new LoginDetailsResponse(new PlayerResponse(1, TEST_USERNAME, "CH", new PlayerResponse.Player(new Rating(900d, 100d), null, 12, new Avatar("http://example.com", "Tooltip"), "FOO"))));
Map<String, Object> me = (Map<String, Object>) result.get("me");
assertThat(me.get("ladder_rating"), is(new double[2]));
}
Aggregations