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 downloadName;
private String set; private String set;
private Integer collectorId; private Integer collectorId;
private Integer type;
private boolean token; private boolean token;
private boolean twoFacedCard; private boolean twoFacedCard;
private boolean secondSide; private boolean secondSide;
private boolean flipCard; private boolean flipCard;
public CardInfo(String name, String set, Integer collectorId) { public CardInfo(String name, String set, Integer collectorId, Integer type) {
this.name = name; this(name, set, collectorId, type, false);
this.set = set;
this.collectorId = collectorId;
token = false;
} }
public CardInfo(String name, String set, Integer collectorId, boolean token) { public CardInfo(String name, String set, Integer collectorId, Integer type, boolean token) {
this.name = name; this(name, set, collectorId, type, token, false, false);
this.set = set;
this.collectorId = collectorId;
this.token = token;
} }
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.name = name;
this.set = set; this.set = set;
this.collectorId = collectorId; this.collectorId = collectorId;
this.type = type;
this.token = token; this.token = token;
this.twoFacedCard = twoFacedCard; this.twoFacedCard = twoFacedCard;
this.secondSide = secondSide; this.secondSide = secondSide;
@ -45,6 +41,7 @@ public class CardInfo {
this.token = card.token; this.token = card.token;
this.twoFacedCard = card.twoFacedCard; this.twoFacedCard = card.twoFacedCard;
this.secondSide = card.secondSide; this.secondSide = card.secondSide;
this.type = card.type;
} }
@Override @Override
@ -83,6 +80,7 @@ public class CardInfo {
hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0); hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
hash = 47 * hash + (this.set != null ? this.set.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.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.token ? 1 : 0);
hash = 47 * hash + (this.twoFacedCard ? 1 : 0); hash = 47 * hash + (this.twoFacedCard ? 1 : 0);
hash = 47 * hash + (this.secondSide ? 1 : 0); hash = 47 * hash + (this.secondSide ? 1 : 0);
@ -144,4 +142,12 @@ public class CardInfo {
public void setFlipCard(boolean flipCard) { public void setFlipCard(boolean flipCard) {
this.flipCard = 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; File file;
for (Card card : allCards) { for (Card card : allCards) {
if (card.getCardNumber() > 0 && !card.getExpansionSetCode().isEmpty()) { 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; boolean withCollectorId = false;
if (card.getName().equals("Forest") || card.getName().equals("Mountain") || card.getName().equals("Swamp") || card.getName().equals("Island") || card.getName().equals("Plains")) { if (card.getName().equals("Forest") || card.getName().equals("Mountain") || card.getName().equals("Swamp") || card.getName().equals("Island") || card.getName().equals("Plains")) {
withCollectorId = true; withCollectorId = true;
@ -242,7 +242,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
for (Card card : allCards) { for (Card card : allCards) {
if (card.getCardNumber() > 0 && !card.getExpansionSetCode().isEmpty()) { if (card.getCardNumber() > 0 && !card.getExpansionSetCode().isEmpty()) {
String cardName = card.getName(); 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")) { 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() + ".", "")); 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 // it has the same expansion set code and card number as original one
// second side = true; // second side = true;
Card secondSide = card.getSecondCardFace(); 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); allCardsUrls.add(url);
} }
} else { } else {
@ -335,7 +335,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
if (params.length >= 4) { if (params.length >= 4) {
if (params[1].toLowerCase().equals("generate") && params[2].startsWith("TOK:")) { if (params[1].toLowerCase().equals("generate") && params[2].startsWith("TOK:")) {
String set = params[2].substring(4); 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); list.add(card);
} }
} else { } else {

View file

@ -1,32 +1,28 @@
package org.mage.plugins.card.images; 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.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; 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 * 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. * be kept as long as possible.
* *
* Key format: "<cardname>#<setname>#<collectorID>#<param>" * Key format: "<cardname>#<setname>#<type>#<collectorID>#<param>"
* *
* where param is: * where param is:
* *
@ -47,7 +43,7 @@ public class ImageCache {
* Common pattern for keys. * Common pattern for keys.
* Format: "<cardname>#<setname>#<collectorID>" * Format: "<cardname>#<setname>#<collectorID>"
*/ */
private static final Pattern KEY_PATTERN = Pattern.compile("(.*)#(.*)#(.*)"); private static final Pattern KEY_PATTERN = Pattern.compile("(.*)#(.*)#(.*)#(.*)");
static { static {
imageCache = new MapMaker().softValues().makeComputingMap(new Function<String, BufferedImage>() { imageCache = new MapMaker().softValues().makeComputingMap(new Function<String, BufferedImage>() {
@ -64,9 +60,10 @@ public class ImageCache {
if (m.matches()) { if (m.matches()) {
String name = m.group(1); String name = m.group(1);
String set = m.group(2); 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); if (collectorId == 0) info.setToken(true);
String path = CardImageUtils.getImagePath(info); String path = CardImageUtils.getImagePath(info);
@ -153,7 +150,8 @@ public class ImageCache {
*/ */
private static String getKey(CardView card) { private static String getKey(CardView card) {
String set = card.getExpansionSetCode(); 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; return key;
} }

View file

@ -1,12 +1,12 @@
package org.mage.plugins.card.utils; 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.constants.Constants;
import org.mage.plugins.card.images.CardInfo; import org.mage.plugins.card.images.CardInfo;
import org.mage.plugins.card.properties.SettingsManager; import org.mage.plugins.card.properties.SettingsManager;
import java.io.File;
import java.util.HashMap;
public class CardImageUtils { public class CardImageUtils {
private static HashMap<CardInfo, String> pathCache = new HashMap<CardInfo, String>(); 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) { 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"; return getImageDir(card, imagesPath) + File.separator + card.getName() + "." + card.getCollectorId() + ".full.jpg";
} else { } else {
return getImageDir(card, imagesPath) + File.separator + card.getName() + ".full.jpg"; return getImageDir(card, imagesPath) + File.separator + card.getName() + type + ".full.jpg";
} }
} }
} }

View file

@ -68,6 +68,7 @@ public class CardView extends SimpleCardView {
protected Rarity rarity; protected Rarity rarity;
protected boolean isAbility; protected boolean isAbility;
protected CardView ability; protected CardView ability;
protected int type;
protected boolean canTransform; protected boolean canTransform;
protected CardView secondCardFace; protected CardView secondCardFace;
@ -112,6 +113,9 @@ public class CardView extends SimpleCardView {
this.canTransform = card.canTransform(); this.canTransform = card.canTransform();
if (card instanceof PermanentToken) { if (card instanceof PermanentToken) {
this.rarity = Rarity.COMMON; this.rarity = Rarity.COMMON;
this.expansionSetCode = ((PermanentToken) card).getExpansionSetCode();
this.rules = ((PermanentToken) card).getRules();
this.type = ((PermanentToken)card).getToken().getTokenType();
} else { } else {
this.rarity = card.getRarity(); this.rarity = card.getRarity();
} }
@ -151,6 +155,7 @@ public class CardView extends SimpleCardView {
this.rarity = Rarity.COMMON; this.rarity = Rarity.COMMON;
this.expansionSetCode = ((PermanentToken) card).getExpansionSetCode(); this.expansionSetCode = ((PermanentToken) card).getExpansionSetCode();
this.rules = ((PermanentToken) card).getRules(); this.rules = ((PermanentToken) card).getRules();
this.type = ((PermanentToken)card).getToken().getTokenType();
} }
if (name.equals("") && card instanceof StackAbility) { if (name.equals("") && card instanceof StackAbility) {
StackAbility stackAbility = (StackAbility)card; StackAbility stackAbility = (StackAbility)card;
@ -211,6 +216,7 @@ public class CardView extends SimpleCardView {
this.color = token.getColor(); this.color = token.getColor();
this.manaCost = token.getManaCost().getSymbols(); this.manaCost = token.getManaCost().getSymbols();
this.rarity = Rarity.NA; this.rarity = Rarity.NA;
this.type = token.getTokenType();
//this.expansionSetCode = ""; //this.expansionSetCode = "";
} }
@ -379,4 +385,8 @@ public class CardView extends SimpleCardView {
public UUID getPairedCard() { public UUID getPairedCard() {
return pairedCard; return pairedCard;
} }
public int getType() {
return type;
}
} }

View file

@ -104,8 +104,6 @@ public class PermanentToken extends PermanentImpl<PermanentToken> {
return token; return token;
} }
@Override @Override
public PermanentToken copy() { public PermanentToken copy() {
return new PermanentToken(this); return new PermanentToken(this);

View file

@ -28,8 +28,6 @@
package mage.game.permanent.token; package mage.game.permanent.token;
import java.util.List;
import java.util.UUID;
import mage.Constants.CardType; import mage.Constants.CardType;
import mage.Constants.Zone; import mage.Constants.Zone;
import mage.MageObjectImpl; import mage.MageObjectImpl;
@ -43,10 +41,14 @@ import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.PermanentToken; import mage.game.permanent.PermanentToken;
import java.util.List;
import java.util.UUID;
public class Token extends MageObjectImpl<Token> { public class Token extends MageObjectImpl<Token> {
protected String description; protected String description;
private UUID lastAddedTokenId; private UUID lastAddedTokenId;
private int tokenType;
public Token(String name, String description) { public Token(String name, String description) {
this.name = name; this.name = name;
@ -68,6 +70,7 @@ public class Token extends MageObjectImpl<Token> {
public Token(final Token token) { public Token(final Token token) {
super(token); super(token);
this.description = token.description; this.description = token.description;
this.tokenType = token.tokenType;
} }
public String getDescription() { public String getDescription() {
@ -107,4 +110,12 @@ public class Token extends MageObjectImpl<Token> {
} }
return false; return false;
} }
public int getTokenType() {
return tokenType;
}
public void setTokenType(int tokenType) {
this.tokenType = tokenType;
}
} }