示例#1
0
  CardCollection removeCards(
      CardCollection oldCards, Iterable<Card> cardsToRemove, TrackableProperty key) {
    if (cardsToRemove == null || oldCards == null) {
      return oldCards;
    }

    TrackableCollection<CardView> views = get(key);
    boolean needFlagAsChanged = false;
    for (Card c : cardsToRemove) {
      if (oldCards.remove(c)) {
        if (views == null) {
          set(key, null);
        } else if (views.remove(c.getView())) {
          if (views.isEmpty()) {
            views = null;
            set(key, null); // avoid keeping around an empty collection
            needFlagAsChanged = false; // doesn't need to be flagged a second time
          } else {
            needFlagAsChanged = true;
          }
        }
        if (oldCards.isEmpty()) {
          oldCards = null; // avoid keeping around an empty collection
          break;
        }
      }
    }
    if (needFlagAsChanged) {
      flagAsChanged(key);
    }
    return oldCards;
  }
示例#2
0
  CardCollection addCards(
      CardCollection oldCards, Iterable<Card> cardsToAdd, TrackableProperty key) {
    if (cardsToAdd == null) {
      return oldCards;
    }

    TrackableCollection<CardView> views = get(key);
    if (oldCards == null) {
      oldCards = new CardCollection();
    }
    boolean needFlagAsChanged = false;
    for (Card c : cardsToAdd) {
      if (c != null && oldCards.add(c)) {
        if (views == null) {
          views = new TrackableCollection<CardView>();
          views.add(c.getView());
          set(key, views);
        } else if (views.add(c.getView())) {
          needFlagAsChanged = true;
        }
      }
    }
    if (needFlagAsChanged) {
      flagAsChanged(key);
    }
    return oldCards;
  }
示例#3
0
 public static TrackableCollection<CardView> getCollection(Iterable<Card> cards) {
   if (cards == null) {
     return null;
   }
   TrackableCollection<CardView> collection = new TrackableCollection<CardView>();
   for (Card c : cards) {
     if (c.getCardForUi() == c) { // only add cards that match their card for UI
       collection.add(c.getView());
     }
   }
   return collection;
 }
示例#4
0
 void updateType(CardState c) {
   CardTypeView type = c.getType();
   if (CardView.this.getCurrentState() == this) {
     Card card = c.getCard();
     if (card != null) {
       type =
           type.getTypeWithChanges(
               card.getChangedCardTypes()); // TODO: find a better way to do this
       updateRulesText(card.getRules(), type);
     }
   }
   set(TrackableProperty.Type, type);
 }
示例#5
0
 void updateCounters(Card c) {
   set(TrackableProperty.Counters, c.getCounters());
   CardStateView state = getCurrentState();
   state.updatePower(c);
   state.updateToughness(c);
   state.updateLoyalty(c);
 }
示例#6
0
 public static CardStateView getState(Card c, CardStateName state) {
   if (c == null) {
     return null;
   }
   CardState s = c.getState(state);
   return s == null ? null : s.getView();
 }
示例#7
0
 void updateKeywords(Card c, CardState state) {
   set(TrackableProperty.HasDeathtouch, c.hasKeyword("Deathtouch", state));
   set(TrackableProperty.HasHaste, c.hasKeyword("Haste", state));
   set(TrackableProperty.HasInfect, c.hasKeyword("Infect", state));
   set(TrackableProperty.HasStorm, c.hasKeyword("Storm", state));
   set(TrackableProperty.HasTrample, c.hasKeyword("Trample", state));
   set(TrackableProperty.YouMayLook, c.hasKeyword("You may look at this card."));
   set(TrackableProperty.OpponentMayLook, c.hasKeyword("Your opponent may look at this card."));
   set(
       TrackableProperty.BlockAdditional,
       c.getAmountOfKeyword("CARDNAME can block an additional creature.", state));
   updateAbilityText(c, state);
 }
示例#8
0
  CardCollection addCard(CardCollection oldCards, Card cardToAdd, TrackableProperty key) {
    if (cardToAdd == null) {
      return oldCards;
    }

    if (oldCards == null) {
      oldCards = new CardCollection();
    }
    if (oldCards.add(cardToAdd)) {
      TrackableCollection<CardView> views = get(key);
      if (views == null) {
        views = new TrackableCollection<CardView>();
        views.add(cardToAdd.getView());
        ;
        set(key, views);
      } else if (views.add(cardToAdd.getView())) {
        flagAsChanged(key);
      }
    }
    return oldCards;
  }
示例#9
0
 void updateRemembered(Card c) {
   if (c.getRemembered() == null) {
     set(TrackableProperty.Remembered, null);
     return;
   }
   StringBuilder sb = new StringBuilder();
   sb.append("\r\nRemembered: \r\n");
   for (final Object o : c.getRemembered()) {
     if (o instanceof Card) {
       final Card card = (Card) o;
       if (card.isFaceDown()) {
         sb.append("Face Down");
         // face-down cards don't show unique number to avoid cheating
       } else {
         sb.append(card.getName());
         sb.append(" (");
         sb.append(card.getId());
         sb.append(")");
       }
     } else if (o != null) {
       sb.append(o.toString());
     }
     sb.append("\r\n");
   }
   set(TrackableProperty.Remembered, sb.toString());
 }
示例#10
0
 void updateToughness(Card c) {
   if (c.getCurrentState().getView() == this || c.getAlternateState() == null) {
     set(TrackableProperty.Toughness, c.getNetToughness());
   } else {
     set(
         TrackableProperty.Toughness,
         c.getNetToughness() - c.getBaseToughness() + c.getAlternateState().getBaseToughness());
   }
 }
