mirror of
https://github.com/correl/mage.git
synced 2025-03-17 01:06:26 -09:00
Some minor changes for BFZ token image handling.
This commit is contained in:
parent
2106b04017
commit
044e8b70f0
5 changed files with 64 additions and 68 deletions
|
@ -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");
|
||||||
|
|
|
@ -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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,6 +214,7 @@ class KioraMasterOfTheDepthsEmblem extends Emblem {
|
||||||
"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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,9 @@
|
||||||
* 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.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue