Search in sources :

Example 1 with Sets

use of mage.cards.Sets in project mage by magefree.

the class MageBook method updateCardStats.

private void updateCardStats(String setCode, boolean isCardsShow) {
    // sets do not have total cards number, it's a workaround
    ExpansionSet set = Sets.findSet(setCode);
    if (set != null) {
        setCaption.setText(set.getCode() + " - " + set.getName());
    } else {
        setCaption.setText("ERROR");
        setInfo.setText("ERROR");
        return;
    }
    if (!isCardsShow) {
        // tokens or emblems, stats not need
        setInfo.setText("");
        return;
    }
    // cards stats
    List<Integer> haveNumbers = set.getSetCardInfo().stream().map(ExpansionSet.SetCardInfo::getCardNumberAsInt).collect(Collectors.toList());
    int startNumber = haveNumbers.stream().min(Integer::compareTo).orElse(9999);
    int endNumber = haveNumbers.stream().max(Integer::compareTo).orElse(0);
    // second run for empty numbers
    int countHave = haveNumbers.size();
    int countNotHave = IntStream.range(startNumber, endNumber + 1).map(x -> haveNumbers.contains(x) ? 0 : 1).sum();
    // result
    setInfo.setText(String.format("%d cards of %d are available", countHave, countHave + countNotHave));
    if (countNotHave > 0) {
        setInfo.setForeground(new Color(150, 0, 0));
    } else {
        setInfo.setForeground(jLayeredPane.getForeground());
    }
}
Also used : IntStream(java.util.stream.IntStream) ManaSymbols(org.mage.card.arcane.ManaSymbols) DownloadPicturesService.getTokenCardUrls(org.mage.plugins.card.images.DownloadPicturesService.getTokenCardUrls) MageFrame(mage.client.MageFrame) CardCriteria(mage.cards.repository.CardCriteria) ImagePanel(mage.components.ImagePanel) Sets(mage.cards.Sets) AudioManager(mage.client.util.audio.AudioManager) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings) Constructor(java.lang.reflect.Constructor) ClientDefaultSettings(mage.client.util.ClientDefaultSettings) ArrayList(java.util.ArrayList) RateCard(mage.game.draft.RateCard) mage.view(mage.view) Logger(org.apache.log4j.Logger) ExpansionSet(mage.cards.ExpansionSet) NaturalOrderCardNumberComparator(mage.client.util.NaturalOrderCardNumberComparator) ImagePanelStyle(mage.components.ImagePanelStyle) PermanentToken(mage.game.permanent.PermanentToken) Locale(java.util.Locale) ImageIO(javax.imageio.ImageIO) MageCard(mage.cards.MageCard) ConstructedFormats(mage.client.util.sets.ConstructedFormats) Emblem(mage.game.command.Emblem) ImageHelper(mage.client.util.ImageHelper) BufferedImage(java.awt.image.BufferedImage) CardDimensions(mage.cards.CardDimensions) Plane(mage.game.command.Plane) CardDownloadData(org.mage.plugins.card.images.CardDownloadData) UUID(java.util.UUID) Math.min(java.lang.Math.min) CardRepository(mage.cards.repository.CardRepository) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HoverButton(mage.client.components.HoverButton) java.awt(java.awt) PreferencesDialog(mage.client.dialog.PreferencesDialog) Plugins(mage.client.plugins.impl.Plugins) Dungeon(mage.game.command.Dungeon) List(java.util.List) Token(mage.game.permanent.token.Token) BigCard(mage.client.cards.BigCard) CardInfo(mage.cards.repository.CardInfo) ExpansionRepository(mage.cards.repository.ExpansionRepository) javax.swing(javax.swing) InputStream(java.io.InputStream) ExpansionSet(mage.cards.ExpansionSet)

Aggregations

java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 Math.min (java.lang.Math.min)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 ImageIO (javax.imageio.ImageIO)1 javax.swing (javax.swing)1 CardIconRenderSettings (mage.abilities.icon.CardIconRenderSettings)1 CardDimensions (mage.cards.CardDimensions)1 ExpansionSet (mage.cards.ExpansionSet)1 MageCard (mage.cards.MageCard)1 Sets (mage.cards.Sets)1