mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Add an explicit field MciCode to edition .txt file, since neither Code nor Code2 matches what magiccards.info uses. Use it for image fetching.
This commit is contained in:
@@ -25,7 +25,7 @@ public class ImageFetcher {
|
||||
private static HashMap<String, HashSet<Callback>> currentFetches = new HashMap<>();
|
||||
private static HashMap<String, String> tokenImages;
|
||||
|
||||
public static void fetchImage(CardView card, final String imageKey, Callback cachedImage) {
|
||||
public static void fetchImage(final CardView card, final String imageKey, final Callback callback) {
|
||||
FThreads.assertExecutedByEdt(true);
|
||||
|
||||
final String prefix = imageKey.substring(0, 2);
|
||||
@@ -50,7 +50,8 @@ public class ImageFetcher {
|
||||
if (paperCard.getRules().getOtherPart() != null) {
|
||||
suffix = (backFace ? "b" : "a");
|
||||
}
|
||||
urlToDownload = String.format("http://magiccards.info/scans/en/%s/%d%s.jpg", editionCode2.toLowerCase(), cardNum, suffix);
|
||||
final String editionMciCode = data.getEditions().getMciCodeByCode(paperCard.getEdition());
|
||||
urlToDownload = String.format("http://magiccards.info/scans/en/%s/%d%s.jpg", editionMciCode, cardNum, suffix);
|
||||
} else {
|
||||
// Fall back to using Forge's LQ card downloaded from Wizards' website. This currently only works for older cards.
|
||||
String[] result = ImageUtil.getDownloadUrlAndDestination(ForgeConstants.CACHE_CARD_PICS_DIR, paperCard, backFace);
|
||||
@@ -89,12 +90,12 @@ public class ImageFetcher {
|
||||
HashSet<Callback> observers = currentFetches.get(destPath);
|
||||
if (observers != null) {
|
||||
// Already in the queue, simply add the new observer.
|
||||
observers.add(cachedImage);
|
||||
observers.add(callback);
|
||||
return;
|
||||
}
|
||||
|
||||
observers = new HashSet<>();
|
||||
observers.add(cachedImage);
|
||||
observers.add(callback);
|
||||
currentFetches.put(destPath, observers);
|
||||
|
||||
final Runnable notifyObservers = new Runnable() {
|
||||
@@ -125,7 +126,7 @@ public class ImageFetcher {
|
||||
System.out.println("Saved image to " + destPath);
|
||||
SwingUtilities.invokeLater(notifyObservers);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Failed to download card image: " + e.getMessage());
|
||||
System.err.println("Failed to download card [" + imageKey + "] image: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user