Search in sources :

Example 6 with AchievementDefinition

use of com.faforever.client.api.dto.AchievementDefinition in project downlords-faf-client by FAForever.

the class UserInfoWindowController method updatePlayerAchievements.

private void updatePlayerAchievements(List<? extends PlayerAchievement> playerAchievements) {
    PlayerAchievement mostRecentPlayerAchievement = null;
    ObservableList<Node> children = unlockedAchievementsContainer.getChildren();
    Platform.runLater(children::clear);
    for (PlayerAchievement playerAchievement : playerAchievements) {
        AchievementItemController achievementItemController = achievementItemById.get(playerAchievement.getAchievement().getId());
        achievementItemController.setPlayerAchievement(playerAchievement);
        if (isUnlocked(playerAchievement)) {
            Platform.runLater(() -> children.add(achievementItemController.getRoot()));
            if (mostRecentPlayerAchievement == null || playerAchievement.getUpdateTime().compareTo(mostRecentPlayerAchievement.getUpdateTime()) > 0) {
                mostRecentPlayerAchievement = playerAchievement;
            }
        }
    }
    if (mostRecentPlayerAchievement == null) {
        mostRecentAchievementPane.setVisible(false);
    } else {
        mostRecentAchievementPane.setVisible(true);
        AchievementDefinition mostRecentAchievement = achievementDefinitionById.get(mostRecentPlayerAchievement.getAchievement().getId());
        if (mostRecentAchievement == null) {
            return;
        }
        String mostRecentAchievementName = mostRecentAchievement.getName();
        String mostRecentAchievementDescription = mostRecentAchievement.getDescription();
        Platform.runLater(() -> {
            mostRecentAchievementNameLabel.setText(mostRecentAchievementName);
            mostRecentAchievementDescriptionLabel.setText(mostRecentAchievementDescription);
            mostRecentAchievementImageView.setImage(achievementService.getImage(mostRecentAchievement, UNLOCKED));
        });
    }
}
Also used : Node(javafx.scene.Node) PlayerAchievement(com.faforever.client.api.dto.PlayerAchievement) AchievementItemController(com.faforever.client.achievements.AchievementItemController) AchievementDefinition(com.faforever.client.api.dto.AchievementDefinition)

Example 7 with AchievementDefinition

use of com.faforever.client.api.dto.AchievementDefinition in project downlords-faf-client by FAForever.

the class FafApiAccessorImplTest method testGetPlayerAchievements.

@Test
@SuppressWarnings("unchecked")
public void testGetPlayerAchievements() {
    PlayerAchievement playerAchievement1 = new PlayerAchievement();
    playerAchievement1.setId("1");
    playerAchievement1.setAchievement(new AchievementDefinition().setId("1-2-3"));
    PlayerAchievement playerAchievement2 = new PlayerAchievement();
    playerAchievement2.setId("2");
    playerAchievement2.setAchievement(new AchievementDefinition().setId("2-3-4"));
    List<PlayerAchievement> result = Arrays.asList(playerAchievement1, playerAchievement2);
    when(restOperations.getForObject(anyString(), eq(List.class))).thenReturn(result).thenReturn(emptyList());
    assertThat(instance.getPlayerAchievements(123), is(result));
    verify(restOperations).getForObject("/data/playerAchievement?filter=player.id==\"123\"&page[size]=10000&page[number]=1", List.class);
}
Also used : PlayerAchievement(com.faforever.client.api.dto.PlayerAchievement) AchievementDefinition(com.faforever.client.api.dto.AchievementDefinition) Test(org.junit.Test)

Example 8 with AchievementDefinition

use of com.faforever.client.api.dto.AchievementDefinition in project downlords-faf-client by FAForever.

the class FafApiAccessorImplTest method testGetAchievementDefinition.

@Test
public void testGetAchievementDefinition() {
    AchievementDefinition achievementDefinition = new AchievementDefinition();
    achievementDefinition.setId("1-2-3");
    when(restOperations.getForObject(startsWith("/data/achievement/123"), eq(AchievementDefinition.class), anyMap())).thenReturn(achievementDefinition);
    assertThat(instance.getAchievementDefinition("123"), is(achievementDefinition));
}
Also used : AchievementDefinition(com.faforever.client.api.dto.AchievementDefinition) Test(org.junit.Test)

Example 9 with AchievementDefinition

use of com.faforever.client.api.dto.AchievementDefinition in project downlords-faf-client by FAForever.

the class AchievementServiceImplTest method testLoadAndCacheImageRevealed.

@Test
public void testLoadAndCacheImageRevealed() throws Exception {
    AchievementDefinition achievementDefinition = AchievementDefinitionBuilder.create().defaultValues().get();
    Path cacheSubDir = Paths.get("achievements").resolve(AchievementState.REVEALED.name().toLowerCase());
    instance.getImage(achievementDefinition, REVEALED);
    verify(assetService).loadAndCacheImage(new URL(achievementDefinition.getRevealedIconUrl()), cacheSubDir, null, 128, 128);
}
Also used : Path(java.nio.file.Path) URL(java.net.URL) AchievementDefinition(com.faforever.client.api.dto.AchievementDefinition) Test(org.junit.Test)

Example 10 with AchievementDefinition

use of com.faforever.client.api.dto.AchievementDefinition in project downlords-faf-client by FAForever.

the class MockFafApiAccessor method getAchievementDefinition.

@Override
public AchievementDefinition getAchievementDefinition(String achievementId) {
    AchievementDefinition achievementDefinition = new AchievementDefinition();
    achievementDefinition.setName("Mock achievement");
    achievementDefinition.setDescription("Congratulations! You read this text.");
    achievementDefinition.setType(AchievementType.STANDARD);
    return achievementDefinition;
}
Also used : AchievementDefinition(com.faforever.client.api.dto.AchievementDefinition)

Aggregations

AchievementDefinition (com.faforever.client.api.dto.AchievementDefinition)10 Test (org.junit.Test)8 PlayerAchievement (com.faforever.client.api.dto.PlayerAchievement)2 URL (java.net.URL)2 Path (java.nio.file.Path)2 Image (javafx.scene.image.Image)2 AchievementItemController (com.faforever.client.achievements.AchievementItemController)1 TransientNotification (com.faforever.client.notification.TransientNotification)1 AbstractPlainJavaFxTest (com.faforever.client.test.AbstractPlainJavaFxTest)1 Node (javafx.scene.Node)1