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; }
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; }
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; }
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); }
void updateCounters(Card c) { set(TrackableProperty.Counters, c.getCounters()); CardStateView state = getCurrentState(); state.updatePower(c); state.updateToughness(c); state.updateLoyalty(c); }
public static CardStateView getState(Card c, CardStateName state) { if (c == null) { return null; } CardState s = c.getState(state); return s == null ? null : s.getView(); }
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); }
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; }
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()); }
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()); } }
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()); } }
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; }
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); } }
void updateNonAbilityText(Card c) { set(TrackableProperty.NonAbilityText, c.getNonAbilityText()); }
void updateChangedTypes(Card c) { set(TrackableProperty.ChangedTypes, c.getChangedTextTypeWords()); }
void updateChangedColorWords(Card c) { set(TrackableProperty.ChangedColorWords, c.getChangedTextColorWords()); }
void updateEnchanting(Card c) { set(TrackableProperty.Enchanting, GameEntityView.get(c.getEnchanting())); }
void updateShieldCount(Card c) { set(TrackableProperty.ShieldCount, c.getShieldCount()); }
void updateColors(Card c) { set(TrackableProperty.Colors, c.determineColor()); }
void updateChosenType(Card c) { set(TrackableProperty.ChosenType, c.getChosenType()); }
void updateChosenDirection(Card c) { set(TrackableProperty.ChosenDirection, c.getChosenDirection()); }
void updateChosenPlayer(Card c) { set(TrackableProperty.ChosenPlayer, PlayerView.get(c.getChosenPlayer())); }
public static CardView get(Card c) { return c == null ? null : c.getView(); }
void updateChosenColors(Card c) { set(TrackableProperty.ChosenColors, c.getChosenColors()); }
void updateImageKey(Card c) { set(TrackableProperty.ImageKey, c.getImageKey()); }
void updateNamedCard(Card c) { set(TrackableProperty.NamedCard, c.getNamedCard()); }
void updateOracleText(Card c) { set(TrackableProperty.OracleText, c.getOracleText().replace("\\n", "\r\n").trim()); }
public static CardView getCardForUi(IPaperCard pc) { return Card.getCardForUi(pc).getView(); }
void updateDamage(Card c) { set(TrackableProperty.Damage, c.getDamage()); }
void updateAssignedDamage(Card c) { set(TrackableProperty.AssignedDamage, c.getTotalAssignedDamage()); }