Fixed a image cache problem that prevented to show cards with different art correctly.

This commit is contained in:
LevelX2 2016-10-09 15:28:54 +02:00
parent 5b544ef28b
commit 27acaa5c9a
2 changed files with 30 additions and 17 deletions

View file

@ -63,7 +63,12 @@ public class CardPanelRenderImpl extends CardPanel {
if (!a.getRules().equals(b.getRules())) {
return false;
}
if (!a.getRarity().equals(b.getRarity())) {
return false;
}
if (!a.getCardNumber().equals(b.getCardNumber())) {
return false;
}
// Expansion set code, with null checking:
// TODO: The null checks should not be necessary, but thanks to Issue #2260
// some tokens / commandobjects will be missing expansion set codes.
@ -329,6 +334,7 @@ public class CardPanelRenderImpl extends CardPanel {
} else {
srcImage = ImageCache.getThumbnail(gameCard);
}
UI.invokeLater(new Runnable() {
@Override
public void run() {
@ -393,7 +399,7 @@ public class CardPanelRenderImpl extends CardPanel {
return ImageCache.loadImage(new TFile(DirectLinksForDownload.outDir + File.separator + DirectLinksForDownload.cardbackFilename));
}
}
@Override
public void setSelected(boolean selected) {
if (selected != isSelected()) {
@ -403,7 +409,7 @@ public class CardPanelRenderImpl extends CardPanel {
repaint();
}
}
@Override
public void setChoosable(boolean choosable) {
if (choosable != isChoosable()) {

View file

@ -1,6 +1,5 @@
package org.mage.plugins.card.images;
import mage.client.util.TransformedImageCache;
import com.google.common.base.Function;
import com.google.common.collect.ComputationException;
import com.google.common.collect.MapMaker;
@ -13,6 +12,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import mage.client.dialog.PreferencesDialog;
import mage.client.util.TransformedImageCache;
import mage.view.CardView;
import net.java.truevfs.access.TFile;
import net.java.truevfs.access.TFileInputStream;
@ -27,11 +27,12 @@ import org.mage.plugins.card.utils.CardImageUtils;
* 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>"
* Key format: "[cardname]#[setname]#[type]#[collectorID]#[param]"
*
* where param is:
*
* <ul>
* <li>size of image</li>
*
* <li>#Normal: request for unrotated image</li>
* <li>#Tapped: request for rotated image</li>
* <li>#Cropped: request for cropped image that is used for Shandalar like card
@ -56,6 +57,7 @@ public class ImageCache {
try {
boolean usesVariousArt = false;
LOGGER.info("Key load to CACHE: " + key);
if (key.matches(".*#usesVariousArt.*")) {
usesVariousArt = true;
key = key.replace("#usesVariousArt", "");
@ -127,7 +129,11 @@ public class ImageCache {
return makeThumbnailByFile(key, file, thumbnailPath);
}
} else {
return getWizardsCard(loadImage(file));
BufferedImage image = loadImage(file);
LOGGER.info("Basic image: @" + Integer.toHexString(image.hashCode()));
image = getWizardsCard(image);
LOGGER.info("Wizard image: @" + Integer.toHexString(image.hashCode()));
return image;
}
} else {
throw new RuntimeException(
@ -201,7 +207,7 @@ public class ImageCache {
public static BufferedImage getThumbnail(CardView card) {
return getImage(getKey(card, card.getName(), "#thumb"));
}
public static BufferedImage tryGetThumbnail(CardView card) {
return tryGetImage(getKey(card, card.getName(), "#thumb"));
}
@ -235,10 +241,10 @@ public class ImageCache {
return null;
}
}
/**
* Returns the Image corresponding to the key only if it already exists
* in the cache.
* Returns the Image corresponding to the key only if it already exists in
* the cache.
*/
private static BufferedImage tryGetImage(String key) {
if (IMAGE_CACHE.containsKey(key)) {
@ -360,15 +366,16 @@ public class ImageCache {
return TransformedImageCache.getResizedImage(original, (int) (original.getWidth() * scale), (int) (original.getHeight() * scale));
}
/**
* Returns the image appropriate to display for a card in a picture panel, but
* only it was ALREADY LOADED. That is, the call is immediate and will not block
* on file IO.
* Returns the image appropriate to display for a card in a picture panel,
* but only it was ALREADY LOADED. That is, the call is immediate and will
* not block on file IO.
*
* @param card
* @param width
* @param height
* @return
* @return
*/
public static BufferedImage tryGetImage(CardView card, int width, int height) {
if (Constants.THUMBNAIL_SIZE_FULL.width + 10 > width) {
@ -386,7 +393,7 @@ public class ImageCache {
return original;
}
return TransformedImageCache.getResizedImage(original, (int) (original.getWidth() * scale), (int) (original.getHeight() * scale));
return TransformedImageCache.getResizedImage(original, (int) (original.getWidth() * scale), (int) (original.getHeight() * scale));
}
public static TFile getTFile(String path) {