mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
Added token type for displaying different images
This commit is contained in:
parent
9b2864044c
commit
4393a55569
7 changed files with 69 additions and 45 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ public class CardView extends SimpleCardView {
|
|||
protected Rarity rarity;
|
||||
protected boolean isAbility;
|
||||
protected CardView ability;
|
||||
protected int type;
|
||||
|
||||
protected boolean canTransform;
|
||||
protected CardView secondCardFace;
|
||||
|
@ -112,6 +113,9 @@ public class CardView extends SimpleCardView {
|
|||
this.canTransform = card.canTransform();
|
||||
if (card instanceof PermanentToken) {
|
||||
this.rarity = Rarity.COMMON;
|
||||
this.expansionSetCode = ((PermanentToken) card).getExpansionSetCode();
|
||||
this.rules = ((PermanentToken) card).getRules();
|
||||
this.type = ((PermanentToken)card).getToken().getTokenType();
|
||||
} else {
|
||||
this.rarity = card.getRarity();
|
||||
}
|
||||
|
@ -151,6 +155,7 @@ public class CardView extends SimpleCardView {
|
|||
this.rarity = Rarity.COMMON;
|
||||
this.expansionSetCode = ((PermanentToken) card).getExpansionSetCode();
|
||||
this.rules = ((PermanentToken) card).getRules();
|
||||
this.type = ((PermanentToken)card).getToken().getTokenType();
|
||||
}
|
||||
if (name.equals("") && card instanceof StackAbility) {
|
||||
StackAbility stackAbility = (StackAbility)card;
|
||||
|
@ -211,6 +216,7 @@ public class CardView extends SimpleCardView {
|
|||
this.color = token.getColor();
|
||||
this.manaCost = token.getManaCost().getSymbols();
|
||||
this.rarity = Rarity.NA;
|
||||
this.type = token.getTokenType();
|
||||
//this.expansionSetCode = "";
|
||||
}
|
||||
|
||||
|
@ -379,4 +385,8 @@ public class CardView extends SimpleCardView {
|
|||
public UUID getPairedCard() {
|
||||
return pairedCard;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,8 +104,6 @@ public class PermanentToken extends PermanentImpl<PermanentToken> {
|
|||
return token;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public PermanentToken copy() {
|
||||
return new PermanentToken(this);
|
||||
|
|
|
@ -28,8 +28,6 @@
|
|||
|
||||
package mage.game.permanent.token;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Zone;
|
||||
import mage.MageObjectImpl;
|
||||
|
@ -43,10 +41,14 @@ import mage.game.events.GameEvent.EventType;
|
|||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.game.permanent.PermanentToken;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Token extends MageObjectImpl<Token> {
|
||||
|
||||
protected String description;
|
||||
private UUID lastAddedTokenId;
|
||||
private int tokenType;
|
||||
|
||||
public Token(String name, String description) {
|
||||
this.name = name;
|
||||
|
@ -68,6 +70,7 @@ public class Token extends MageObjectImpl<Token> {
|
|||
public Token(final Token token) {
|
||||
super(token);
|
||||
this.description = token.description;
|
||||
this.tokenType = token.tokenType;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
|
@ -107,4 +110,12 @@ public class Token extends MageObjectImpl<Token> {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getTokenType() {
|
||||
return tokenType;
|
||||
}
|
||||
|
||||
public void setTokenType(int tokenType) {
|
||||
this.tokenType = tokenType;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue