mirror of
https://github.com/correl/mage.git
synced 2025-01-11 19:13:02 +00:00
Merge pull request #2217 from spjspj/master
spjspj - Implement new method for image generation of tokens.
This commit is contained in:
commit
0c89b81da0
15 changed files with 154 additions and 52 deletions
|
@ -12,6 +12,7 @@ public class CardDownloadData {
|
|||
private String downloadName;
|
||||
private String set;
|
||||
private String tokenSetCode;
|
||||
private String tokenDescriptor;
|
||||
private String collectorId;
|
||||
private Integer type;
|
||||
private boolean token;
|
||||
|
@ -23,15 +24,15 @@ public class CardDownloadData {
|
|||
private boolean usesVariousArt;
|
||||
private boolean isType2;
|
||||
|
||||
public CardDownloadData(String name, String set, String collectorId, boolean usesVariousArt, Integer type, String tokenSetCode) {
|
||||
this(name, set, collectorId, usesVariousArt, type, tokenSetCode, false);
|
||||
public CardDownloadData(String name, String set, String collectorId, boolean usesVariousArt, Integer type, String tokenSetCode, String tokenDescriptor) {
|
||||
this(name, set, collectorId, usesVariousArt, type, tokenSetCode, tokenDescriptor, false);
|
||||
}
|
||||
|
||||
public CardDownloadData(String name, String set, String collectorId, boolean usesVariousArt, Integer type, String tokenSetCode, boolean token) {
|
||||
this(name, set, collectorId, usesVariousArt, type, tokenSetCode, token, false, false);
|
||||
public CardDownloadData(String name, String set, String collectorId, boolean usesVariousArt, Integer type, String tokenSetCode, String tokenDescriptor, boolean token) {
|
||||
this(name, set, collectorId, usesVariousArt, type, tokenSetCode, tokenDescriptor, token, false, false);
|
||||
}
|
||||
|
||||
public CardDownloadData(String name, String set, String collectorId, boolean usesVariousArt, Integer type, String tokenSetCode, boolean token, boolean twoFacedCard, boolean secondSide) {
|
||||
public CardDownloadData(String name, String set, String collectorId, boolean usesVariousArt, Integer type, String tokenSetCode, String tokenDescriptor, boolean token, boolean twoFacedCard, boolean secondSide) {
|
||||
this.name = name;
|
||||
this.set = set;
|
||||
this.collectorId = collectorId;
|
||||
|
@ -41,6 +42,7 @@ public class CardDownloadData {
|
|||
this.twoFacedCard = twoFacedCard;
|
||||
this.secondSide = secondSide;
|
||||
this.tokenSetCode = tokenSetCode;
|
||||
this.tokenDescriptor = tokenDescriptor;
|
||||
}
|
||||
|
||||
public CardDownloadData(final CardDownloadData card) {
|
||||
|
@ -117,7 +119,7 @@ public class CardDownloadData {
|
|||
public String getSet() {
|
||||
return set;
|
||||
}
|
||||
|
||||
|
||||
public void setSet(String set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
@ -130,6 +132,13 @@ public class CardDownloadData {
|
|||
this.tokenSetCode = tokenSetCode;
|
||||
}
|
||||
|
||||
public String getTokenDescriptor() {
|
||||
return tokenDescriptor;
|
||||
}
|
||||
|
||||
public void setTokenDescriptor(String tokenDescriptor) {
|
||||
this.tokenDescriptor = tokenDescriptor;
|
||||
}
|
||||
public boolean isToken() {
|
||||
return token;
|
||||
}
|
||||
|
|
|
@ -239,7 +239,8 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
TFile file;
|
||||
for (CardInfo card : allCards) {
|
||||
if (!card.getCardNumber().isEmpty() && !"0".equals(card.getCardNumber()) && !card.getSetCode().isEmpty()) {
|
||||
CardDownloadData url = new CardDownloadData(card.getName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", false, card.isDoubleFaced(), card.isNightCard());
|
||||
CardDownloadData url = new CardDownloadData(card.getName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(),
|
||||
0, "", "", false, card.isDoubleFaced(), card.isNightCard());
|
||||
file = new TFile(CardImageUtils.generateImagePath(url));
|
||||
if (!file.exists()) {
|
||||
return true;
|
||||
|
@ -285,7 +286,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
&& !ignoreUrls.contains(card.getSetCode())) {
|
||||
String cardName = card.getName();
|
||||
boolean isType2 = type2SetsFilter.contains(card.getSetCode());
|
||||
CardDownloadData url = new CardDownloadData(cardName, card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", false, card.isDoubleFaced(), card.isNightCard());
|
||||
CardDownloadData url = new CardDownloadData(cardName, card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), card.isNightCard());
|
||||
if (url.getUsesVariousArt()) {
|
||||
url.setDownloadName(createDownloadName(card));
|
||||
}
|
||||
|
@ -299,7 +300,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
if (card.getSecondSideName() == null || card.getSecondSideName().trim().isEmpty()) {
|
||||
throw new IllegalStateException("Second side card can't have empty name.");
|
||||
}
|
||||
url = new CardDownloadData(card.getSecondSideName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", false, card.isDoubleFaced(), true);
|
||||
url = new CardDownloadData(card.getSecondSideName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), true);
|
||||
url.setType2(isType2);
|
||||
allCardsUrls.add(url);
|
||||
}
|
||||
|
@ -307,7 +308,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
if (card.getFlipCardName() == null || card.getFlipCardName().trim().isEmpty()) {
|
||||
throw new IllegalStateException("Flipped card can't have empty name.");
|
||||
}
|
||||
url = new CardDownloadData(card.getFlipCardName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", false, card.isDoubleFaced(), card.isNightCard());
|
||||
url = new CardDownloadData(card.getFlipCardName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), card.isNightCard());
|
||||
url.setFlipCard(true);
|
||||
url.setFlippedSide(true);
|
||||
url.setType2(isType2);
|
||||
|
@ -385,19 +386,19 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
}
|
||||
if (params[1].toLowerCase().equals("generate") && params[2].startsWith("TOK:")) {
|
||||
String set = params[2].substring(4);
|
||||
CardDownloadData card = new CardDownloadData(params[3], set, "0", false, type, "", true);
|
||||
CardDownloadData card = new CardDownloadData(params[3], set, "0", false, type, "", "", true);
|
||||
list.add(card);
|
||||
} else if (params[1].toLowerCase().equals("generate") && params[2].startsWith("EMBLEM:")) {
|
||||
String set = params[2].substring(7);
|
||||
CardDownloadData card = new CardDownloadData("Emblem " + params[3], set, "0", false, type, "", true);
|
||||
CardDownloadData card = new CardDownloadData("Emblem " + params[3], set, "0", false, type, "", "", true);
|
||||
list.add(card);
|
||||
} else if (params[1].toLowerCase().equals("generate") && params[2].startsWith("EMBLEM-:")) {
|
||||
String set = params[2].substring(8);
|
||||
CardDownloadData card = new CardDownloadData(params[3] + " Emblem", set, "0", false, type, "", true);
|
||||
CardDownloadData card = new CardDownloadData(params[3] + " Emblem", set, "0", false, type, "", "", true);
|
||||
list.add(card);
|
||||
} else if (params[1].toLowerCase().equals("generate") && params[2].startsWith("EMBLEM!:")) {
|
||||
String set = params[2].substring(8);
|
||||
CardDownloadData card = new CardDownloadData(params[3], set, "0", false, type, "", true);
|
||||
CardDownloadData card = new CardDownloadData(params[3], set, "0", false, type, "", "", true);
|
||||
list.add(card);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -47,7 +47,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 {
|
||||
IMAGE_CACHE = new MapMaker().softValues().makeComputingMap(new Function<String, BufferedImage>() {
|
||||
|
@ -56,12 +56,12 @@ public class ImageCache {
|
|||
try {
|
||||
|
||||
boolean usesVariousArt = false;
|
||||
if (key.endsWith("#usesVariousArt")) {
|
||||
if (key.matches(".*#usesVariousArt.*")) {
|
||||
usesVariousArt = true;
|
||||
key = key.replace("#usesVariousArt", "");
|
||||
}
|
||||
boolean thumbnail = false;
|
||||
if (key.endsWith("#thumb")) {
|
||||
if (key.matches(".*#thumb.*")) {
|
||||
thumbnail = true;
|
||||
key = key.replace("#thumb", "");
|
||||
}
|
||||
|
@ -76,8 +76,9 @@ public class ImageCache {
|
|||
collectorId = "0";
|
||||
}
|
||||
String tokenSetCode = m.group(5);
|
||||
String tokenDescriptor = m.group(6);
|
||||
|
||||
CardDownloadData info = new CardDownloadData(name, set, collectorId, usesVariousArt, type, tokenSetCode);
|
||||
CardDownloadData info = new CardDownloadData(name, set, collectorId, usesVariousArt, type, tokenSetCode, tokenDescriptor);
|
||||
|
||||
String path;
|
||||
if (collectorId.isEmpty() || "0".equals(collectorId)) {
|
||||
|
@ -154,7 +155,7 @@ public class ImageCache {
|
|||
}
|
||||
|
||||
public static BufferedImage getMorphImage() {
|
||||
CardDownloadData info = new CardDownloadData("Morph", "KTK", "0", false, 0, "KTK");
|
||||
CardDownloadData info = new CardDownloadData("Morph", "KTK", "0", false, 0, "KTK", "");
|
||||
info.setToken(true);
|
||||
String path = CardImageUtils.generateTokenImagePath(info);
|
||||
if (path == null) {
|
||||
|
@ -165,7 +166,7 @@ public class ImageCache {
|
|||
}
|
||||
|
||||
public static BufferedImage getManifestImage() {
|
||||
CardDownloadData info = new CardDownloadData("Manifest", "FRF", "0", false, 0, "FRF");
|
||||
CardDownloadData info = new CardDownloadData("Manifest", "FRF", "0", false, 0, "FRF", "");
|
||||
info.setToken(true);
|
||||
String path = CardImageUtils.generateTokenImagePath(info);
|
||||
if (path == null) {
|
||||
|
@ -238,8 +239,8 @@ public class ImageCache {
|
|||
return name + "#" + card.getExpansionSetCode() + "#" + card.getType() + "#" + card.getCardNumber() + "#"
|
||||
+ (card.getTokenSetCode() == null ? "" : card.getTokenSetCode())
|
||||
+ suffix
|
||||
+ (card.getUsesVariousArt() ? "#usesVariousArt" : "");
|
||||
|
||||
+ (card.getUsesVariousArt() ? "#usesVariousArt" : "")
|
||||
+ (card.getTokenDescriptor() != null ? "#" + card.getTokenDescriptor() : "#");
|
||||
}
|
||||
|
||||
// /**
|
||||
|
|
|
@ -42,7 +42,7 @@ public class CardImageUtils {
|
|||
return filePath;
|
||||
}
|
||||
}
|
||||
log.warn("Token image file not found: " + card.getTokenSetCode() + " - " + card.getName());
|
||||
log.warn("Token image file not found: " + card.getTokenSetCode() + " - " + card.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,11 @@ public class CardImageUtils {
|
|||
String filename = generateImagePath(card);
|
||||
|
||||
TFile file = new TFile(filename);
|
||||
if (!file.exists()) {
|
||||
filename = generateTokenDescriptorImagePath(card);
|
||||
}
|
||||
|
||||
file = new TFile(filename);
|
||||
if (!file.exists()) {
|
||||
CardDownloadData updated = new CardDownloadData(card);
|
||||
updated.setName(card.getName() + " 1");
|
||||
|
@ -86,7 +91,7 @@ public class CardImageUtils {
|
|||
// return path;
|
||||
// }
|
||||
// }
|
||||
return "";
|
||||
return generateTokenDescriptorImagePath(card);
|
||||
}
|
||||
|
||||
public static String updateSet(String cardSet, boolean forUrl) {
|
||||
|
@ -102,17 +107,28 @@ public class CardImageUtils {
|
|||
|
||||
private static String getImageDir(CardDownloadData card, String imagesPath) {
|
||||
if (card.getSet() == null) {
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
String set = updateSet(card.getSet(), false).toUpperCase();
|
||||
String imagesDir = (imagesPath != null ? imagesPath : Constants.IO.imageBaseDir);
|
||||
String imagesDir = (imagesPath != null ? imagesPath : Constants.IO.imageBaseDir);
|
||||
if (card.isToken()) {
|
||||
return buildTokenPath(imagesDir, set);
|
||||
} else {
|
||||
return buildPath(imagesDir, set);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String getTokenDescriptorImagePath(CardDownloadData card) {
|
||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||
String imagesPath = useDefault.equals("true") ? null : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||
|
||||
if (PreferencesDialog.isSaveImagesToZip()) {
|
||||
return imagesPath + TFile.separator + "TOK" + ".zip" + TFile.separator + card.getTokenDescriptor() + ".full.jpg";
|
||||
} else {
|
||||
return imagesPath + TFile.separator + "TOK" + TFile.separator + card.getTokenDescriptor() + ".full.jpg";
|
||||
}
|
||||
}
|
||||
|
||||
private static String buildTokenPath(String imagesDir, String set) {
|
||||
if (PreferencesDialog.isSaveImagesToZip()) {
|
||||
return imagesDir + TFile.separator + "TOK" + ".zip" + TFile.separator + set;
|
||||
|
@ -156,7 +172,31 @@ public class CardImageUtils {
|
|||
|
||||
return imageDir + TFile.separator + imageName;
|
||||
}
|
||||
|
||||
|
||||
public static String generateTokenDescriptorImagePath(CardDownloadData card) {
|
||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||
String imagesPath = useDefault.equals("true") ? null : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||
|
||||
String straightImageFile = getTokenDescriptorImagePath(card);
|
||||
TFile file = new TFile(straightImageFile);
|
||||
if (file.exists()) {
|
||||
return straightImageFile;
|
||||
}
|
||||
|
||||
straightImageFile = straightImageFile.replaceFirst("\\.[0-9]+\\.[0-9]+", ".X.X");
|
||||
file = new TFile(straightImageFile);
|
||||
if (file.exists()) {
|
||||
return straightImageFile;
|
||||
}
|
||||
|
||||
straightImageFile = straightImageFile.replaceFirst("\\.X\\.X", ".S.S");
|
||||
file = new TFile(straightImageFile);
|
||||
if (file.exists()) {
|
||||
return straightImageFile;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static Proxy getProxyFromPreferences() {
|
||||
Preferences prefs = MageFrame.getPreferences();
|
||||
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
|
||||
|
|
|
@ -18,15 +18,15 @@ public class TokensMtgImageSourceTest {
|
|||
public void generateTokenUrlTest() throws Exception {
|
||||
CardImageSource imageSource = TokensMtgImageSource.getInstance();
|
||||
|
||||
String url = imageSource.generateTokenUrl(new CardDownloadData("Thopter", "ORI", "0", false, 1, "ORI"));
|
||||
String url = imageSource.generateTokenUrl(new CardDownloadData("Thopter", "ORI", "0", false, 1, "ORI", ""));
|
||||
Assert.assertEquals("http://tokens.mtg.onl/tokens/ORI_010-Thopter.jpg", url);
|
||||
url = imageSource.generateTokenUrl(new CardDownloadData("Thopter", "ORI", "0", false, 2, "ORI"));
|
||||
url = imageSource.generateTokenUrl(new CardDownloadData("Thopter", "ORI", "0", false, 2, "ORI", ""));
|
||||
Assert.assertEquals("http://tokens.mtg.onl/tokens/ORI_011-Thopter.jpg", url);
|
||||
|
||||
url = imageSource.generateTokenUrl(new CardDownloadData("Ashaya, the Awoken World", "ORI", "0", false, 0, "ORI"));
|
||||
url = imageSource.generateTokenUrl(new CardDownloadData("Ashaya, the Awoken World", "ORI", "0", false, 0, "ORI", ""));
|
||||
Assert.assertEquals("http://tokens.mtg.onl/tokens/ORI_007-Ashaya,-the-Awoken-World.jpg", url);
|
||||
|
||||
url = imageSource.generateTokenUrl(new CardDownloadData("Emblem Gideon, Ally of Zendikar", "BFZ", "0", false, 0, null));
|
||||
url = imageSource.generateTokenUrl(new CardDownloadData("Emblem Gideon, Ally of Zendikar", "BFZ", "0", false, 0, null, ""));
|
||||
Assert.assertEquals("http://tokens.mtg.onl/tokens/BFZ_012-Gideon-Emblem.jpg", url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ public class CardView extends SimpleCardView {
|
|||
* @param storeZone if true the card zone will be set in the zone attribute.
|
||||
*/
|
||||
public CardView(Card card, Game game, boolean controlled, boolean showFaceDownCard, boolean storeZone) {
|
||||
super(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), card.getTokenSetCode(), game != null);
|
||||
super(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), card.getTokenSetCode(), game != null, card.getTokenDescriptor());
|
||||
// no information available for face down cards as long it's not a controlled face down morph card
|
||||
// TODO: Better handle this in Framework (but currently I'm not sure how to do it there) LevelX2
|
||||
boolean showFaceUp = true;
|
||||
|
@ -291,6 +291,7 @@ public class CardView extends SimpleCardView {
|
|||
} else {
|
||||
// a created token
|
||||
this.expansionSetCode = ((PermanentToken) card).getExpansionSetCode();
|
||||
this.tokenDescriptor = ((PermanentToken) card).getTokenDescriptor();
|
||||
}
|
||||
//
|
||||
// set code und card number for token copies to get the image
|
||||
|
@ -332,7 +333,7 @@ public class CardView extends SimpleCardView {
|
|||
}
|
||||
|
||||
public CardView(MageObject object) {
|
||||
super(object.getId(), "", "0", false, "", true);
|
||||
super(object.getId(), "", "0", false, "", true, "");
|
||||
this.name = object.getName();
|
||||
this.displayName = object.getName();
|
||||
if (object instanceof Permanent) {
|
||||
|
@ -376,7 +377,7 @@ public class CardView extends SimpleCardView {
|
|||
}
|
||||
|
||||
protected CardView() {
|
||||
super(null, "", "0", false, "", true);
|
||||
super(null, "", "0", false, "", true, "");
|
||||
}
|
||||
|
||||
public CardView(EmblemView emblem) {
|
||||
|
@ -393,7 +394,7 @@ public class CardView extends SimpleCardView {
|
|||
}
|
||||
|
||||
public CardView(boolean empty) {
|
||||
super(null, "", "0", false, "");
|
||||
super(null, "", "0", false, "", "");
|
||||
if (!empty) {
|
||||
throw new IllegalArgumentException("Not supported.");
|
||||
}
|
||||
|
@ -442,7 +443,7 @@ public class CardView extends SimpleCardView {
|
|||
}
|
||||
|
||||
CardView(Token token) {
|
||||
super(token.getId(), "", "0", false, "");
|
||||
super(token.getId(), "", "0", false, "", "");
|
||||
this.isToken = true;
|
||||
this.id = token.getId();
|
||||
this.name = token.getName();
|
||||
|
@ -459,6 +460,7 @@ public class CardView extends SimpleCardView {
|
|||
this.rarity = Rarity.NA;
|
||||
this.type = token.getTokenType();
|
||||
this.tokenSetCode = token.getOriginalExpansionSetCode();
|
||||
this.tokenDescriptor = token.getTokenDescriptor();
|
||||
}
|
||||
|
||||
protected final void setTargets(Targets targets) {
|
||||
|
|
|
@ -46,7 +46,7 @@ public class LookedAtView implements Serializable {
|
|||
public LookedAtView(String name, Cards cards, Game game) {
|
||||
this.name = name;
|
||||
for (Card card: cards.getCards(game)) {
|
||||
this.cards.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), card.getTokenSetCode()));
|
||||
this.cards.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), card.getTokenSetCode(), card.getTokenDescriptor()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ public class PermanentView extends CardView {
|
|||
original = new CardView(((PermanentToken) permanent).getToken());
|
||||
original.expansionSetCode = permanent.getExpansionSetCode();
|
||||
tokenSetCode = original.getTokenSetCode();
|
||||
tokenDescriptor = original.getTokenDescriptor();
|
||||
} else {
|
||||
if (card != null) {
|
||||
// original may not be face down
|
||||
|
|
|
@ -39,16 +39,18 @@ public class SimpleCardView implements Serializable {
|
|||
protected UUID id;
|
||||
protected String expansionSetCode;
|
||||
protected String tokenSetCode;
|
||||
protected String tokenDescriptor;
|
||||
protected String cardNumber;
|
||||
protected boolean usesVariousArt;
|
||||
protected boolean gameObject;
|
||||
|
||||
public SimpleCardView(UUID id, String expansionSetCode, String cardNumber, boolean usesVariousArt, String tokenSetCode) {
|
||||
this(id, expansionSetCode, cardNumber, usesVariousArt, tokenSetCode, false);
|
||||
public SimpleCardView(UUID id, String expansionSetCode, String cardNumber, boolean usesVariousArt, String tokenSetCode, String tokenDescriptor) {
|
||||
this(id, expansionSetCode, cardNumber, usesVariousArt, tokenSetCode, false, tokenDescriptor);
|
||||
}
|
||||
public SimpleCardView(UUID id, String expansionSetCode, String cardNumber, boolean usesVariousArt, String tokenSetCode, boolean isGameObject) {
|
||||
public SimpleCardView(UUID id, String expansionSetCode, String cardNumber, boolean usesVariousArt, String tokenSetCode, boolean isGameObject, String tokenDescriptor) {
|
||||
this.id = id;
|
||||
this.expansionSetCode = expansionSetCode;
|
||||
this.tokenDescriptor = tokenDescriptor;
|
||||
this.cardNumber = cardNumber;
|
||||
this.usesVariousArt = usesVariousArt;
|
||||
this.tokenSetCode = tokenSetCode;
|
||||
|
@ -74,6 +76,10 @@ public class SimpleCardView implements Serializable {
|
|||
public String getTokenSetCode() {
|
||||
return tokenSetCode;
|
||||
}
|
||||
|
||||
public String getTokenDescriptor() {
|
||||
return tokenDescriptor;
|
||||
}
|
||||
|
||||
public boolean isGameObject() {
|
||||
return gameObject;
|
||||
|
|
|
@ -44,7 +44,8 @@ public class SimpleCardsView extends LinkedHashMap<UUID, SimpleCardView> {
|
|||
|
||||
public SimpleCardsView(Collection<Card> cards, boolean isGameObject) {
|
||||
for (Card card: cards) {
|
||||
this.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), card.getTokenSetCode(), isGameObject));
|
||||
this.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), card.getTokenSetCode(), isGameObject,
|
||||
card.getTokenDescriptor()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,8 @@ public interface Card extends MageObject {
|
|||
String getExpansionSetCode();
|
||||
|
||||
String getTokenSetCode();
|
||||
|
||||
String getTokenDescriptor();
|
||||
|
||||
void checkForCountersToAdd(Permanent permanent, Game game);
|
||||
|
||||
|
|
|
@ -74,6 +74,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
|||
protected String cardNumber;
|
||||
public String expansionSetCode;
|
||||
protected String tokenSetCode;
|
||||
protected String tokenDescriptor;
|
||||
protected Rarity rarity;
|
||||
protected boolean canTransform;
|
||||
protected Card secondSideCard;
|
||||
|
@ -316,6 +317,11 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
|||
public String getTokenSetCode() {
|
||||
return tokenSetCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTokenDescriptor() {
|
||||
return tokenDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mana> getMana() {
|
||||
|
|
|
@ -86,6 +86,7 @@ public class PermanentToken extends PermanentImpl {
|
|||
this.toughness.modifyBaseValue(token.getToughness().getBaseValueModified());
|
||||
this.supertype = token.getSupertype();
|
||||
this.subtype = token.getSubtype();
|
||||
this.tokenDescriptor = token.getTokenDescriptor();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -55,6 +55,7 @@ public class Token extends MageObjectImpl {
|
|||
private int tokenType;
|
||||
private String originalCardNumber;
|
||||
private String originalExpansionSetCode;
|
||||
private String tokenDescriptor;
|
||||
private boolean expansionSetCodeChecked;
|
||||
private Card copySourceCard; // the card the Token is a copy from
|
||||
|
||||
|
@ -113,6 +114,26 @@ public class Token extends MageObjectImpl {
|
|||
this.copySourceCard = token.copySourceCard; // will never be changed
|
||||
this.availableImageSetCodes = token.availableImageSetCodes;
|
||||
}
|
||||
|
||||
private void setTokenDescriptor() {
|
||||
this.tokenDescriptor = tokenDescriptor();
|
||||
}
|
||||
|
||||
public String getTokenDescriptor() {
|
||||
this.tokenDescriptor = tokenDescriptor();
|
||||
return tokenDescriptor;
|
||||
}
|
||||
|
||||
private String tokenDescriptor() {
|
||||
String name = this.name.replaceAll("[^a-zA-Z0-9]", "");
|
||||
String color = this.color.toString().replaceAll("[^a-zA-Z0-9]", "");
|
||||
String subtype = this.subtype.toString().replaceAll("[^a-zA-Z0-9]", "");
|
||||
String cardType = this.cardType.toString().replaceAll("[^a-zA-Z0-9]", "");
|
||||
String originalset = this.getOriginalExpansionSetCode();
|
||||
String descriptor = name + "." + color + "." + subtype + "." + cardType + "." + this.power + "." + this.toughness ;
|
||||
descriptor = descriptor.toUpperCase();
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
|
@ -241,13 +262,14 @@ public class Token extends MageObjectImpl {
|
|||
public void setOriginalCardNumber(String originalCardNumber) {
|
||||
this.originalCardNumber = originalCardNumber;
|
||||
}
|
||||
|
||||
public String getOriginalExpansionSetCode() {
|
||||
|
||||
public String getOriginalExpansionSetCode() {
|
||||
return originalExpansionSetCode;
|
||||
}
|
||||
|
||||
public void setOriginalExpansionSetCode(String originalExpansionSetCode) {
|
||||
this.originalExpansionSetCode = originalExpansionSetCode;
|
||||
setTokenDescriptor();
|
||||
}
|
||||
|
||||
public Card getCopySourceCard() {
|
||||
|
@ -264,15 +286,20 @@ public class Token extends MageObjectImpl {
|
|||
if (availableImageSetCodes.size() > 0) {
|
||||
if (availableImageSetCodes.contains(code)) {
|
||||
setOriginalExpansionSetCode(code);
|
||||
} else // we should not set random set if appropriate set is already used
|
||||
if (getOriginalExpansionSetCode() == null || getOriginalExpansionSetCode().isEmpty()
|
||||
|| !availableImageSetCodes.contains(getOriginalExpansionSetCode())) {
|
||||
setOriginalExpansionSetCode(availableImageSetCodes.get(new Random().nextInt(availableImageSetCodes.size())));
|
||||
} else {
|
||||
// we should not set random set if appropriate set is already used
|
||||
if (getOriginalExpansionSetCode() == null || getOriginalExpansionSetCode().isEmpty()
|
||||
|| !availableImageSetCodes.contains(getOriginalExpansionSetCode())) {
|
||||
setOriginalExpansionSetCode(availableImageSetCodes.get(new Random().nextInt(availableImageSetCodes.size())));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (getOriginalExpansionSetCode() == null || getOriginalExpansionSetCode().isEmpty()) {
|
||||
setOriginalExpansionSetCode(code);
|
||||
}
|
||||
} else if (getOriginalExpansionSetCode() == null || getOriginalExpansionSetCode().isEmpty()) {
|
||||
setOriginalExpansionSetCode(code);
|
||||
}
|
||||
}
|
||||
setTokenDescriptor();
|
||||
}
|
||||
|
||||
public boolean updateExpansionSetCode(String setCode) {
|
||||
if (setCode == null || setCode.isEmpty()) {
|
||||
|
|
|
@ -572,6 +572,11 @@ public class Spell extends StackObjImpl implements Card {
|
|||
public String getTokenSetCode() {
|
||||
return card.getTokenSetCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTokenDescriptor() {
|
||||
return card.getTokenDescriptor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFaceDown(boolean value, Game game) {
|
||||
|
|
Loading…
Reference in a new issue