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
* that the images may be garbage collected when they are not needed any more, but will
* be kept as long as possible.
* 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>#<type>#<collectorID>#<param>"
*
@ -46,8 +46,7 @@ public class ImageCache {
private static final Map<String, BufferedImage> imageCache;
/**
* Common pattern for keys.
* Format: "<cardname>#<setname>#<collectorID>"
* Common pattern for keys. Format: "<cardname>#<setname>#<collectorID>"
*/
private static final Pattern KEY_PATTERN = Pattern.compile("(.*)#(.*)#(.*)#(.*)#(.*)");
@ -104,16 +103,16 @@ public class ImageCache {
thumbnailFile = new TFile(thumbnailPath);
} catch (Exception ex) {
}
boolean exists =false;
boolean exists = false;
if (thumbnailFile != null) {
try {
exists = thumbnailFile.exists();
} catch(Exception ex) {
} catch (Exception ex) {
exists = false;
}
}
if (exists) {
log.debug("loading thumbnail for " + key + ", path="+thumbnailPath);
log.debug("loading thumbnail for " + key + ", path=" + thumbnailPath);
return loadImage(thumbnailFile);
} else {
BufferedImage image = loadImage(file);
@ -187,30 +186,15 @@ public class ImageCache {
}
public static BufferedImage getThumbnail(CardView card) {
String key = getKey(card) + "#thumb";
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
// log.debug("#key: " + key);
return getImage(key);
return getImage(getKey(card, card.getName(), "#thumb"));
}
public static BufferedImage getImageOriginal(CardView card) {
String key = getKey(card);
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
// log.warn("#key: " + key);
return getImage(key);
return getImage(getKey(card, card.getName(), ""));
}
public static BufferedImage getImageOriginalAlternateName(CardView card) {
String key = getKeyAlternateName(card, card.getAlternateName());
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
// log.warn("#key: " + key);
return getImage(key);
return getImage(getKey(card, card.getAlternateName(), ""));
}
/**
@ -230,7 +214,7 @@ public class ImageCache {
if (ex.getCause() instanceof NullPointerException) {
return null;
}
log.error(ex,ex);
log.error(ex, ex);
return null;
}
}
@ -238,32 +222,25 @@ public class ImageCache {
/**
* Returns the map key for a card, without any suffixes for the image size.
*/
private static String getKey(CardView card) {
StringBuilder sb = new StringBuilder(card.getName()).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) {
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();
private static String getKey(CardView card, String name, String suffix) {
return name + "#" + card.getExpansionSetCode() + "#" + card.getType() + "#" + card.getCardNumber() + "#"
+ (card.getTokenSetCode() == null ? "" : card.getTokenSetCode())
+ suffix
+ (card.getUsesVariousArt() ? "#usesVariousArt" : "");
}
// /**
// * 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
*
* @param file
* file to load image from
* @param file file to load image from
* @return {@link BufferedImage}
*/
public static BufferedImage loadImage(TFile file) {
@ -297,7 +274,7 @@ public class ImageCache {
ImageIO.write(image, "jpg", outputStream);
}
} catch (IOException e) {
log.error(e,e);
log.error(e, e);
imageFile.delete();
}
return image;
@ -305,6 +282,7 @@ public class ImageCache {
/**
* Returns an image scaled to the size given
*
* @param original
* @return
*/
@ -344,6 +322,7 @@ public class ImageCache {
/**
* Returns an image scaled to the size appropriate for the card picture
* panel
*
* @param original
* @param sizeNeed
* @return
@ -356,6 +335,7 @@ public class ImageCache {
/**
* Returns the image appropriate to display the card in the picture panel
*
* @param card
* @param width
* @param height
@ -365,11 +345,7 @@ public class ImageCache {
if (Constants.THUMBNAIL_SIZE_FULL.width + 10 > width) {
return getThumbnail(card);
}
String key = getKey(card);
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
// log.warn("getImage: " + key);
String key = getKey(card, card.getName(), "");
BufferedImage original = getImage(key);
if (original == null) {
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}");
this.expansionSetCode = "BFZ";
this.subtype.add("Gideon");
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.
@ -69,7 +69,7 @@ public class GideonAllyOfZendikar extends CardImpl {
effect.setText("Prevent all damage that would be dealt to him this turn");
ability.addEffect(effect);
this.addAbility(ability);
// 0: Put a 2/2 white Knight Ally creature token onto the battlefield.
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);
Ability ability = new SimpleStaticAbility(Zone.COMMAND, effect);
this.getAbilities().add(ability);
this.setExpansionSetCodeForImage("BFZ");
}
}
@ -107,8 +108,8 @@ class GideonAllyOfZendikarToken extends Token {
subtype.add("Ally");
power = 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);
toughness = new MageInt(2);
}
}
}

View file

@ -173,8 +173,8 @@ class KioraRevealEffect extends OneShotEffect {
if (!cards.isEmpty()) {
player.revealCards(sourceObject.getName(), cards, game);
if ((creatureCardFound || landCardFound)
&& player.chooseUse(Outcome.DrawCard,
if ((creatureCardFound || landCardFound)
&& player.chooseUse(Outcome.DrawCard,
"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"));
if (creatureCardFound && player.choose(Outcome.DrawCard, cards, target, game)) {
@ -208,12 +208,13 @@ class KioraMasterOfTheDepthsEmblem extends Emblem {
public KioraMasterOfTheDepthsEmblem() {
this.setName("EMBLEM: Kiora, Master of the Depths");
Ability ability = new EntersBattlefieldControlledTriggeredAbility(Zone.COMMAND,
new KioraFightEffect(), filter, true, SetTargetPointer.PERMANENT,
"Whenever a creature enters the battlefield under your control, you may have it fight target creature.");
ability.addTarget(new TargetCreaturePermanent());
this.getAbilities().add(ability);
this.setExpansionSetCodeForImage("BFZ");
}
}

View file

@ -100,6 +100,7 @@ class ObNixilisReignitedEmblem extends Emblem {
setName("EMBLEM: Ob Nixilis Reignited");
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.
*
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
*
* 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
* provided with the distribution.
*
*
* 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
* 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
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* 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
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.permanent.token;
import java.util.Random;
import mage.MageInt;
import mage.Mana;
import mage.abilities.costs.common.SacrificeSourceCost;
@ -49,7 +49,24 @@ public class EldraziScionToken extends Token {
power = new MageInt(1);
toughness = new MageInt(1);
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.
}
}