mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Cards lazy loading
This commit is contained in:
parent
c630ecd2d5
commit
653f236c65
6 changed files with 98 additions and 52 deletions
|
|
@ -1,7 +1,5 @@
|
|||
package mage.client.cards;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import mage.Constants;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
|
|
@ -10,6 +8,9 @@ import mage.sets.Sets;
|
|||
import mage.utils.CardUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Stores all implemented cards on client side.
|
||||
* Used by deck editor, deck generator, collection viewer, etc.
|
||||
|
|
@ -25,6 +26,8 @@ public class CardsStorage {
|
|||
private static Map<String, Integer> ratings;
|
||||
private static Integer min = Integer.MAX_VALUE, max = 0;
|
||||
private static List<Card> notImplementedCards;
|
||||
|
||||
private static boolean loaded;
|
||||
|
||||
/**
|
||||
* Rating that is given for new cards.
|
||||
|
|
@ -43,19 +46,33 @@ public class CardsStorage {
|
|||
setCodes.add(set.getCode());
|
||||
}
|
||||
|
||||
for (ExpansionSet set : sets) {
|
||||
List<Card> cards = set.getCards();
|
||||
Collections.sort(cards, new CardComparator());
|
||||
allCards.addAll(cards);
|
||||
for (Card card : cards) {
|
||||
if (CardUtil.isLand(card) && !CardUtil.isBasicLand(card)) {
|
||||
nonBasicLandCards.add(card);
|
||||
}
|
||||
|
||||
private static void loadLazily() {
|
||||
if (!loaded) {
|
||||
synchronized (CardsStorage.class) {
|
||||
if (!loaded) {
|
||||
List<ExpansionSet> sets = new ArrayList<ExpansionSet>(Sets.getInstance().values());
|
||||
for (ExpansionSet set : sets) {
|
||||
List<Card> cards = set.getCards();
|
||||
Collections.sort(cards, new CardComparator());
|
||||
allCards.addAll(cards);
|
||||
for (Card card : cards) {
|
||||
if (CardUtil.isLand(card) && !CardUtil.isBasicLand(card)) {
|
||||
nonBasicLandCards.add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Card> getAllCards() {
|
||||
if (!loaded) {
|
||||
loadLazily();
|
||||
}
|
||||
return allCards;
|
||||
}
|
||||
|
||||
|
|
@ -73,10 +90,10 @@ public class CardsStorage {
|
|||
List<Card> cards = new ArrayList<Card>();
|
||||
List<Card> pool;
|
||||
if (set == null) {
|
||||
pool = allCards;
|
||||
pool = getAllCards();
|
||||
} else {
|
||||
pool = new ArrayList<Card>();
|
||||
for (Card card : allCards) {
|
||||
for (Card card : getAllCards()) {
|
||||
if (card.getExpansionSetCode().equals(set)) {
|
||||
pool.add(card);
|
||||
}
|
||||
|
|
@ -97,7 +114,7 @@ public class CardsStorage {
|
|||
}
|
||||
|
||||
public static int getCardsCount() {
|
||||
return allCards.size();
|
||||
return getAllCards().size();
|
||||
}
|
||||
|
||||
public static List<String> getSetCodes() {
|
||||
|
|
@ -105,6 +122,9 @@ public class CardsStorage {
|
|||
}
|
||||
|
||||
public static Set<Card> getNonBasicLandCards() {
|
||||
if (!loaded) {
|
||||
loadLazily();
|
||||
}
|
||||
return nonBasicLandCards;
|
||||
}
|
||||
|
||||
|
|
@ -165,12 +185,12 @@ public class CardsStorage {
|
|||
public static List<Card> getNotImplementedCards() {
|
||||
List<Card> cards = new ArrayList<Card>();
|
||||
if (notImplementedCards == null) {
|
||||
if (allCards.isEmpty()) {
|
||||
if (getAllCards().isEmpty()) {
|
||||
return cards;
|
||||
}
|
||||
|
||||
Set<String> names = new HashSet<String>();
|
||||
for (Card card : allCards) {
|
||||
for (Card card : getAllCards()) {
|
||||
names.add(card.getExpansionSetCode() + card.getName());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,13 +27,14 @@
|
|||
*/
|
||||
package mage.client.deckeditor.collection.viewer;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.swing.JComponent;
|
||||
import mage.client.MagePane;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Collection viewer pane.
|
||||
* Contains background and components container.
|
||||
|
|
@ -79,5 +80,13 @@ public class CollectionViewerPane extends MagePane {
|
|||
pack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean aFlag) {
|
||||
super.setVisible(aFlag);
|
||||
if (collectionViewerPanel != null) {
|
||||
collectionViewerPanel.showCards();
|
||||
}
|
||||
}
|
||||
|
||||
private CollectionViewerPanel collectionViewerPanel;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -215,6 +215,12 @@ public final class CollectionViewerPanel extends JPanel {
|
|||
private javax.swing.JScrollPane jScrollPane1;
|
||||
}
|
||||
|
||||
public void showCards() {
|
||||
if (mageBook != null) {
|
||||
mageBook.showCards();
|
||||
}
|
||||
}
|
||||
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JPanel jPanel2;
|
||||
private mage.client.cards.BigCard bigCard;
|
||||
|
|
|
|||
|
|
@ -135,13 +135,6 @@ public class MageBook extends JComponent {
|
|||
add(jPanelRight, BorderLayout.LINE_END);
|
||||
|
||||
cardDimensions = new CardDimensions(0.45d);
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showCards();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addLeftRightPageButtons() {
|
||||
|
|
@ -212,7 +205,7 @@ public class MageBook extends JComponent {
|
|||
}
|
||||
}
|
||||
|
||||
private void showCards() {
|
||||
public void showCards() {
|
||||
jLayeredPane.removeAll();
|
||||
addLeftRightPageButtons();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue