[Client]Load cards from db only once during a game.

Display library with effects like "fetchland" are faster
This commit is contained in:
Plopman 2013-11-27 21:59:17 +01:00
parent 16eee07a74
commit 0d88b4055b
3 changed files with 36 additions and 10 deletions

View file

@ -29,6 +29,7 @@
package mage.client.util;
import java.util.List;
import java.util.Map;
import mage.cards.Card;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
@ -53,6 +54,26 @@ public class CardsViewUtil {
return cards;
}
public static CardsView convertSimple(SimpleCardsView view, Map<String, Card> loadedCards) {
CardsView cards = new CardsView();
for (SimpleCardView simple: view.values()) {
String key = simple.getExpansionSetCode() + "_" + simple.getCardNumber();
Card card = loadedCards.get(key);
if(card == null)
{
CardInfo cardInfo = CardRepository.instance.findCard(simple.getExpansionSetCode(), simple.getCardNumber());
card = cardInfo != null ? cardInfo.getMockCard() : null;
loadedCards.put(key, card);
}
if (card != null) {
cards.put(simple.getId(), new CardView(card, simple.getId()));
}
}
return cards;
}
public static CardsView convertCommandObject(List<CommandObjectView> view) {
CardsView cards = new CardsView();