mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
moved all image-acquiring code to ImageCache
This commit is contained in:
@@ -29,11 +29,20 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.mortennobel.imagescaling.ResampleOp;
|
||||
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardSplitType;
|
||||
import forge.game.player.IHasIcon;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.item.BoosterPack;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.CardToken;
|
||||
import forge.item.FatPack;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.PreconDeck;
|
||||
import forge.item.TournamentPack;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.util.Base64Coder;
|
||||
|
||||
/**
|
||||
* This class stores ALL card images in a cache with soft values. this means
|
||||
@@ -79,7 +88,7 @@ public class ImageCache {
|
||||
* and cannot be loaded from disk. pass -1 for width and/or height to avoid resizing in that dimension.
|
||||
*/
|
||||
public static BufferedImage getImage(InventoryItem ii, int width, int height) {
|
||||
return scaleImage(ii.getImageKey(), width, height);
|
||||
return scaleImage(getImageKey(ii), width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,4 +163,105 @@ public class ImageCache {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getImageKey(InventoryItem ii) {
|
||||
return getImageKey(ii, false);
|
||||
}
|
||||
|
||||
// Inventory items don't have to know how a certain client should draw them.
|
||||
// That's why this method is not encapsulated and overloaded in the InventoryItem descendants
|
||||
public static String getImageKey(InventoryItem ii, boolean altState) {
|
||||
if ( ii instanceof CardPrinted )
|
||||
return getImageKey((CardPrinted)ii, altState, true);
|
||||
if ( ii instanceof TournamentPack )
|
||||
return ImageCache.TOURNAMENTPACK_PREFIX + ((TournamentPack)ii).getEdition();
|
||||
if ( ii instanceof BoosterPack )
|
||||
return ImageCache.BOOSTER_PREFIX + ((BoosterPack)ii).getEdition();
|
||||
if ( ii instanceof FatPack )
|
||||
return ImageCache.FATPACK_PREFIX + ((FatPack)ii).getEdition();
|
||||
if ( ii instanceof PreconDeck )
|
||||
return ImageCache.PRECON_PREFIX + ((PreconDeck)ii).getImageFilename();
|
||||
if ( ii instanceof CardToken )
|
||||
return ImageCache.TOKEN_PREFIX + ((CardToken)ii).getImageFilename();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getImageLocator(CardPrinted cp, String nameToUse, boolean includeSet, boolean isDownloadUrl) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
|
||||
CardRules card = cp.getRules();
|
||||
String edition = cp.getEdition();
|
||||
s.append(ImageCache.toMWSFilename(nameToUse));
|
||||
|
||||
final int cntPictures;
|
||||
if (includeSet) {
|
||||
cntPictures = card.getEditionInfo(edition).getCopiesCount();
|
||||
} else {
|
||||
// raise the art index limit to the maximum of the sets this card was printed in
|
||||
int maxCntPictures = 1;
|
||||
for (String set : card.getSets()) {
|
||||
maxCntPictures = Math.max(maxCntPictures, card.getEditionInfo(set).getCopiesCount());
|
||||
}
|
||||
cntPictures = maxCntPictures;
|
||||
}
|
||||
|
||||
int artIdx = cp.getArtIndex();
|
||||
if (cntPictures > 1 ) {
|
||||
if ( cntPictures <= artIdx )
|
||||
artIdx = Math.min(artIdx, cntPictures - 1);
|
||||
s.append(artIdx + 1);
|
||||
}
|
||||
|
||||
// for whatever reason, MWS-named plane cards don't have the ".full" infix
|
||||
if (!card.getType().isPlane() && !card.getType().isPhenomenon()) {
|
||||
s.append(".full");
|
||||
}
|
||||
|
||||
final String fname;
|
||||
if (isDownloadUrl) {
|
||||
s.append(".jpg");
|
||||
fname = Base64Coder.encodeString(s.toString(), true);
|
||||
} else {
|
||||
fname = s.toString();
|
||||
}
|
||||
|
||||
if (includeSet) {
|
||||
return String.format("%s/%s", Singletons.getModel().getEditions().getCode2ByCode(cp.getEdition()), fname);
|
||||
} else {
|
||||
return fname;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getImageName(CardPrinted cp) {
|
||||
return CardSplitType.Split != cp.getRules().getSplitType() ? cp.getName() : cp.getRules().getMainPart().getName() + cp.getRules().getOtherPart().getName();
|
||||
}
|
||||
|
||||
public static String getImageKey(CardPrinted cp, boolean backFace, boolean includeSet) {
|
||||
final CardRules card = cp.getRules();
|
||||
final String nameToUse;
|
||||
if (backFace) {
|
||||
if ( card.getSplitType() == CardSplitType.Transform )
|
||||
nameToUse = card.getOtherPart().getName();
|
||||
else
|
||||
return null;
|
||||
} else {
|
||||
nameToUse = getImageName(cp);
|
||||
}
|
||||
|
||||
return getImageLocator(cp, nameToUse, includeSet, false);
|
||||
}
|
||||
|
||||
public static String toMWSFilename(String in) {
|
||||
final StringBuffer out = new StringBuffer();
|
||||
char c;
|
||||
for (int i = 0; i < in.length(); i++) {
|
||||
c = in.charAt(i);
|
||||
if ((c == '"') || (c == '/') || (c == ':') || (c == '?')) {
|
||||
out.append("");
|
||||
} else {
|
||||
out.append(c);
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ final class ImageLoader extends CacheLoader<String, BufferedImage> {
|
||||
BufferedImage ret = _findFile(key, path, filename);
|
||||
|
||||
// some S00/S2K cards are really part of 6ED/6E
|
||||
if (null == ret && filename.startsWith("S2K") ) {
|
||||
ret = _findFile(key, path, filename.replace("S2K", "6E"));
|
||||
if (null == ret && filename.startsWith("S00") ) {
|
||||
ret = _findFile(key, path, filename.replace("S00", "6ED"));
|
||||
}
|
||||
|
||||
// try without set prefix
|
||||
|
||||
@@ -27,6 +27,7 @@ import forge.CardCharacteristicName;
|
||||
import forge.CardColor;
|
||||
import forge.CardUtil;
|
||||
import forge.Color;
|
||||
import forge.ImageCache;
|
||||
import forge.card.CardCharacteristics;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardSplitType;
|
||||
@@ -224,7 +225,8 @@ public class CardFactory {
|
||||
c.setCurSetCode(cp.getEdition());
|
||||
c.setRarity(cp.getRarity());
|
||||
|
||||
String originalPicture = cp.getImageKey();
|
||||
// Would like to move this away from in-game entities
|
||||
String originalPicture = ImageCache.getImageKey(cp);
|
||||
//System.out.println(c.getName() + " -> " + originalPicture);
|
||||
c.setImageKey(originalPicture);
|
||||
c.setToken(cp.isToken());
|
||||
@@ -236,7 +238,7 @@ public class CardFactory {
|
||||
}
|
||||
else if (c.isDoubleFaced() && cp instanceof CardPrinted) {
|
||||
c.setState(CardCharacteristicName.Transformed);
|
||||
c.setImageKey(((CardPrinted)cp).getImageKey(true));
|
||||
c.setImageKey(ImageCache.getImageKey(cp, true));
|
||||
}
|
||||
else if (c.getRules().getSplitType() == CardSplitType.Split) {
|
||||
c.setState(CardCharacteristicName.LeftSplit);
|
||||
|
||||
@@ -33,6 +33,7 @@ import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.deck.Deck;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.properties.NewConstants;
|
||||
@@ -138,7 +139,8 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
|
||||
for (final Entry<CardPrinted, Integer> card : d.getMain()) {
|
||||
// System.out.println(card.getSets().get(card.getSets().size() - 1).URL);
|
||||
for (int i = card.getValue().intValue(); i > 0; --i ) {
|
||||
String url = NewConstants.URL_PIC_DOWNLOAD + card.getKey().getImageUrlPath(false);
|
||||
CardPrinted r = card.getKey();
|
||||
String url = NewConstants.URL_PIC_DOWNLOAD + ImageCache.getImageLocator(r, ImageCache.getImageName(r), true, true);
|
||||
list.add(url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import forge.game.player.Player;
|
||||
import forge.game.zone.PlayerZone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.match.views.VAntes;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.properties.ForgePreferences;
|
||||
@@ -51,21 +52,24 @@ public class GameNew {
|
||||
private static void preparePlayerLibrary(Player player, final ZoneType zoneType, CardPool secion, boolean canRandomFoil, Random generator) {
|
||||
PlayerZone library = player.getZone(zoneType);
|
||||
for (final Entry<CardPrinted, Integer> stackOfCards : secion) {
|
||||
final CardPrinted cardPrinted = stackOfCards.getKey();
|
||||
final CardPrinted cp = stackOfCards.getKey();
|
||||
for (int i = 0; i < stackOfCards.getValue(); i++) {
|
||||
|
||||
final Card card = cardPrinted.toForgeCard(player);
|
||||
|
||||
CardPrinted cpi = cp;
|
||||
// apply random pictures for cards
|
||||
if (preferences.getPrefBoolean(FPref.UI_RANDOM_CARD_ART)) {
|
||||
final int cntVariants = cardPrinted.getRules().getEditionInfo(cardPrinted.getEdition()).getCopiesCount();
|
||||
final int cntVariants = cp.getRules().getEditionInfo(cp.getEdition()).getCopiesCount();
|
||||
if (cntVariants > 1) {
|
||||
card.setImageKey(cardPrinted.getImageKey(false, generator.nextInt(cntVariants), true));
|
||||
cpi = CardDb.instance().getCard(cp.getName(), cp.getEdition(), generator.nextInt(cntVariants));
|
||||
if ( cp.isFoil() )
|
||||
cpi = CardPrinted.makeFoiled(cpi);
|
||||
}
|
||||
}
|
||||
|
||||
final Card card = cpi.toForgeCard(player);
|
||||
|
||||
// Assign random foiling on approximately 1:20 cards
|
||||
if (cardPrinted.isFoil() || (canRandomFoil && MyRandom.percentTrue(5))) {
|
||||
if (cp.isFoil() || (canRandomFoil && MyRandom.percentTrue(5))) {
|
||||
final int iFoil = generator.nextInt(9) + 1;
|
||||
card.setFoil(iFoil);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ import forge.gui.toolbox.FScrollPane;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FTextArea;
|
||||
import forge.item.InventoryItemFromSet;
|
||||
import forge.item.OpenablePack;
|
||||
import forge.item.PreconDeck;
|
||||
|
||||
/**
|
||||
* The class CardDetailPanel. Shows the details of a card.
|
||||
@@ -148,13 +150,21 @@ public class CardDetailPanel extends FPanel {
|
||||
|
||||
this.setCard(card);
|
||||
}
|
||||
|
||||
public String getItemDescription(InventoryItemFromSet i) {
|
||||
if( i instanceof OpenablePack )
|
||||
return ((OpenablePack)i).getDescription();
|
||||
if( i instanceof PreconDeck)
|
||||
return ((PreconDeck) i).getDescription();
|
||||
return i.getName();
|
||||
}
|
||||
|
||||
public final void setItem(InventoryItemFromSet item) {
|
||||
nameCostLabel.setText(item.getName());
|
||||
typeLabel.setVisible(false);
|
||||
powerToughnessLabel.setVisible(false);
|
||||
idLabel.setText(null);
|
||||
cdArea.setText(item.getDescription());
|
||||
cdArea.setText(getItemDescription(item));
|
||||
setBorder(GuiDisplayUtil.getBorder(null));
|
||||
|
||||
String set = item.getEdition();
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRules;
|
||||
@@ -278,9 +279,8 @@ public class MigrationSourceAnalyzer {
|
||||
|
||||
private static String _oldCleanString(String in) {
|
||||
final StringBuffer out = new StringBuffer();
|
||||
char c;
|
||||
for (int i = 0; i < in.length(); i++) {
|
||||
c = in.charAt(i);
|
||||
char c = in.charAt(i);
|
||||
if ((c == ' ') || (c == '-')) {
|
||||
out.append('_');
|
||||
} else if (Character.isLetterOrDigit(c) || (c == '_')) {
|
||||
@@ -299,27 +299,30 @@ public class MigrationSourceAnalyzer {
|
||||
if (StringUtils.isEmpty(urls)) { return; }
|
||||
|
||||
int numPics = urls.split("\\\\").length;
|
||||
for (int artIdx = 0; numPics > artIdx; ++artIdx) {
|
||||
String filename = c.getImageKey(backFace, artIdx, false) + ".jpg";
|
||||
_defaultPicNames.put(filename, filename);
|
||||
|
||||
final String oldFilenameBase;
|
||||
if (cardRules.getType().isPlane() || cardRules.getType().isPhenomenon()) {
|
||||
oldFilenameBase = _oldCleanString(filename.replace(".jpg", ""));
|
||||
} else {
|
||||
oldFilenameBase = _oldCleanString(filename.replace(".full.jpg", ""));
|
||||
}
|
||||
|
||||
if (0 == artIdx) {
|
||||
// remove trailing "1" from first art index
|
||||
String oldFilename = oldFilenameBase.replaceAll("1$", "") + ".jpg";
|
||||
_defaultPicOldNameToCurrentName.put(oldFilename, filename);
|
||||
} else {
|
||||
// offset art indices by one
|
||||
String oldFilename = oldFilenameBase.replaceAll("[0-9]+$", String.valueOf(artIdx)) + ".jpg";
|
||||
_defaultPicOldNameToCurrentName.put(oldFilename, filename);
|
||||
}
|
||||
if ( c.getArtIndex() >= numPics )
|
||||
return;
|
||||
|
||||
String filename = ImageCache.getImageKey(c, backFace, false) + ".jpg";
|
||||
_defaultPicNames.put(filename, filename);
|
||||
|
||||
final String oldFilenameBase;
|
||||
if (cardRules.getType().isPlane() || cardRules.getType().isPhenomenon()) {
|
||||
oldFilenameBase = _oldCleanString(filename.replace(".jpg", ""));
|
||||
} else {
|
||||
oldFilenameBase = _oldCleanString(filename.replace(".full.jpg", ""));
|
||||
}
|
||||
|
||||
int maxArtIdx = c.getRules().getEditionInfo(c.getEdition()).getCopiesCount();
|
||||
if (1 == maxArtIdx) {
|
||||
// remove trailing "1" from first art index
|
||||
String oldFilename = oldFilenameBase.replaceAll("1$", "") + ".jpg";
|
||||
_defaultPicOldNameToCurrentName.put(oldFilename, filename);
|
||||
} else {
|
||||
// offset art indices by one
|
||||
String oldFilename = oldFilenameBase.replaceAll("[0-9]+$", String.valueOf(c.getArtIndex())) + ".jpg";
|
||||
_defaultPicOldNameToCurrentName.put(oldFilename, filename);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Map<String, String> _defaultPicNames;
|
||||
@@ -329,12 +332,12 @@ public class MigrationSourceAnalyzer {
|
||||
_defaultPicNames = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
_defaultPicOldNameToCurrentName = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (CardPrinted c : CardDb.instance().getUniqueCards()) {
|
||||
for (CardPrinted c : CardDb.instance().getAllCards()) {
|
||||
_addDefaultPicNames(c, false);
|
||||
_addDefaultPicNames(c, true);
|
||||
}
|
||||
|
||||
for (CardPrinted c : CardDb.variants().getUniqueCards()) {
|
||||
for (CardPrinted c : CardDb.variants().getAllCards()) {
|
||||
_addDefaultPicNames(c, false);
|
||||
_addDefaultPicNames(c, true);
|
||||
}
|
||||
@@ -369,11 +372,11 @@ public class MigrationSourceAnalyzer {
|
||||
|
||||
private static void _addSetCards(Map<String, String> cardFileNames, Iterable<CardPrinted> library, Predicate<CardPrinted> filter) {
|
||||
for (CardPrinted c : Iterables.filter(library, filter)) {
|
||||
boolean hasBackFace = null != c.getRules().getPictureOtherSideUrl();
|
||||
String filename = c.getImageKey(false, c.getArtIndex(), true) + ".jpg";
|
||||
boolean hasBackFacePicture = null != c.getRules().getPictureOtherSideUrl();
|
||||
String filename = ImageCache.getImageKey(c, false, true) + ".jpg";
|
||||
cardFileNames.put(filename, filename);
|
||||
if (hasBackFace) {
|
||||
filename = c.getImageKey(true, c.getArtIndex(), true) + ".jpg";
|
||||
if (hasBackFacePicture) {
|
||||
filename = ImageCache.getImageKey(c, true, true) + ".jpg";
|
||||
cardFileNames.put(filename, filename);
|
||||
}
|
||||
}
|
||||
@@ -402,11 +405,11 @@ public class MigrationSourceAnalyzer {
|
||||
};
|
||||
|
||||
for (CardPrinted c : Iterables.filter(CardDb.variants().getAllCards(), predPlanes)) {
|
||||
boolean hasBackFace = null != c.getRules().getPictureOtherSideUrl();
|
||||
String baseName = c.getImageKey(false, c.getArtIndex(), true);
|
||||
boolean hasBackFacePciture = null != c.getRules().getPictureOtherSideUrl();
|
||||
String baseName = ImageCache.getImageKey(c,false, true);
|
||||
_nameUpdates.put(baseName + ".full.jpg", baseName + ".jpg");
|
||||
if (hasBackFace) {
|
||||
baseName = c.getImageKey(true, c.getArtIndex(), true);
|
||||
if (hasBackFacePciture) {
|
||||
baseName = ImageCache.getImageKey(c, true, true);
|
||||
_nameUpdates.put(baseName + ".full.jpg", baseName + ".jpg");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.card.CardRules;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
@@ -40,12 +41,12 @@ public class GuiDownloadPicturesLQ extends GuiDownloader {
|
||||
ArrayList<DownloadObject> downloads = new ArrayList<DownloadObject>();
|
||||
Set<String> filenames = new HashSet<String>();
|
||||
|
||||
for (CardPrinted c : CardDb.instance().getUniqueCards()) {
|
||||
for (CardPrinted c : CardDb.instance().getAllCards()) {
|
||||
addDLObject(c, false, downloads, filenames);
|
||||
addDLObject(c, true, downloads, filenames);
|
||||
}
|
||||
|
||||
for (CardPrinted c : CardDb.variants().getUniqueCards()) {
|
||||
for (CardPrinted c : CardDb.variants().getAllCards()) {
|
||||
addDLObject(c, false, downloads, filenames);
|
||||
addDLObject(c, true, downloads, filenames);
|
||||
}
|
||||
@@ -63,11 +64,10 @@ public class GuiDownloadPicturesLQ extends GuiDownloader {
|
||||
return;
|
||||
}
|
||||
|
||||
int artIdx = -1;
|
||||
for (String url : urls.split("\\\\")) {
|
||||
++artIdx;
|
||||
|
||||
String filename = c.getImageKey(backFace, artIdx, false);
|
||||
for (String url : urls.split("\\\\")) {
|
||||
|
||||
String filename = ImageCache.getImageKey(c, backFace, false);
|
||||
if (filenames.contains(filename)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardSplitType;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.properties.NewConstants;
|
||||
@@ -40,16 +43,16 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
|
||||
|
||||
for (final CardPrinted c : Iterables.concat(CardDb.instance().getAllCards(), CardDb.variants().getAllCards())) {
|
||||
final String setCode3 = c.getEdition();
|
||||
if (StringUtils.isBlank(setCode3) || "???".equals(setCode3)) {
|
||||
if (StringUtils.isBlank(setCode3) || CardEdition.UNKNOWN.getCode().equals(setCode3)) {
|
||||
// we don't want cards from unknown sets
|
||||
continue;
|
||||
}
|
||||
|
||||
addDLObject(c.getImageUrlPath(false), c.getImageKey(), downloads);
|
||||
String url = ImageCache.getImageLocator(c, ImageCache.getImageName(c), true, true);
|
||||
addDLObject(url, ImageCache.getImageKey(c), downloads);
|
||||
|
||||
String backFaceImage = c.getImageKey(true);
|
||||
if (backFaceImage != null) {
|
||||
addDLObject(c.getImageUrlPath(true), backFaceImage, downloads);
|
||||
if ( c.getRules().getSplitType() == CardSplitType.Transform ) {
|
||||
String url2 = ImageCache.getImageLocator(c, c.getRules().getOtherPart().getName(), true, true);
|
||||
addDLObject(url2, ImageCache.getImageKey(c, true), downloads);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ package forge.item;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.card.BoosterData;
|
||||
import forge.card.CardEdition;
|
||||
@@ -38,11 +37,6 @@ public class BoosterPack extends OpenablePack {
|
||||
super(name0, boosterData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getImageKey() {
|
||||
return ImageCache.BOOSTER_PREFIX + this.contents.getEdition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getItemType() {
|
||||
return "Booster Pack";
|
||||
|
||||
@@ -24,13 +24,10 @@ import com.google.common.base.Function;
|
||||
|
||||
import forge.Card;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardInSet;
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardSplitType;
|
||||
import forge.card.cardfactory.CardFactory;
|
||||
import forge.game.player.Player;
|
||||
import forge.util.Base64Coder;
|
||||
|
||||
|
||||
/**
|
||||
@@ -61,11 +58,6 @@ public final class CardPrinted implements Comparable<IPaperCard>, InventoryItemF
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEdition() {
|
||||
return this.edition;
|
||||
@@ -81,6 +73,11 @@ public final class CardPrinted implements Comparable<IPaperCard>, InventoryItemF
|
||||
return this.foiled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToken() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CardRules getRules() {
|
||||
return this.card;
|
||||
@@ -91,99 +88,14 @@ public final class CardPrinted implements Comparable<IPaperCard>, InventoryItemF
|
||||
return this.rarity;
|
||||
}
|
||||
|
||||
private static String toMWSFilename(String in) {
|
||||
final StringBuffer out = new StringBuffer();
|
||||
char c;
|
||||
for (int i = 0; i < in.length(); i++) {
|
||||
c = in.charAt(i);
|
||||
if ((c == '"') || (c == '/') || (c == ':') || (c == '?')) {
|
||||
out.append("");
|
||||
} else {
|
||||
out.append(c);
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
private String getImageName() {
|
||||
return CardSplitType.Split != card.getSplitType() ? name : card.getMainPart().getName() + card.getOtherPart().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImageKey() {
|
||||
return getImageLocator(getImageName(), getArtIndex(), true, false);
|
||||
}
|
||||
|
||||
public String getImageKey(boolean backFace) {
|
||||
return getImageKey(backFace, getArtIndex(), true);
|
||||
}
|
||||
// @Override
|
||||
// public String getImageKey() {
|
||||
// return getImageLocator(getImageName(), getArtIndex(), true, false);
|
||||
// }
|
||||
|
||||
public String getImageKey(boolean backFace, int artIdx, boolean includeSet) {
|
||||
final String nameToUse;
|
||||
if (backFace) {
|
||||
if (null == card.getOtherPart()) {
|
||||
return null;
|
||||
}
|
||||
switch (card.getSplitType()) {
|
||||
case Transform: case Flip: case Licid:
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
nameToUse = card.getOtherPart().getName();
|
||||
} else {
|
||||
nameToUse = getImageName();
|
||||
}
|
||||
|
||||
return getImageLocator(nameToUse, artIdx, includeSet, false);
|
||||
}
|
||||
|
||||
public String getImageUrlPath(boolean backFace) {
|
||||
return getImageLocator(backFace ? card.getOtherPart().getName() : getImageName(), getArtIndex(), true, true);
|
||||
}
|
||||
|
||||
private String getImageLocator(String nameToUse, int artIdx, boolean includeSet, boolean base64encode) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
|
||||
s.append(toMWSFilename(nameToUse));
|
||||
|
||||
final int cntPictures;
|
||||
if (includeSet) {
|
||||
cntPictures = card.getEditionInfo(edition).getCopiesCount();
|
||||
} else {
|
||||
// raise the art index limit to the maximum of the sets this card was printed in
|
||||
int maxCntPictures = 1;
|
||||
for (String set : card.getSets()) {
|
||||
CardInSet setInfo = card.getEditionInfo(set);
|
||||
if (maxCntPictures < setInfo.getCopiesCount()) {
|
||||
maxCntPictures = setInfo.getCopiesCount();
|
||||
}
|
||||
}
|
||||
cntPictures = maxCntPictures;
|
||||
}
|
||||
if (cntPictures > 1 && cntPictures > artIdx) {
|
||||
s.append(artIdx + 1);
|
||||
}
|
||||
|
||||
// for whatever reason, MWS-named plane cards don't have the ".full" infix
|
||||
if (!card.getType().isPlane() && !card.getType().isPhenomenon()) {
|
||||
s.append(".full");
|
||||
}
|
||||
|
||||
final String fname;
|
||||
if (base64encode) {
|
||||
s.append(".jpg");
|
||||
fname = Base64Coder.encodeString(s.toString(), true);
|
||||
} else {
|
||||
fname = s.toString();
|
||||
}
|
||||
|
||||
if (includeSet) {
|
||||
return String.format("%s/%s", Singletons.getModel().getEditions().getCode2ByCode(edition), fname);
|
||||
} else {
|
||||
return fname;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemType() {
|
||||
@@ -353,9 +265,4 @@ public final class CardPrinted implements Comparable<IPaperCard>, InventoryItemF
|
||||
// TODO compare sets properly
|
||||
return this.edition.compareTo(o.getEdition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToken() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ public class CardToken implements InventoryItemFromSet, IPaperCard {
|
||||
}
|
||||
|
||||
@Override public String getName() { return name; }
|
||||
@Override public String getDescription() { return name; }
|
||||
|
||||
@Override public String getEdition() { return edition.getCode(); }
|
||||
|
||||
@@ -61,7 +60,8 @@ public class CardToken implements InventoryItemFromSet, IPaperCard {
|
||||
|
||||
@Override public CardRarity getRarity() { return CardRarity.Common; } // They don't have rarity though!
|
||||
|
||||
@Override public String getImageKey() { return imageFileName; }
|
||||
// Unfortunately this is a property of token, cannot move it outside of class
|
||||
public String getImageFilename() { return imageFileName; }
|
||||
|
||||
@Override public String getItemType() { return "Token"; }
|
||||
@Override public Card getMatchingForgeCard() { return toForgeCard(null); } // hope this won't be queried too frequently, so no cache
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.List;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.FatPackData;
|
||||
@@ -51,12 +50,6 @@ public class FatPack extends OpenablePack {
|
||||
return fpData.toString() + contents.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getImageKey() {
|
||||
return ImageCache.FATPACK_PREFIX + this.contents.getEdition();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final String getItemType() {
|
||||
return "Fat Pack";
|
||||
|
||||
@@ -15,7 +15,7 @@ import forge.card.CardRules;
|
||||
import forge.game.player.Player;
|
||||
import forge.util.PredicateString;
|
||||
|
||||
public interface IPaperCard {
|
||||
public interface IPaperCard extends InventoryItem {
|
||||
|
||||
/**
|
||||
* Number of filters based on CardPrinted values.
|
||||
@@ -155,7 +155,6 @@ public interface IPaperCard {
|
||||
public abstract boolean isToken();
|
||||
public abstract CardRules getRules();
|
||||
public abstract CardRarity getRarity();
|
||||
public abstract String getImageKey();
|
||||
|
||||
public abstract String getItemType();
|
||||
|
||||
|
||||
@@ -30,13 +30,6 @@ public interface InventoryItem {
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* An inventory item has to provide a picture.
|
||||
*
|
||||
* @return the image filename
|
||||
*/
|
||||
String getImageKey();
|
||||
|
||||
/**
|
||||
* Return type as a string.
|
||||
*
|
||||
|
||||
@@ -22,11 +22,6 @@ package forge.item;
|
||||
* CardPrinted, Booster, Pets, Plants... etc
|
||||
*/
|
||||
public interface InventoryItemFromSet extends InventoryItem {
|
||||
/**
|
||||
* The description to display for the item
|
||||
*/
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* An item belonging to a set should return its set as well.
|
||||
*
|
||||
|
||||
@@ -47,7 +47,6 @@ public abstract class OpenablePack implements InventoryItemFromSet {
|
||||
return this.name + " " + this.getItemType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return contents.toString();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.Map;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.quest.SellRules;
|
||||
@@ -38,6 +37,10 @@ public class PreconDeck implements InventoryItemFromSet {
|
||||
|
||||
private final Deck deck;
|
||||
private final String imageFilename;
|
||||
public final String getImageFilename() {
|
||||
return imageFilename;
|
||||
}
|
||||
|
||||
private final String set;
|
||||
private final String description;
|
||||
|
||||
@@ -53,16 +56,6 @@ public class PreconDeck implements InventoryItemFromSet {
|
||||
return this.deck.getName();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.item.InventoryItemFromSet#getImageFilename()
|
||||
*/
|
||||
@Override
|
||||
public String getImageKey() {
|
||||
return ImageCache.PRECON_PREFIX + imageFilename;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
@@ -132,7 +125,6 @@ public class PreconDeck implements InventoryItemFromSet {
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
@Override
|
||||
public final String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.List;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.card.BoosterData;
|
||||
import forge.card.BoosterGenerator;
|
||||
@@ -42,11 +41,6 @@ public class TournamentPack extends OpenablePack {
|
||||
super(name0, boosterData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getImageKey() {
|
||||
return ImageCache.TOURNAMENTPACK_PREFIX + contents.getEdition();
|
||||
}
|
||||
|
||||
public final boolean isStarterDeck() {
|
||||
return contents.getCommon() < 30;
|
||||
}
|
||||
|
||||
@@ -121,16 +121,6 @@ public abstract class QuestRewardCard implements InventoryItem, IQuestRewardCard
|
||||
return filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* A QuestRewardCardChooser ought to always be resolved to an actual card, hence no images.
|
||||
*
|
||||
* @return an empty string
|
||||
*/
|
||||
@Override
|
||||
public String getImageKey() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public abstract List<CardPrinted> getChoices();
|
||||
|
||||
}
|
||||
@@ -35,16 +35,6 @@ public class QuestRewardCardDuplicate implements IQuestRewardCard {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is a dynamic list of cards, hence no images.
|
||||
*
|
||||
* @return an empty string
|
||||
*/
|
||||
@Override
|
||||
public String getImageKey() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* The item type.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user