Exemplo n.º 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;
  }
Exemplo n.º 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;
  }
Exemplo n.º 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;
 }
Exemplo n.º 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);
 }
Exemplo n.º 5
0
 void updateCounters(Card c) {
   set(TrackableProperty.Counters, c.getCounters());
   CardStateView state = getCurrentState();
   state.updatePower(c);
   state.updateToughness(c);
   state.updateLoyalty(c);
 }
Exemplo n.º 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();
 }
Exemplo n.º 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);
 }
Exemplo n.º 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;
  }
Exemplo n.º 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());
 }
Exemplo n.º 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());
   }
 }
Exemplo n.º 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());
   }
 }
Exemplo n.º 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;
  }
Exemplo n.º 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);
    }
  }
Exemplo n.º 14
0
 void updateNonAbilityText(Card c) {
   set(TrackableProperty.NonAbilityText, c.getNonAbilityText());
 }
Exemplo n.º 15
0
 void updateChangedTypes(Card c) {
   set(TrackableProperty.ChangedTypes, c.getChangedTextTypeWords());
 }
Exemplo n.º 16
0
 void updateChangedColorWords(Card c) {
   set(TrackableProperty.ChangedColorWords, c.getChangedTextColorWords());
 }
Exemplo n.º 17
0
 void updateEnchanting(Card c) {
   set(TrackableProperty.Enchanting, GameEntityView.get(c.getEnchanting()));
 }
Exemplo n.º 18
0
 void updateShieldCount(Card c) {
   set(TrackableProperty.ShieldCount, c.getShieldCount());
 }
Exemplo n.º 19
0
 void updateColors(Card c) {
   set(TrackableProperty.Colors, c.determineColor());
 }
Exemplo n.º 20
0
 void updateChosenType(Card c) {
   set(TrackableProperty.ChosenType, c.getChosenType());
 }
Exemplo n.º 21
0
 void updateChosenDirection(Card c) {
   set(TrackableProperty.ChosenDirection, c.getChosenDirection());
 }
Exemplo n.º 22
0
 void updateChosenPlayer(Card c) {
   set(TrackableProperty.ChosenPlayer, PlayerView.get(c.getChosenPlayer()));
 }
Exemplo n.º 23
0
 public static CardView get(Card c) {
   return c == null ? null : c.getView();
 }
Exemplo n.º 24
0
 void updateChosenColors(Card c) {
   set(TrackableProperty.ChosenColors, c.getChosenColors());
 }
Exemplo n.º 25
0
 void updateImageKey(Card c) {
   set(TrackableProperty.ImageKey, c.getImageKey());
 }
Exemplo n.º 26
0
 void updateNamedCard(Card c) {
   set(TrackableProperty.NamedCard, c.getNamedCard());
 }
Exemplo n.º 27
0
 void updateOracleText(Card c) {
   set(TrackableProperty.OracleText, c.getOracleText().replace("\\n", "\r\n").trim());
 }
Exemplo n.º 28
0
 public static CardView getCardForUi(IPaperCard pc) {
   return Card.getCardForUi(pc).getView();
 }
Exemplo n.º 29
0
 void updateDamage(Card c) {
   set(TrackableProperty.Damage, c.getDamage());
 }
Exemplo n.º 30
0
 void updateAssignedDamage(Card c) {
   set(TrackableProperty.AssignedDamage, c.getTotalAssignedDamage());
 }