mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
update ImageFetcher & CardImageRenderer
- allow zoomed cards to fetch image if possible
This commit is contained in:
@@ -712,20 +712,22 @@ public class CardImageRenderer {
|
||||
x += pieceWidths[i];
|
||||
}
|
||||
}
|
||||
static class CachedCardImageRenderer extends CachedCardImage {
|
||||
|
||||
public CachedCardImageRenderer(String key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImageFetched() {
|
||||
ImageCache.clear();
|
||||
}
|
||||
}
|
||||
public static void drawZoom(Graphics g, CardView card, GameView gameView, boolean altState, float x, float y, float w, float h, float dispW, float dispH, boolean isCurrentCard) {
|
||||
boolean canshow = MatchController.instance.mayView(card);
|
||||
Texture image = null;
|
||||
try {
|
||||
image = ImageCache.getImage(card.getState(altState).getImageKey(), true);
|
||||
} catch (Exception ex) {
|
||||
//System.err.println(card.toString()+" : " +ex.getMessage());
|
||||
//TODO: don't know why this is needed, needs further investigation...
|
||||
if (!card.hasAlternateState()) {
|
||||
altState = false;
|
||||
image = ImageCache.getImage(card.getState(altState).getImageKey(), true);
|
||||
}
|
||||
}
|
||||
String key = card.getState(altState).getImageKey();
|
||||
Texture image = new CachedCardImageRenderer(key).getImage();
|
||||
|
||||
FImage sleeves = MatchController.getPlayerSleeve(card.getOwner());
|
||||
if (image == null) { //draw details if can't draw zoom
|
||||
drawDetails(g, card, gameView, altState, x, y, w, h);
|
||||
|
||||
@@ -148,6 +148,16 @@ public abstract class ImageFetcher {
|
||||
if (useArtCrop) {
|
||||
filename = TextUtil.fastReplace(filename, ".full", ".artcrop");
|
||||
}
|
||||
boolean updateLink = false;
|
||||
if ("back".equals(face)) {// seems getimage relative path don't process variants for back faces.
|
||||
try {
|
||||
filename = TextUtil.fastReplace(filename, "1.full", imageKey.substring(imageKey.lastIndexOf('|') + 1, imageKey.indexOf('$')) + ".full");
|
||||
updateLink = true;
|
||||
} catch (Exception e) {
|
||||
filename = paperCard.getCardAltImageKey();
|
||||
updateLink = false;
|
||||
}
|
||||
}
|
||||
destFile = new File(ForgeConstants.CACHE_CARD_PICS_DIR, filename + ".jpg");
|
||||
|
||||
//skip ftp if using art crop
|
||||
@@ -155,8 +165,14 @@ public abstract class ImageFetcher {
|
||||
//move priority of ftp image here
|
||||
StringBuilder setDownload = new StringBuilder(ForgeConstants.URL_PIC_DOWNLOAD);
|
||||
if (!hasSetLookup) {
|
||||
setDownload.append(ImageUtil.getDownloadUrl(paperCard, face));
|
||||
downloadUrls.add(setDownload.toString());
|
||||
if (!updateLink) {
|
||||
setDownload.append(ImageUtil.getDownloadUrl(paperCard, face));
|
||||
downloadUrls.add(setDownload.toString());
|
||||
} else {
|
||||
String url = ImageUtil.getDownloadUrl(paperCard, face);
|
||||
setDownload.append(TextUtil.fastReplace(url, "1.full", imageKey.substring(imageKey.lastIndexOf('|') + 1, imageKey.indexOf('$')) + ".full"));
|
||||
downloadUrls.add(setDownload.toString());
|
||||
}
|
||||
} else {
|
||||
List<PaperCard> clones = StaticData.instance().getCommonCards().getAllCards(paperCard.getName());
|
||||
for (PaperCard pc : clones) {
|
||||
@@ -234,15 +250,13 @@ public abstract class ImageFetcher {
|
||||
observers.add(callback);
|
||||
currentFetches.put(destPath, observers);
|
||||
|
||||
final Runnable notifyObservers = new Runnable() {
|
||||
public void run() {
|
||||
FThreads.assertExecutedByEdt(true);
|
||||
final Runnable notifyObservers = () -> {
|
||||
FThreads.assertExecutedByEdt(true);
|
||||
|
||||
for (Callback o : currentFetches.get(destPath)) {
|
||||
o.onImageFetched();
|
||||
}
|
||||
currentFetches.remove(destPath);
|
||||
for (Callback o : currentFetches.get(destPath)) {
|
||||
o.onImageFetched();
|
||||
}
|
||||
currentFetches.remove(destPath);
|
||||
};
|
||||
try {
|
||||
ThreadUtil.getServicePool().submit(getDownloadTask(downloadUrls.toArray(new String[0]), destPath, notifyObservers));
|
||||
|
||||
Reference in New Issue
Block a user