示例#11
0
 void updatePower(Card c) {
   if (c.getCurrentState().getView() == this || c.getAlternateState() == null) {
     set(TrackableProperty.Power, c.getNetPower());
   } else {
     set(
         TrackableProperty.Power,
         c.getNetPower() - c.getBasePower() + c.getAlternateState().getBasePower());
   }
 }
示例#12
0
  CardCollection removeCard(CardCollection oldCards, Card cardToRemove, TrackableProperty key) {
    if (cardToRemove == null || oldCards == null) {
      return oldCards;
    }

    if (oldCards.remove(cardToRemove)) {
      TrackableCollection<CardView> views = get(key);
      if (views == null) {
        set(key, null);
      } else if (views.remove(cardToRemove.getView())) {
        if (views.isEmpty()) {
          set(key, null); // avoid keeping around an empty collection
        } else {
          flagAsChanged(key);
        }
      }
      if (oldCards.isEmpty()) {
        oldCards = null; // avoid keeping around an empty collection
      }
    }
    return oldCards;
  }
示例#13
0
  void updateState(Card c) {
    updateName(c);

    boolean isSplitCard = c.isSplitCard();
    set(TrackableProperty.Cloned, c.isCloned());
    set(TrackableProperty.SplitCard, isSplitCard);
    set(TrackableProperty.FlipCard, c.isFlipCard());

    CardStateView cloner = CardView.getState(c, CardStateName.Cloner);
    set(
        TrackableProperty.Cloner,
        cloner == null ? null : cloner.getName() + " (" + cloner.getId() + ")");

    CardState currentState = c.getCurrentState();
    if (isSplitCard) {
      if (c.getCurrentStateName() != CardStateName.LeftSplit
          && c.getCurrentStateName() != CardStateName.RightSplit) {
        currentState = c.getState(CardStateName.LeftSplit);
      }
    }

    CardStateView currentStateView = currentState.getView();
    if (getCurrentState() != currentStateView) {
      set(TrackableProperty.CurrentState, currentStateView);
      currentStateView.updatePower(
          c); // ensure power, toughness, and loyalty updated when current state changes
      currentStateView.updateToughness(c);
      currentStateView.updateLoyalty(c);

      // update the color only while in Game
      if (c.getGame() != null) {
        currentStateView.updateColors(currentState);
      }
    }
    currentState
        .getView()
        .updateKeywords(c, currentState); // update keywords even if state doesn't change

    CardState alternateState =
        isSplitCard ? c.getState(CardStateName.RightSplit) : c.getAlternateState();
    if (alternateState == null) {
      set(TrackableProperty.AlternateState, null);
    } else {
      CardStateView alternateStateView = alternateState.getView();
      if (getAlternateState() != alternateStateView) {
        set(TrackableProperty.AlternateState, alternateStateView);
        alternateStateView.updatePower(
            c); // ensure power, toughness, and loyalty updated when current state changes
        alternateStateView.updateToughness(c);
        alternateStateView.updateLoyalty(c);

        // update the color only while in Game
        if (c.getGame() != null) {
          alternateStateView.updateColors(alternateState);
        }
      }
      alternateState.getView().updateKeywords(c, alternateState);
    }
  }
示例#14
0
 void updateNonAbilityText(Card c) {
   set(TrackableProperty.NonAbilityText, c.getNonAbilityText());
 }
示例#15
0
 void updateChangedTypes(Card c) {
   set(TrackableProperty.ChangedTypes, c.getChangedTextTypeWords());
 }
示例#16
0
 void updateChangedColorWords(Card c) {
   set(TrackableProperty.ChangedColorWords, c.getChangedTextColorWords());
 }
示例#17
0
 void updateEnchanting(Card c) {
   set(TrackableProperty.Enchanting, GameEntityView.get(c.getEnchanting()));
 }
示例#18
0
 void updateShieldCount(Card c) {
   set(TrackableProperty.ShieldCount, c.getShieldCount());
 }
示例#19
0
 void updateColors(Card c) {
   set(TrackableProperty.Colors, c.determineColor());
 }
示例#20
0
 void updateChosenType(Card c) {
   set(TrackableProperty.ChosenType, c.getChosenType());
 }
示例#21
0
 void updateChosenDirection(Card c) {
   set(TrackableProperty.ChosenDirection, c.getChosenDirection());
 }
示例#22
0
 void updateChosenPlayer(Card c) {
   set(TrackableProperty.ChosenPlayer, PlayerView.get(c.getChosenPlayer()));
 }
示例#23
0
 public static CardView get(Card c) {
   return c == null ? null : c.getView();
 }
示例#24
0
 void updateChosenColors(Card c) {
   set(TrackableProperty.ChosenColors, c.getChosenColors());
 }
示例#25
0
 void updateImageKey(Card c) {
   set(TrackableProperty.ImageKey, c.getImageKey());
 }
示例#26
0
 void updateNamedCard(Card c) {
   set(TrackableProperty.NamedCard, c.getNamedCard());
 }
示例#27
0
 void updateOracleText(Card c) {
   set(TrackableProperty.OracleText, c.getOracleText().replace("\\n", "\r\n").trim());
 }
示例#28
0
 public static CardView getCardForUi(IPaperCard pc) {
   return Card.getCardForUi(pc).getView();
 }
示例#29
0
 void updateDamage(Card c) {
   set(TrackableProperty.Damage, c.getDamage());
 }
示例#30
0
 void updateAssignedDamage(Card c) {
   set(TrackableProperty.AssignedDamage, c.getTotalAssignedDamage());
 }