mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Merge branch 'patch-carddb-performance' into 'master'
Card Hover FIX in Catalog + extra optimisation in performance and refactoring See merge request core-developers/forge!5263
This commit is contained in:
@@ -236,7 +236,9 @@ public interface IPaperCard extends InventoryItem, Serializable {
|
||||
CardRules getRules();
|
||||
CardRarity getRarity();
|
||||
String getArtist();
|
||||
|
||||
String getItemType();
|
||||
boolean hasBackFace();
|
||||
String getCardImageKey();
|
||||
String getCardAltImageKey();
|
||||
|
||||
}
|
||||
@@ -20,10 +20,7 @@ package forge.item;
|
||||
import com.google.common.base.Function;
|
||||
import forge.ImageKeys;
|
||||
import forge.StaticData;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.*;
|
||||
import forge.util.CardTranslation;
|
||||
import forge.util.ImageUtil;
|
||||
import forge.util.Localizer;
|
||||
@@ -141,13 +138,6 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
return hasImage;
|
||||
}
|
||||
|
||||
private String imageKeyFromSet = null;
|
||||
public String getImageKeyFromSet() {
|
||||
if (this.imageKeyFromSet == null)
|
||||
this.imageKeyFromSet = ImageUtil.getImageKey(this, false, true);
|
||||
return imageKeyFromSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lambda to get rules for selects from list of printed cards.
|
||||
*/
|
||||
@@ -308,6 +298,32 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
return imageKey;
|
||||
}
|
||||
|
||||
private String cardImageKey = null;
|
||||
@Override
|
||||
public String getCardImageKey() {
|
||||
if (this.cardImageKey == null)
|
||||
this.cardImageKey = ImageUtil.getImageKey(this, false, true);
|
||||
return cardImageKey;
|
||||
}
|
||||
|
||||
private String cardAltImageKey = null;
|
||||
@Override
|
||||
public String getCardAltImageKey() {
|
||||
if (this.cardAltImageKey == null){
|
||||
if (this.hasBackFace())
|
||||
this.cardAltImageKey = ImageUtil.getImageKey(this, true, true);
|
||||
else // altImageKey will be the same as cardImageKey
|
||||
this.cardAltImageKey = ImageUtil.getImageKey(this, false, true);
|
||||
}
|
||||
return cardAltImageKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBackFace(){
|
||||
CardSplitType cst = this.rules.getSplitType();
|
||||
return cst == CardSplitType.Transform || cst == CardSplitType.Flip || cst == CardSplitType.Meld || cst == CardSplitType.Modal;
|
||||
}
|
||||
|
||||
// Return true if card is one of the five basic lands that can be added for free
|
||||
public boolean isVeryBasicLand() {
|
||||
return (this.getName().equals("Swamp"))
|
||||
|
||||
@@ -151,8 +151,25 @@ public class PaperToken implements InventoryItemFromSet, IPaperCard {
|
||||
|
||||
@Override public String getItemType() { return "Token"; }
|
||||
|
||||
@Override
|
||||
public boolean hasBackFace() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean isToken() { return true; }
|
||||
|
||||
// IPaperCard
|
||||
@Override
|
||||
public String getCardImageKey() {
|
||||
return this.getImageKey(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCardAltImageKey() {
|
||||
return getImageKey(true);
|
||||
}
|
||||
|
||||
// InventoryItem
|
||||
@Override
|
||||
public String getImageKey(boolean altState) {
|
||||
int idx = MyRandom.getRandom().nextInt(artIndex);
|
||||
|
||||
@@ -83,15 +83,10 @@ public class ImageUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasBackFacePicture(PaperCard cp) {
|
||||
CardSplitType cst = cp.getRules().getSplitType();
|
||||
return cst == CardSplitType.Transform || cst == CardSplitType.Flip || cst == CardSplitType.Meld || cst == CardSplitType.Modal;
|
||||
}
|
||||
|
||||
public static String getNameToUse(PaperCard cp, boolean backFace) {
|
||||
final CardRules card = cp.getRules();
|
||||
if (backFace) {
|
||||
if (hasBackFacePicture(cp))
|
||||
if (cp.hasBackFace())
|
||||
if (card.getOtherPart() != null) {
|
||||
return card.getOtherPart().getName();
|
||||
} else if (!card.getMeldWith().isEmpty()) {
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import forge.item.InventoryItem;
|
||||
|
||||
/**
|
||||
@@ -149,12 +150,14 @@ public class ItemPool<T extends InventoryItem> implements Iterable<Entry<T, Inte
|
||||
@SuppressWarnings("unchecked")
|
||||
public final <U extends InventoryItem> int countAll(Predicate<U> condition, Class<U> cls) {
|
||||
int count = 0;
|
||||
for (Entry<T, Integer> e : this) {
|
||||
T item = e.getKey();
|
||||
if (cls.isInstance(item) && condition.apply((U)item)) {
|
||||
count += e.getValue();
|
||||
Iterable<T> matchingKeys = Iterables.filter(this.items.keySet(), new Predicate<T>() {
|
||||
@Override
|
||||
public boolean apply(T item) {
|
||||
return cls.isInstance(item) && condition.apply((U)item);
|
||||
}
|
||||
}
|
||||
});
|
||||
for (T key : matchingKeys)
|
||||
count += this.items.get(key);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user