Some minor changes for BFZ token image handling.

This commit is contained in:
LevelX2 2015-09-23 19:53:25 +02:00
parent 2106b04017
commit 044e8b70f0
5 changed files with 64 additions and 68 deletions

View file

@ -25,8 +25,8 @@ import org.mage.plugins.card.utils.CardImageUtils;
/** /**
* 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 garbage collected when they are not needed any more, but will * that the images may be garbage collected when they are not needed any more,
* be kept as long as possible. * but will be kept as long as possible.
* *
* Key format: "<cardname>#<setname>#<type>#<collectorID>#<param>" * Key format: "<cardname>#<setname>#<type>#<collectorID>#<param>"
* *
@ -46,8 +46,7 @@ public class ImageCache {
private static final Map<String, BufferedImage> imageCache; private static final Map<String, BufferedImage> 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("(.*)#(.*)#(.*)#(.*)#(.*)");
@ -104,16 +103,16 @@ public class ImageCache {
thumbnailFile = new TFile(thumbnailPath); thumbnailFile = new TFile(thumbnailPath);
} catch (Exception ex) { } catch (Exception ex) {
} }
boolean exists =false; boolean exists = false;
if (thumbnailFile != null) { if (thumbnailFile != null) {
try { try {
exists = thumbnailFile.exists(); exists = thumbnailFile.exists();
} catch(Exception ex) { } catch (Exception ex) {
exists = false; exists = false;
} }
} }
if (exists) { if (exists) {
log.debug("loading thumbnail for " + key + ", path="+thumbnailPath); log.debug("loading thumbnail for " + key + ", path=" + thumbnailPath);
return loadImage(thumbnailFile); return loadImage(thumbnailFile);
} else { } else {
BufferedImage image = loadImage(file); BufferedImage image = loadImage(file);
@ -187,30 +186,15 @@ public class ImageCache {
} }
public static BufferedImage getThumbnail(CardView card) { public static BufferedImage getThumbnail(CardView card) {
String key = getKey(card) + "#thumb"; return getImage(getKey(card, card.getName(), "#thumb"));
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
// log.debug("#key: " + key);
return getImage(key);
} }
public static BufferedImage getImageOriginal(CardView card) { public static BufferedImage getImageOriginal(CardView card) {
String key = getKey(card); return getImage(getKey(card, card.getName(), ""));
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
// log.warn("#key: " + key);
return getImage(key);
} }
public static BufferedImage getImageOriginalAlternateName(CardView card) { public static BufferedImage getImageOriginalAlternateName(CardView card) {
String key = getKeyAlternateName(card, card.getAlternateName()); return getImage(getKey(card, card.getAlternateName(), ""));
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
// log.warn("#key: " + key);
return getImage(key);
} }
/** /**
@ -230,7 +214,7 @@ public class ImageCache {
if (ex.getCause() instanceof NullPointerException) { if (ex.getCause() instanceof NullPointerException) {
return null; return null;
} }
log.error(ex,ex); log.error(ex, ex);
return null; return null;
} }
} }
@ -238,32 +222,25 @@ public class ImageCache {
/** /**
* Returns the map key for a card, without any suffixes for the image size. * Returns the map key for a card, without any suffixes for the image size.
*/ */
private static String getKey(CardView card) { private static String getKey(CardView card, String name, String suffix) {
StringBuilder sb = new StringBuilder(card.getName()).append("#"); return name + "#" + card.getExpansionSetCode() + "#" + card.getType() + "#" + card.getCardNumber() + "#"
sb.append(card.getExpansionSetCode()).append("#"); + (card.getTokenSetCode() == null ? "" : card.getTokenSetCode())
sb.append(card.getType()).append("#"); + suffix
sb.append(card.getCardNumber()).append("#"); + (card.getUsesVariousArt() ? "#usesVariousArt" : "");
sb.append(card.getTokenSetCode() == null ? "":card.getTokenSetCode());
return sb.toString();
}
/**
* Returns the map key for the flip image of a card, without any suffixes for the image size.
*/
private static String getKeyAlternateName(CardView card, String alternateName) {
StringBuilder sb = new StringBuilder(alternateName).append("#");
sb.append(card.getExpansionSetCode()).append("#");
sb.append(card.getType()).append("#");
sb.append(card.getCardNumber()).append("#");
sb.append(card.getTokenSetCode() == null ? "":card.getTokenSetCode());
return sb.toString();
} }
// /**
// * Returns the map key for the flip image of a card, without any suffixes for the image size.
// */
// private static String getKeyAlternateName(CardView card, String alternateName) {
// return alternateName + "#" + card.getExpansionSetCode() + "#" +card.getType()+ "#" + card.getCardNumber() + "#"
// + (card.getTokenSetCode() == null ? "":card.getTokenSetCode());
// }
/** /**
* Load image from file * Load image from file
* *
* @param file * @param file file to load image from
* file to load image from
* @return {@link BufferedImage} * @return {@link BufferedImage}
*/ */
public static BufferedImage loadImage(TFile file) { public static BufferedImage loadImage(TFile file) {
@ -297,7 +274,7 @@ public class ImageCache {
ImageIO.write(image, "jpg", outputStream); ImageIO.write(image, "jpg", outputStream);
} }
} catch (IOException e) { } catch (IOException e) {
log.error(e,e); log.error(e, e);
imageFile.delete(); imageFile.delete();
} }
return image; return image;
@ -305,6 +282,7 @@ public class ImageCache {
/** /**
* Returns an image scaled to the size given * Returns an image scaled to the size given
*
* @param original * @param original
* @return * @return
*/ */
@ -344,6 +322,7 @@ public class ImageCache {
/** /**
* Returns an image scaled to the size appropriate for the card picture * Returns an image scaled to the size appropriate for the card picture
* panel * panel
*
* @param original * @param original
* @param sizeNeed * @param sizeNeed
* @return * @return
@ -356,6 +335,7 @@ public class ImageCache {
/** /**
* Returns the image appropriate to display the card in the picture panel * Returns the image appropriate to display the card in the picture panel
*
* @param card * @param card
* @param width * @param width
* @param height * @param height
@ -365,11 +345,7 @@ public class ImageCache {
if (Constants.THUMBNAIL_SIZE_FULL.width + 10 > width) { if (Constants.THUMBNAIL_SIZE_FULL.width + 10 > width) {
return getThumbnail(card); return getThumbnail(card);
} }
String key = getKey(card); String key = getKey(card, card.getName(), "");
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
// log.warn("getImage: " + key);
BufferedImage original = getImage(key); BufferedImage original = getImage(key);
if (original == null) { if (original == null) {
log.debug(key + " not found"); log.debug(key + " not found");

View file

@ -60,7 +60,7 @@ public class GideonAllyOfZendikar extends CardImpl {
super(ownerId, 29, "Gideon, Ally of Zendikar", Rarity.MYTHIC, new CardType[]{CardType.PLANESWALKER}, "{2}{W}{W}"); super(ownerId, 29, "Gideon, Ally of Zendikar", Rarity.MYTHIC, new CardType[]{CardType.PLANESWALKER}, "{2}{W}{W}");
this.expansionSetCode = "BFZ"; this.expansionSetCode = "BFZ";
this.subtype.add("Gideon"); this.subtype.add("Gideon");
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(4)), false)); this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(4)), false));
// +1: Until end of turn, Gideon, Ally of Zendikar becomes a 5/5 Human Soldier Ally creature with indestructible that's still a planeswalker. Prevent all damage that would be dealt to him this turn. // +1: Until end of turn, Gideon, Ally of Zendikar becomes a 5/5 Human Soldier Ally creature with indestructible that's still a planeswalker. Prevent all damage that would be dealt to him this turn.
@ -69,7 +69,7 @@ public class GideonAllyOfZendikar extends CardImpl {
effect.setText("Prevent all damage that would be dealt to him this turn"); effect.setText("Prevent all damage that would be dealt to him this turn");
ability.addEffect(effect); ability.addEffect(effect);
this.addAbility(ability); this.addAbility(ability);
// 0: Put a 2/2 white Knight Ally creature token onto the battlefield. // 0: Put a 2/2 white Knight Ally creature token onto the battlefield.
this.addAbility(new LoyaltyAbility(new CreateTokenEffect(new KnightAllyToken()), 0)); this.addAbility(new LoyaltyAbility(new CreateTokenEffect(new KnightAllyToken()), 0));
@ -94,6 +94,7 @@ class GideonAllyOfZendikarEmblem extends Emblem {
BoostControlledEffect effect = new BoostControlledEffect(1, 1, Duration.EndOfGame); BoostControlledEffect effect = new BoostControlledEffect(1, 1, Duration.EndOfGame);
Ability ability = new SimpleStaticAbility(Zone.COMMAND, effect); Ability ability = new SimpleStaticAbility(Zone.COMMAND, effect);
this.getAbilities().add(ability); this.getAbilities().add(ability);
this.setExpansionSetCodeForImage("BFZ");
} }
} }
@ -107,8 +108,8 @@ class GideonAllyOfZendikarToken extends Token {
subtype.add("Ally"); subtype.add("Ally");
power = new MageInt(5); power = new MageInt(5);
toughness = new MageInt(5); toughness = new MageInt(5);
addAbility(IndestructibleAbility.getInstance()); addAbility(IndestructibleAbility.getInstance());
} }
} }
@ -123,4 +124,4 @@ class KnightAllyToken extends Token {
power = new MageInt(2); power = new MageInt(2);
toughness = new MageInt(2); toughness = new MageInt(2);
} }
} }

View file

@ -173,8 +173,8 @@ class KioraRevealEffect extends OneShotEffect {
if (!cards.isEmpty()) { if (!cards.isEmpty()) {
player.revealCards(sourceObject.getName(), cards, game); player.revealCards(sourceObject.getName(), cards, game);
if ((creatureCardFound || landCardFound) if ((creatureCardFound || landCardFound)
&& player.chooseUse(Outcome.DrawCard, && player.chooseUse(Outcome.DrawCard,
"Put a creature card and/or a land card into your hand?", source, game)) { "Put a creature card and/or a land card into your hand?", source, game)) {
TargetCard target = new TargetCard(Zone.PICK, new FilterCreatureCard("creature card to put into your hand")); TargetCard target = new TargetCard(Zone.PICK, new FilterCreatureCard("creature card to put into your hand"));
if (creatureCardFound && player.choose(Outcome.DrawCard, cards, target, game)) { if (creatureCardFound && player.choose(Outcome.DrawCard, cards, target, game)) {
@ -208,12 +208,13 @@ class KioraMasterOfTheDepthsEmblem extends Emblem {
public KioraMasterOfTheDepthsEmblem() { public KioraMasterOfTheDepthsEmblem() {
this.setName("EMBLEM: Kiora, Master of the Depths"); this.setName("EMBLEM: Kiora, Master of the Depths");
Ability ability = new EntersBattlefieldControlledTriggeredAbility(Zone.COMMAND, Ability ability = new EntersBattlefieldControlledTriggeredAbility(Zone.COMMAND,
new KioraFightEffect(), filter, true, SetTargetPointer.PERMANENT, new KioraFightEffect(), filter, true, SetTargetPointer.PERMANENT,
"Whenever a creature enters the battlefield under your control, you may have it fight target creature."); "Whenever a creature enters the battlefield under your control, you may have it fight target creature.");
ability.addTarget(new TargetCreaturePermanent()); ability.addTarget(new TargetCreaturePermanent());
this.getAbilities().add(ability); this.getAbilities().add(ability);
this.setExpansionSetCodeForImage("BFZ");
} }
} }

View file

@ -100,6 +100,7 @@ class ObNixilisReignitedEmblem extends Emblem {
setName("EMBLEM: Ob Nixilis Reignited"); setName("EMBLEM: Ob Nixilis Reignited");
this.getAbilities().add(new ObNixilisEmblemTriggeredAbility(new LoseLifeSourceControllerEffect(2), false)); this.getAbilities().add(new ObNixilisEmblemTriggeredAbility(new LoseLifeSourceControllerEffect(2), false));
this.setExpansionSetCodeForImage("BFZ");
} }
} }

View file

@ -1,16 +1,16 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
@ -20,14 +20,14 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.game.permanent.token; package mage.game.permanent.token;
import java.util.Random;
import mage.MageInt; import mage.MageInt;
import mage.Mana; import mage.Mana;
import mage.abilities.costs.common.SacrificeSourceCost; import mage.abilities.costs.common.SacrificeSourceCost;
@ -49,7 +49,24 @@ public class EldraziScionToken extends Token {
power = new MageInt(1); power = new MageInt(1);
toughness = new MageInt(1); toughness = new MageInt(1);
addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, Mana.ColorlessMana, new SacrificeSourceCost())); addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, Mana.ColorlessMana, new SacrificeSourceCost()));
this.setOriginalExpansionSetCode("BFZ"); setOriginalExpansionSetCode("BFZ");
} }
@Override
public void setExpansionSetCodeForImage(String code) {
super.setExpansionSetCodeForImage(code);
if (getOriginalExpansionSetCode().equals("BFZ")) {
this.setTokenType(new Random().nextInt(3) + 1); // 3 different images
}
}
public EldraziScionToken(final EldraziScionToken token) {
super(token);
}
@Override
public EldraziScionToken copy() {
return new EldraziScionToken(this); //To change body of generated methods, choose Tools | Templates.
}
} }