* Moved the hardcoded predicates for variants cards from CEditorConstructed to card/CardRulesPredicates.java

* Added a method in CardDb that returns only the cards matching the supplied predicate
This commit is contained in:
Maxmtg
2013-02-16 20:30:39 +00:00
parent 0c142cb32c
commit 2cf28435de
3 changed files with 25 additions and 49 deletions

View File

@@ -519,8 +519,13 @@ public final class CardRulesPredicates {
public static final Predicate<CardRules> IS_SORCERY = CardRulesPredicates.coreType(true, CardCoreType.Sorcery);
/** The Constant isEnchantment. */
public static final Predicate<CardRules> IS_ENCHANTMENT = CardRulesPredicates.coreType(true,
CardCoreType.Enchantment);
public static final Predicate<CardRules> IS_ENCHANTMENT = CardRulesPredicates.coreType(true, CardCoreType.Enchantment);
public static final Predicate<CardRules> IS_PLANE = CardRulesPredicates.coreType(true, CardCoreType.Enchantment);
public static final Predicate<CardRules> IS_PHENOMENON = CardRulesPredicates.coreType(true, CardCoreType.Phenomenon);
public static final Predicate<CardRules> IS_PLANE_OR_PHENOMENON = Predicates.or(IS_PLANE, IS_PHENOMENON);
public static final Predicate<CardRules> IS_SCHEME = CardRulesPredicates.coreType(true, CardCoreType.Scheme);
public static final Predicate<CardRules> IS_VANGUARD = CardRulesPredicates.coreType(true, CardCoreType.Vanguard);
/** The Constant isNonLand. */
public static final Predicate<CardRules> IS_NON_LAND = CardRulesPredicates.coreType(false, CardCoreType.Land);

View File

@@ -21,12 +21,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import forge.Command;
import forge.Singletons;
import forge.card.CardRulesPredicates;
import forge.deck.Deck;
import forge.deck.DeckSection;
import forge.gui.deckeditor.SEditorIO;
@@ -65,9 +64,9 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
private List<DeckSection> allSections = new ArrayList<DeckSection>();
private DeckSection sectionMode = DeckSection.Main;
private ItemPoolView<CardPrinted> avatarPool;
private ItemPoolView<CardPrinted> planePool;
private ItemPoolView<CardPrinted> schemePool;
private final ItemPoolView<CardPrinted> avatarPool;
private final ItemPoolView<CardPrinted> planePool;
private final ItemPoolView<CardPrinted> schemePool;
//=========== Constructor
/**
@@ -85,47 +84,10 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
allSections.add(DeckSection.Planes);
//allSections.add(DeckSection.Commander);
avatarPool = ItemPool.createFrom(Iterables.filter(CardDb.variants().getAllCards(),new Predicate<CardPrinted>() {
@Override
public boolean apply(CardPrinted arg0) {
if(arg0.getCard().getType().isVanguard())
{
return true;
}
return false;
}
}),CardPrinted.class);
planePool = ItemPool.createFrom(Iterables.filter(CardDb.variants().getAllCards(),new Predicate<CardPrinted>() {
@Override
public boolean apply(CardPrinted arg0) {
if(arg0.getCard().getType().isPlane() || arg0.getCard().getType().isPhenomenon())
{
return true;
}
return false;
}
}),CardPrinted.class);
schemePool = ItemPool.createFrom(Iterables.filter(CardDb.variants().getAllCards(),new Predicate<CardPrinted>() {
@Override
public boolean apply(CardPrinted arg0) {
if(arg0.getCard().getType().isScheme())
{
return true;
}
return false;
}
}),CardPrinted.class);
avatarPool = ItemPool.createFrom(CardDb.variants().getAllCards(Predicates.compose(CardRulesPredicates.Presets.IS_VANGUARD, CardPrinted.FN_GET_RULES)),CardPrinted.class);
planePool = ItemPool.createFrom(CardDb.variants().getAllCards(Predicates.compose(CardRulesPredicates.Presets.IS_PLANE_OR_PHENOMENON, CardPrinted.FN_GET_RULES)),CardPrinted.class);
schemePool = ItemPool.createFrom(CardDb.variants().getAllCards(Predicates.compose(CardRulesPredicates.Presets.IS_SCHEME, CardPrinted.FN_GET_RULES)),CardPrinted.class);
boolean wantUnique = SEditorIO.getPref(EditorPreference.display_unique_only);
@@ -238,6 +200,7 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
/**
* Switch between the main deck and the sideboard editor.
*/
@SuppressWarnings("incomplete-switch")
public void cycleEditorMode() {
int curindex = allSections.indexOf(sectionMode);

View File

@@ -34,6 +34,8 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Card;
import forge.card.CardInSet;
import forge.card.CardRules;
@@ -286,10 +288,16 @@ public final class CardDb {
*
* @return the all cards
*/
public Collection<CardPrinted> getAllCards() {
public List<CardPrinted> getAllCards() {
return this.allCardsFlat;
}
/** Returns a modifiable list of cards matching the given predicate */
public List<CardPrinted> getAllCards(Predicate<CardPrinted> predicate) {
return Lists.newArrayList(Iterables.filter(this.allCardsFlat, predicate));
}
/**
* Gets the card.
*