Added token type for displaying different images

This commit is contained in:
magenoxx 2012-06-12 22:58:21 +04:00
parent 9b2864044c
commit 4393a55569
7 changed files with 69 additions and 45 deletions

View file

@ -10,29 +10,25 @@ public class CardInfo {
private String downloadName;
private String set;
private Integer collectorId;
private Integer type;
private boolean token;
private boolean twoFacedCard;
private boolean secondSide;
private boolean flipCard;
public CardInfo(String name, String set, Integer collectorId) {
this.name = name;
this.set = set;
this.collectorId = collectorId;
token = false;
public CardInfo(String name, String set, Integer collectorId, Integer type) {
this(name, set, collectorId, type, false);
}
public CardInfo(String name, String set, Integer collectorId, boolean token) {
this.name = name;
this.set = set;
this.collectorId = collectorId;
this.token = token;
public CardInfo(String name, String set, Integer collectorId, Integer type, boolean token) {
this(name, set, collectorId, type, token, false, false);
}
public CardInfo(String name, String set, Integer collectorId, boolean token, boolean twoFacedCard, boolean secondSide) {
public CardInfo(String name, String set, Integer collectorId, Integer type, boolean token, boolean twoFacedCard, boolean secondSide) {
this.name = name;
this.set = set;
this.collectorId = collectorId;
this.type = type;
this.token = token;
this.twoFacedCard = twoFacedCard;
this.secondSide = secondSide;
@ -45,6 +41,7 @@ public class CardInfo {
this.token = card.token;
this.twoFacedCard = card.twoFacedCard;
this.secondSide = card.secondSide;
this.type = card.type;
}
@Override
@ -83,6 +80,7 @@ public class CardInfo {
hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
hash = 47 * hash + (this.set != null ? this.set.hashCode() : 0);
hash = 47 * hash + (this.collectorId != null ? this.collectorId.hashCode() : 0);
hash = 47 * hash + (this.type != null ? this.type.hashCode() : 0);
hash = 47 * hash + (this.token ? 1 : 0);
hash = 47 * hash + (this.twoFacedCard ? 1 : 0);
hash = 47 * hash + (this.secondSide ? 1 : 0);
@ -144,4 +142,12 @@ public class CardInfo {
public void setFlipCard(boolean flipCard) {
this.flipCard = flipCard;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
}

View file

@ -214,7 +214,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
File file;
for (Card card : allCards) {
if (card.getCardNumber() > 0 && !card.getExpansionSetCode().isEmpty()) {
CardInfo url = new CardInfo(card.getName(), card.getExpansionSetCode(), card.getCardNumber(), false, card.canTransform(), card.isNightCard());
CardInfo url = new CardInfo(card.getName(), card.getExpansionSetCode(), card.getCardNumber(), 0, false, card.canTransform(), card.isNightCard());
boolean withCollectorId = false;
if (card.getName().equals("Forest") || card.getName().equals("Mountain") || card.getName().equals("Swamp") || card.getName().equals("Island") || card.getName().equals("Plains")) {
withCollectorId = true;
@ -242,7 +242,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
for (Card card : allCards) {
if (card.getCardNumber() > 0 && !card.getExpansionSetCode().isEmpty()) {
String cardName = card.getName();
CardInfo url = new CardInfo(cardName, card.getExpansionSetCode(), card.getCardNumber(), false, card.canTransform(), card.isNightCard());
CardInfo url = new CardInfo(cardName, card.getExpansionSetCode(), card.getCardNumber(), 0, false, card.canTransform(), card.isNightCard());
if (cardName.equals("Forest") || cardName.equals("Swamp") || cardName.equals("Mountain") || cardName.equals("Island") || cardName.equals("Plains")) {
url.setDownloadName(card.getClass().getName().replace(card.getClass().getPackage().getName() + ".", ""));
}
@ -255,7 +255,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
// it has the same expansion set code and card number as original one
// second side = true;
Card secondSide = card.getSecondCardFace();
url = new CardInfo(secondSide.getName(), card.getExpansionSetCode(), card.getCardNumber(), false, card.canTransform(), true);
url = new CardInfo(secondSide.getName(), card.getExpansionSetCode(), card.getCardNumber(), 0, false, card.canTransform(), true);
allCardsUrls.add(url);
}
} else {
@ -335,7 +335,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
if (params.length >= 4) {
if (params[1].toLowerCase().equals("generate") && params[2].startsWith("TOK:")) {
String set = params[2].substring(4);
CardInfo card = new CardInfo(params[3], set, 0, true);
CardInfo card = new CardInfo(params[3], set, 0, 0, true);
list.add(card);
}
} else {

View file

@ -1,32 +1,28 @@
package org.mage.plugins.card.images;
import java.awt.Rectangle;
import com.google.common.base.Function;
import com.google.common.collect.ComputationException;
import com.google.common.collect.MapMaker;
import com.mortennobel.imagescaling.ResampleOp;
import mage.view.CardView;
import org.apache.log4j.Logger;
import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.utils.CardImageUtils;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import mage.view.CardView;
import org.apache.log4j.Logger;
import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.utils.CardImageUtils;
import com.google.common.base.Function;
import com.google.common.collect.ComputationException;
import com.google.common.collect.MapMaker;
import com.mortennobel.imagescaling.ResampleOp;
import java.awt.Graphics2D;
/**
* This class stores ALL card images in a cache with soft values. this means
* that the images may be collected when they are not needed any more, but will
* that the images may be garbage collected when they are not needed any more, but will
* be kept as long as possible.
*
* Key format: "<cardname>#<setname>#<collectorID>#<param>"
* Key format: "<cardname>#<setname>#<type>#<collectorID>#<param>"
*
* where param is:
*
@ -47,7 +43,7 @@ public class ImageCache {
* Common pattern for keys.
* Format: "<cardname>#<setname>#<collectorID>"
*/
private static final Pattern KEY_PATTERN = Pattern.compile("(.*)#(.*)#(.*)");
private static final Pattern KEY_PATTERN = Pattern.compile("(.*)#(.*)#(.*)#(.*)");
static {
imageCache = new MapMaker().softValues().makeComputingMap(new Function<String, BufferedImage>() {
@ -64,9 +60,10 @@ public class ImageCache {
if (m.matches()) {
String name = m.group(1);
String set = m.group(2);
Integer collectorId = Integer.parseInt(m.group(3));
Integer type = Integer.parseInt(m.group(3));
Integer collectorId = Integer.parseInt(m.group(4));
CardInfo info = new CardInfo(name, set, collectorId);
CardInfo info = new CardInfo(name, set, collectorId, type);
if (collectorId == 0) info.setToken(true);
String path = CardImageUtils.getImagePath(info);
@ -153,7 +150,8 @@ public class ImageCache {
*/
private static String getKey(CardView card) {
String set = card.getExpansionSetCode();
String key = card.getName() + "#" + set + "#" + String.valueOf(card.getCardNumber());
int type = card.getType();
String key = card.getName() + "#" + set + "#" + type + "#" + String.valueOf(card.getCardNumber());
return key;
}

View file

@ -1,12 +1,12 @@
package org.mage.plugins.card.utils;
import java.io.File;
import java.util.HashMap;
import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.images.CardInfo;
import org.mage.plugins.card.properties.SettingsManager;
import java.io.File;
import java.util.HashMap;
public class CardImageUtils {
private static HashMap<CardInfo, String> pathCache = new HashMap<CardInfo, String>();
@ -145,10 +145,11 @@ public class CardImageUtils {
}
public static String getImagePath(CardInfo card, boolean withCollector, String imagesPath) {
if (withCollector) {
String type = card.getType() != 0 ? " " + Integer.toString(card.getType()) : "";
if (withCollector) {
return getImageDir(card, imagesPath) + File.separator + card.getName() + "." + card.getCollectorId() + ".full.jpg";
} else {
return getImageDir(card, imagesPath) + File.separator + card.getName() + ".full.jpg";
return getImageDir(card, imagesPath) + File.separator + card.getName() + type + ".full.jpg";
}
}
}