mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Download token images when token collector numbers are defined
This commit is contained in:
@@ -309,6 +309,7 @@ public final class CardEdition implements Comparable<CardEdition> {
|
|||||||
private String code;
|
private String code;
|
||||||
private String code2;
|
private String code2;
|
||||||
private String scryfallCode;
|
private String scryfallCode;
|
||||||
|
private String tokensCode;
|
||||||
private String cardsLanguage;
|
private String cardsLanguage;
|
||||||
private Type type;
|
private Type type;
|
||||||
private String name;
|
private String name;
|
||||||
@@ -403,6 +404,7 @@ public final class CardEdition implements Comparable<CardEdition> {
|
|||||||
public String getCode() { return code; }
|
public String getCode() { return code; }
|
||||||
public String getCode2() { return code2; }
|
public String getCode2() { return code2; }
|
||||||
public String getScryfallCode() { return scryfallCode.toLowerCase(); }
|
public String getScryfallCode() { return scryfallCode.toLowerCase(); }
|
||||||
|
public String getTokensCode() { return tokensCode.toLowerCase(); }
|
||||||
public String getCardsLangCode() { return cardsLanguage.toLowerCase(); }
|
public String getCardsLangCode() { return cardsLanguage.toLowerCase(); }
|
||||||
public Type getType() { return type; }
|
public Type getType() { return type; }
|
||||||
public String getName() { return name; }
|
public String getName() { return name; }
|
||||||
@@ -713,19 +715,10 @@ public final class CardEdition implements Comparable<CardEdition> {
|
|||||||
res.name = metadata.get("name");
|
res.name = metadata.get("name");
|
||||||
res.date = parseDate(metadata.get("date"));
|
res.date = parseDate(metadata.get("date"));
|
||||||
res.code = metadata.get("code");
|
res.code = metadata.get("code");
|
||||||
res.code2 = metadata.get("code2");
|
res.code2 = metadata.get("code2", res.code);
|
||||||
if (res.code2 == null) {
|
res.scryfallCode = metadata.get("ScryfallCode", res.code);
|
||||||
res.code2 = res.code;
|
res.tokensCode = metadata.get("TokensCode", "T" + res.scryfallCode);
|
||||||
}
|
res.cardsLanguage = metadata.get("CardLang", "en");
|
||||||
res.scryfallCode = metadata.get("ScryfallCode");
|
|
||||||
if (res.scryfallCode == null) {
|
|
||||||
res.scryfallCode = res.code;
|
|
||||||
}
|
|
||||||
res.cardsLanguage = metadata.get("CardLang");
|
|
||||||
if (res.cardsLanguage == null) {
|
|
||||||
res.cardsLanguage = "en";
|
|
||||||
}
|
|
||||||
|
|
||||||
res.boosterArts = metadata.getInt("BoosterCovers", 1);
|
res.boosterArts = metadata.getInt("BoosterCovers", 1);
|
||||||
|
|
||||||
String boosterDesc = metadata.get("Booster");
|
String boosterDesc = metadata.get("Booster");
|
||||||
|
|||||||
@@ -197,6 +197,13 @@ public class ImageUtil {
|
|||||||
langCode, versionParam, faceParam);
|
langCode, versionParam, faceParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getScryfallTokenDownloadUrl(String collectorNumber, String setCode, String langCode) {
|
||||||
|
String versionParam = "normal";
|
||||||
|
String faceParam = "";
|
||||||
|
return String.format("%s/%s/%s?format=image&version=%s%s", setCode, collectorNumber,
|
||||||
|
langCode, versionParam, faceParam);
|
||||||
|
}
|
||||||
|
|
||||||
public static String toMWSFilename(String in) {
|
public static String toMWSFilename(String in) {
|
||||||
in = StringUtils.stripAccents(in);
|
in = StringUtils.stripAccents(in);
|
||||||
final StringBuilder out = new StringBuilder();
|
final StringBuilder out = new StringBuilder();
|
||||||
|
|||||||
@@ -502,18 +502,18 @@ A143 R A-Leyline of Resonance @Sergey Glushakov
|
|||||||
1 Strangled Cemetery|DSK
|
1 Strangled Cemetery|DSK
|
||||||
|
|
||||||
[tokens]
|
[tokens]
|
||||||
b_2_2_e_horror
|
2 c_e_shard_draw
|
||||||
b_6_6_demon_flying
|
3 w_4_4_beast_lonely
|
||||||
bg_1_1_insect_flying
|
4 w_1_1_e_glimmer
|
||||||
c_a_treasure_sac
|
5 w_2_1_insect_flying
|
||||||
c_e_shard_draw
|
6 w_3_1_spirit_flying
|
||||||
everywhere
|
7 w_1_1_a_toy
|
||||||
g_2_2_spider_reach
|
8 u_x_x_spirit_flying
|
||||||
primo_the_indivisible
|
9 b_6_6_demon_flying
|
||||||
r_1_1_gremlin
|
10 b_2_2_e_horror
|
||||||
u_x_x_spirit_flying
|
11 r_1_1_gremlin
|
||||||
w_1_1_a_toy
|
12 g_2_2_spider_reach
|
||||||
w_1_1_e_glimmer
|
13 bg_1_1_insect_flying
|
||||||
w_2_1_insect_flying
|
14 primo_the_indivisible
|
||||||
w_3_1_spirit_flying
|
15 c_a_treasure_sac
|
||||||
w_4_4_beast_lonely
|
16 everywhere
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ Date=2025-04-11
|
|||||||
Name=Tarkir: Dragonstorm
|
Name=Tarkir: Dragonstorm
|
||||||
Type=Expansion
|
Type=Expansion
|
||||||
ScryfallCode=TDM
|
ScryfallCode=TDM
|
||||||
|
TokensCode=TTDM
|
||||||
# https://mtgscribe.com/2025/03/20/play-booster-fact-sheet-dragonstorm/
|
# https://mtgscribe.com/2025/03/20/play-booster-fact-sheet-dragonstorm/
|
||||||
BoosterSlots=Common,Common-Guest,Uncommon,RareMythic,AnyLand,Wildcard,FoilWildcard
|
BoosterSlots=Common,Common-Guest,Uncommon,RareMythic,AnyLand,Wildcard,FoilWildcard
|
||||||
Booster=6 Common, 1 Common-Guest, 3 Uncommon, 1 RareMythic, 1 AnyLand, 1 Wildcard, 1 FoilWildcard
|
Booster=6 Common, 1 Common-Guest, 3 Uncommon, 1 RareMythic, 1 AnyLand, 1 Wildcard, 1 FoilWildcard
|
||||||
|
|||||||
@@ -9,13 +9,9 @@ import forge.item.PaperCard;
|
|||||||
import forge.localinstance.properties.ForgeConstants;
|
import forge.localinstance.properties.ForgeConstants;
|
||||||
import forge.localinstance.properties.ForgePreferences;
|
import forge.localinstance.properties.ForgePreferences;
|
||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
|
|
||||||
public abstract class ImageFetcher {
|
public abstract class ImageFetcher {
|
||||||
@@ -232,33 +228,52 @@ public abstract class ImageFetcher {
|
|||||||
this.getScryfallDownloadURL(paperCard, face, useArtCrop, hasSetLookup, filename, downloadUrls);
|
this.getScryfallDownloadURL(paperCard, face, useArtCrop, hasSetLookup, filename, downloadUrls);
|
||||||
}
|
}
|
||||||
} else if (prefix.equals(ImageKeys.TOKEN_PREFIX)) {
|
} else if (prefix.equals(ImageKeys.TOKEN_PREFIX)) {
|
||||||
if (tokenImages == null) {
|
|
||||||
tokenImages = new HashMap<>();
|
|
||||||
for (Pair<String, String> nameUrlPair : FileUtil
|
|
||||||
.readNameUrlFile(ForgeConstants.IMAGE_LIST_TOKENS_FILE)) {
|
|
||||||
tokenImages.put(nameUrlPair.getLeft(), nameUrlPair.getRight());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final String filename = imageKey.substring(2) + ".jpg";
|
final String filename = imageKey.substring(2) + ".jpg";
|
||||||
String tokenUrl = tokenImages.get(filename);
|
if (ImageKeys.missingCards.contains(filename))
|
||||||
if (tokenUrl == null) {
|
return;
|
||||||
String[] tempdata = imageKey.split("[_](?=[^_]*$)"); //We want to check the edition first.
|
|
||||||
if (tempdata.length == 2) {
|
|
||||||
CardEdition E = StaticData.instance().getEditions().get(tempdata[1]);
|
|
||||||
if (E != null && E.getType() == CardEdition.Type.CUSTOM_SET) return; //Custom set token, skip fetching.
|
|
||||||
}
|
|
||||||
if (filename.equalsIgnoreCase("null.jpg"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (ImageKeys.missingCards.contains(filename))
|
if (filename.equalsIgnoreCase("null.jpg"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ImageKeys.missingCards.add(filename);
|
String[] tempdata = imageKey.substring(2).split("[_](?=[^_]*$)"); //We want to check the edition first.
|
||||||
System.err.println("No specified file for '" + filename + "'.. Attempting to download from default Url");
|
if (tempdata.length < 2) {
|
||||||
tokenUrl = String.format("%s%s", ForgeConstants.URL_TOKEN_DOWNLOAD, filename);
|
System.err.println("Token image key is malformed: " + imageKey);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String tokenName = tempdata[0];
|
||||||
|
String setCode = tempdata[1];
|
||||||
|
|
||||||
|
// Load the paper token from filename + edition
|
||||||
|
CardEdition edition = StaticData.instance().getEditions().get(setCode);
|
||||||
|
if (edition == null || edition.getType() == CardEdition.Type.CUSTOM_SET) return; //Custom set token, skip fetching.
|
||||||
|
|
||||||
|
//PaperToken pt = StaticData.instance().getAllTokens().getToken(tokenName, setCode);
|
||||||
|
Collection<CardEdition.TokenInSet> allTokens = edition.getTokens().get(tokenName);
|
||||||
|
|
||||||
|
if (!allTokens.isEmpty()) {
|
||||||
|
// This loop is going to try to download all the arts until it finds one
|
||||||
|
// This is a bit wrong since it _should_ just be trying to get the one with the appropriate collector number
|
||||||
|
// Since we don't have that for tokens, we'll just take the first one
|
||||||
|
// Ideally we would have some mapping for generating card to determine which art indexed/collector number to try to fetch
|
||||||
|
// Token art we're downloading and which location we're storing it in.
|
||||||
|
// Once we're pulling from PaperTokens this section will change a bit
|
||||||
|
Iterator <CardEdition.TokenInSet> it = allTokens.iterator();
|
||||||
|
CardEdition.TokenInSet tis;
|
||||||
|
while(it.hasNext()) {
|
||||||
|
tis = it.next();
|
||||||
|
String tokenCode = edition.getTokensCode();
|
||||||
|
String langCode = edition.getCardsLangCode();
|
||||||
|
if (tis.collectorNumber.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadUrls.add(ForgeConstants.URL_PIC_SCRYFALL_DOWNLOAD + ImageUtil.getScryfallTokenDownloadUrl(tis.collectorNumber, tokenCode, langCode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageKeys.missingCards.add(filename);
|
||||||
destFile = new File(ForgeConstants.CACHE_TOKEN_PICS_DIR, filename);
|
destFile = new File(ForgeConstants.CACHE_TOKEN_PICS_DIR, filename);
|
||||||
downloadUrls.add(tokenUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloadUrls.isEmpty()) {
|
if (downloadUrls.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user