mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
[CardRepository] Replaced CardsStorage from Ratings Plugin
This commit is contained in:
parent
3419c4366d
commit
670646de15
3 changed files with 24 additions and 49 deletions
|
@ -1,7 +1,6 @@
|
|||
package org.mage.plugins.rating;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.plugins.rating.cards.CardsStorage;
|
||||
import org.mage.plugins.rating.results.ResultHandler;
|
||||
import org.mage.plugins.rating.ui.BigCard;
|
||||
|
||||
|
@ -78,7 +77,6 @@ public class RateFrame extends JFrame {
|
|||
}
|
||||
|
||||
public void startRating() {
|
||||
CardsStorage.getAllCards();
|
||||
label.setText("The results are stored automatically for every 10 compare.");
|
||||
RateThread.getInstance().start(this, this.bigCard);
|
||||
}
|
||||
|
|
|
@ -12,10 +12,13 @@ import mage.Constants.CardType;
|
|||
import mage.cards.Card;
|
||||
import mage.cards.CardDimensions;
|
||||
import mage.cards.MageCard;
|
||||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.cards.repository.CardScanner;
|
||||
import mage.view.CardView;
|
||||
|
||||
import org.mage.plugins.card.CardPluginImpl;
|
||||
import org.mage.plugins.rating.cards.CardsStorage;
|
||||
import org.mage.plugins.rating.results.Rating;
|
||||
import org.mage.plugins.rating.results.ResultHandler;
|
||||
import org.mage.plugins.rating.ui.BigCard;
|
||||
|
@ -35,6 +38,21 @@ public class RateThread extends Thread {
|
|||
private Random random = new Random();
|
||||
|
||||
private static List<Rating> results = new ArrayList<Rating>();
|
||||
private static final List<CardInfo> cards = new ArrayList<CardInfo>();
|
||||
|
||||
static {
|
||||
CardScanner.scan();
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.notTypes(CardType.LAND);
|
||||
List<CardInfo> allCards = CardRepository.instance.findCards(criteria);
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (CardInfo card : allCards) {
|
||||
if (!names.contains(card.getName())) {
|
||||
names.add(card.getName());
|
||||
cards.add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RateThread() {
|
||||
setDaemon(true);
|
||||
|
@ -70,14 +88,12 @@ public class RateThread extends Thread {
|
|||
}
|
||||
|
||||
protected Card getRandomUniqueNonLandCard(Card previousCard) {
|
||||
int count = CardsStorage.getUniqueCards().size();
|
||||
int index = random.nextInt(count);
|
||||
Card card1 = CardsStorage.getUniqueCards().get(index);
|
||||
while (card1.getCardType().contains(CardType.LAND) || card1.getName().equals(previousCard)) {
|
||||
index = random.nextInt(count);
|
||||
card1 = CardsStorage.getUniqueCards().get(index);
|
||||
int count = cards.size();
|
||||
Card card = cards.get(random.nextInt(count)).getCard();
|
||||
while (previousCard != null && card.getName().equals(previousCard.getName())) {
|
||||
card = cards.get(random.nextInt(count)).getCard();
|
||||
}
|
||||
return card1;
|
||||
return card;
|
||||
}
|
||||
|
||||
public void start(JFrame frame, BigCard bigCard) {
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
package org.mage.plugins.rating.cards;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.sets.Sets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CardsStorage {
|
||||
private static List<Card> allCards = new ArrayList<Card>();
|
||||
private static List<Card> uniqueCards = new ArrayList<Card>();
|
||||
|
||||
static {
|
||||
for (ExpansionSet set: Sets.getInstance().values()) {
|
||||
if (set.getName().equals("Magic 2013")) {
|
||||
allCards.addAll(set.getCards());
|
||||
}
|
||||
}
|
||||
Set<String> names = new HashSet<String>();
|
||||
for (Card card : allCards) {
|
||||
if (!names.contains(card.getName())) {
|
||||
uniqueCards.add(card);
|
||||
names.add(card.getName());
|
||||
}
|
||||
}
|
||||
System.out.println("cards=" + allCards.size() + ", unique cards=" + uniqueCards.size());
|
||||
}
|
||||
|
||||
public static List<Card> getAllCards() {
|
||||
return allCards;
|
||||
}
|
||||
|
||||
public static List<Card> getUniqueCards() {
|
||||
return uniqueCards;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue