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<StackItemView> getCollection( Iterable<SpellAbilityStackInstance> instances) { if (instances == null) { return null; } TrackableCollection<StackItemView> collection = new TrackableCollection<StackItemView>(); for (SpellAbilityStackInstance si : instances) { collection.add(si.getView()); } return collection; }
public boolean mayPlayerLook(PlayerView pv) { TrackableCollection<PlayerView> col = get(TrackableProperty.PlayerMayLook); if (col != null && col.contains(pv)) { return true; } col = get(TrackableProperty.PlayerMayLookTemp); if (col != null && col.contains(pv)) { return true; } return false; }
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 setPlayerMayLook(Player p, boolean mayLook, boolean temp) { TrackableProperty prop = temp ? TrackableProperty.PlayerMayLookTemp : TrackableProperty.PlayerMayLook; TrackableCollection<PlayerView> col = get(prop); if (mayLook) { if (col == null) { col = new TrackableCollection<PlayerView>(p.getView()); set(prop, col); } else if (col.add(p.getView())) { flagAsChanged(prop); } } else if (col != null) { if (col.remove(p.getView())) { if (col.isEmpty()) { set(prop, null); } else { flagAsChanged(prop); } } } }
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; }
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; }