Example #1
0
 @Override
 public void loadCards(
     CardsView showCards, SortSetting sortSetting, BigCard bigCard, UUID gameId, boolean merge) {
   boolean drawImage = showCards.size() <= MAX_IMAGES;
   this.bigCard = bigCard;
   this.gameId = gameId;
   if (merge) {
     for (CardView card : showCards.values()) {
       if (!cards.containsKey(card.getId())) {
         addCard(card, bigCard, gameId, drawImage);
       }
     }
     for (Iterator<Entry<UUID, MageCard>> i = cards.entrySet().iterator(); i.hasNext(); ) {
       Entry<UUID, MageCard> entry = i.next();
       if (!showCards.containsKey(entry.getKey())) {
         removeCardImg(entry.getKey());
         i.remove();
       }
     }
   } else {
     this.clearCards();
     for (CardView card : showCards.values()) {
       addCard(card, bigCard, gameId, drawImage);
     }
   }
   // System.gc();
   drawCards(sortSetting);
   this.setVisible(true);
 }
Example #2
0
  @Override
  public void loadCards(
      CardsView showCards, SortSetting sortSetting, BigCard bigCard, UUID gameId, boolean merge) {
    if (this.sortSetting == null) {
      this.sortSetting = sortSetting;
    }
    this.bigCard = bigCard;
    this.gameId = gameId;
    int landCount = 0;
    int creatureCount = 0;
    int instantCount = 0;
    int sorceryCount = 0;
    int enchantmentCount = 0;
    int artifactCount = 0;
    if (!merge) {
      this.clearCards();
      for (CardView card : showCards.values()) {
        addCard(card, bigCard, gameId);
      }
    } else {
      for (CardView card : showCards.values()) {
        if (!cards.containsKey(card.getId())) {
          addCard(card, bigCard, gameId);
        }
        if (updateCountsCallback != null) {
          if (card.getCardTypes().contains(CardType.LAND)) {
            landCount++;
          }
          if (card.getCardTypes().contains(CardType.CREATURE)) {
            creatureCount++;
          }
          if (card.getCardTypes().contains(CardType.INSTANT)) {
            instantCount++;
          }
          if (card.getCardTypes().contains(CardType.SORCERY)) {
            sorceryCount++;
          }
          if (card.getCardTypes().contains(CardType.ENCHANTMENT)) {
            enchantmentCount++;
          }
          if (card.getCardTypes().contains(CardType.ARTIFACT)) {
            artifactCount++;
          }
        }
      }

      // no easy logic for merge :)
      for (Iterator<Entry<UUID, CardView>> i = cards.entrySet().iterator(); i.hasNext(); ) {
        Entry<UUID, CardView> entry = i.next();
        if (!showCards.containsKey(entry.getKey())) {
          i.remove();
          if (displayNoCopies) {
            String key =
                entry.getValue().getName()
                    + entry.getValue().getExpansionSetCode()
                    + entry.getValue().getCardNumber();
            if (cardsNoCopies.containsKey(key)) {
              Integer count = cardsNoCopies.get(key);
              count--;
              if (count > 0) {
                cardsNoCopies.put(key, count);
              } else {
                cardsNoCopies.remove(key);
              }
              for (int j = 0; j < view.size(); j++) {
                CardView cv = view.get(j);
                if (cv.getId().equals(entry.getValue().getId())) {
                  if (count > 0) {
                    // replace by another card with the same name+setCode
                    String key1 = cv.getName() + cv.getExpansionSetCode() + cv.getCardNumber();
                    for (CardView cardView : cards.values()) {
                      String key2 =
                          cardView.getName()
                              + cardView.getExpansionSetCode()
                              + cardView.getCardNumber();
                      if ((key1).equals(key2)) {
                        view.set(j, cardView);
                        break;
                      }
                    }
                  } else {
                    view.remove(j);
                  }
                  break;
                }
              }
            }
          } else {
            for (CardView cv : view) {
              if (cv.getId().equals(entry.getKey())) {
                view.remove(cv);
                break;
              }
            }
          }
        }
      }

      if (updateCountsCallback != null) {
        updateCountsCallback.update(
            cards.size(),
            creatureCount,
            landCount,
            sorceryCount,
            instantCount,
            enchantmentCount,
            artifactCount);
      }
    }

    sort(this.sortSetting.getSortIndex(), this.sortSetting.isAscending());
    drawCards(sortSetting);
  }