mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Create DeckManager
This commit is contained in:
@@ -105,7 +105,7 @@ public final class CardDb implements ICardDatabase {
|
||||
}
|
||||
|
||||
private void addCard(PaperCard paperCard) {
|
||||
allCardsByName.put(paperCard.name, paperCard);
|
||||
allCardsByName.put(paperCard.getName(), paperCard);
|
||||
}
|
||||
|
||||
private void reIndex() {
|
||||
|
||||
@@ -134,5 +134,4 @@ public class DeckGroup extends DeckBase {
|
||||
return arg1.getName();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
73
forge-core/src/main/java/forge/item/DeckBox.java
Normal file
73
forge-core/src/main/java/forge/item/DeckBox.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.item;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
|
||||
/**
|
||||
* A deck box containing a deck
|
||||
*
|
||||
*/
|
||||
public class DeckBox implements InventoryItem {
|
||||
private final Deck deck;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.deck.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemType() {
|
||||
return "Deck";
|
||||
}
|
||||
|
||||
public DeckBox(final Deck deck0) {
|
||||
this.deck = deck0;
|
||||
}
|
||||
|
||||
//create predicate that applys a card predicate to all cards in deck
|
||||
public static final Predicate<DeckBox> createPredicate(final Predicate<PaperCard> cardPredicate) {
|
||||
return new Predicate<DeckBox>() {
|
||||
@Override
|
||||
public boolean apply(DeckBox input) {
|
||||
for (Entry<DeckSection, CardPool> deckEntry : input.deck) {
|
||||
switch (deckEntry.getKey()) {
|
||||
case Main:
|
||||
case Sideboard:
|
||||
case Commander:
|
||||
for (Entry<PaperCard, Integer> poolEntry : deckEntry.getValue()) {
|
||||
if (!cardPredicate.apply(poolEntry.getKey())) {
|
||||
return false; //all cards in deck must pass card predicate to pass deck predicate
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break; //ignore other sections
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -35,10 +35,10 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
private final transient CardRules rules;
|
||||
|
||||
// These fields are kinda PK for PrintedCard
|
||||
public final String name;
|
||||
public final String edition;
|
||||
public final int artIndex;
|
||||
public final boolean foil;
|
||||
private final String name;
|
||||
private final String edition;
|
||||
private final int artIndex;
|
||||
private final boolean foil;
|
||||
|
||||
// Calculated fields are below:
|
||||
private final transient CardRarity rarity; // rarity is given in ctor when set is assigned
|
||||
|
||||
Reference in New Issue
Block a user