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

View file

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