extracted method for loading a card in Deck class

This commit is contained in:
North 2013-07-06 10:46:02 +03:00
parent 9e5f3887bf
commit d9b37cc12a

View file

@ -31,7 +31,8 @@ package mage.cards.decks;
import java.io.Serializable; import java.io.Serializable;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import mage.cards.*; import mage.cards.Card;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import mage.game.GameException; import mage.game.GameException;
@ -53,37 +54,38 @@ public class Deck implements Serializable {
Deck deck = new Deck(); Deck deck = new Deck();
deck.setName(deckCardLists.getName()); deck.setName(deckCardLists.getName());
for (DeckCardInfo deckCardInfo: deckCardLists.getCards()) { for (DeckCardInfo deckCardInfo: deckCardLists.getCards()) {
Card card; Card card = createCard(deckCardInfo, mockCards);
if (mockCards) {
card = CardRepository.instance.findCard(deckCardInfo.getSetCode(), deckCardInfo.getCardNum()).getMockCard();
} else {
card = CardImpl.createCard(CardRepository.instance.findCard(deckCardInfo.getSetCode(), deckCardInfo.getCardNum()).getClassName());
}
if (card != null) { if (card != null) {
deck.cards.add(card); deck.cards.add(card);
} } else if (!ignoreErrors) {
else { throw new GameException("Error loading card - " + deckCardInfo.getCardName() + " for deck - " + deck.getName());
if (!ignoreErrors) {
throw new GameException("Error loading card - " + deckCardInfo.getCardName() + " for deck - " + deck.getName());
}
} }
} }
for (DeckCardInfo deckCardInfo: deckCardLists.getSideboard()) { for (DeckCardInfo deckCardInfo: deckCardLists.getSideboard()) {
Card card = CardRepository.instance.findCard(deckCardInfo.getSetCode(), deckCardInfo.getCardNum()).getMockCard(); Card card = createCard(deckCardInfo, mockCards);
// Card card = CardImpl.createCard(cardName);
if (card != null) { if (card != null) {
deck.sideboard.add(card); deck.sideboard.add(card);
} } else if (!ignoreErrors) {
else { throw new GameException("Error loading card - " + deckCardInfo.getCardName() + " for deck - " + deck.getName());
if (!ignoreErrors) {
throw new GameException("Error loading card - " + deckCardInfo.getCardName() + " for deck - " + deck.getName());
}
} }
} }
return deck; return deck;
} }
private static Card createCard(DeckCardInfo deckCardInfo, boolean mockCards) {
CardInfo cardInfo = CardRepository.instance.findCard(deckCardInfo.getSetCode(), deckCardInfo.getCardNum());
if (cardInfo == null) {
return null;
}
if (mockCards) {
return cardInfo.getMockCard();
} else {
return cardInfo.getCard();
}
}
public DeckCardLists getDeckCardLists() { public DeckCardLists getDeckCardLists() {
DeckCardLists deckCardLists = new DeckCardLists(); DeckCardLists deckCardLists = new DeckCardLists();
@ -114,30 +116,18 @@ public class Deck implements Serializable {
return sets; return sets;
} }
/**
* @return the name
*/
public String getName() { public String getName() {
return name; return name;
} }
/**
* @param name the name to set
*/
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/**
* @return the cards
*/
public Set<Card> getCards() { public Set<Card> getCards() {
return cards; return cards;
} }
/**
* @return the sideboard
*/
public Set<Card> getSideboard() { public Set<Card> getSideboard() {
return sideboard; return sideboard;
} }