mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
change collector number to be a String
This change moves the internal storage of collector number from Integer to String. The parsed pattern for valid collector numbers is any number of digits followed by an optional single non-digit character. This follows the format used by Scryfall for the alternate art WAR planeswalkers and cards from older formats sucha as FEM. Signed-off-by: Jamin W. Collins <jamin.collins@gmail.com>
This commit is contained in:
@@ -312,17 +312,17 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
return tryGetCard(request);
|
return tryGetCard(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCardCollectorNumber(String cardName, String reqEdition) {
|
public String getCardCollectorNumber(String cardName, String reqEdition) {
|
||||||
cardName = getName(cardName);
|
cardName = getName(cardName);
|
||||||
CardEdition edition = editions.get(reqEdition);
|
CardEdition edition = editions.get(reqEdition);
|
||||||
if (edition == null)
|
if (edition == null)
|
||||||
return -1;
|
return null;
|
||||||
for (CardInSet card : edition.getCards()) {
|
for (CardInSet card : edition.getCards()) {
|
||||||
if (card.name.equalsIgnoreCase(cardName)) {
|
if (card.name.equalsIgnoreCase(cardName)) {
|
||||||
return card.collectorNumber;
|
return card.collectorNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PaperCard tryGetCard(CardRequest request) {
|
private PaperCard tryGetCard(CardRequest request) {
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ import java.text.ParseException;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,10 +77,10 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
|||||||
|
|
||||||
public static class CardInSet {
|
public static class CardInSet {
|
||||||
public final CardRarity rarity;
|
public final CardRarity rarity;
|
||||||
public final int collectorNumber;
|
public final String collectorNumber;
|
||||||
public final String name;
|
public final String name;
|
||||||
|
|
||||||
public CardInSet(final String name, final int collectorNumber, final CardRarity rarity) {
|
public CardInSet(final String name, final String collectorNumber, final CardRarity rarity) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.collectorNumber = collectorNumber;
|
this.collectorNumber = collectorNumber;
|
||||||
this.rarity = rarity;
|
this.rarity = rarity;
|
||||||
@@ -86,7 +88,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
|||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
if (collectorNumber != -1) {
|
if (collectorNumber != null) {
|
||||||
sb.append(collectorNumber);
|
sb.append(collectorNumber);
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
}
|
}
|
||||||
@@ -266,26 +268,25 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
|||||||
Map<String, Integer> tokenNormalized = new HashMap<>();
|
Map<String, Integer> tokenNormalized = new HashMap<>();
|
||||||
List<CardEdition.CardInSet> processedCards = new ArrayList<>();
|
List<CardEdition.CardInSet> processedCards = new ArrayList<>();
|
||||||
if (contents.containsKey("cards")) {
|
if (contents.containsKey("cards")) {
|
||||||
|
final Pattern pattern = Pattern.compile(
|
||||||
|
/*
|
||||||
|
The following pattern will match the WAR Japanese art entries,
|
||||||
|
it should also match the Un-set and older alternate art cards
|
||||||
|
like Merseine from FEM (should the editions files ever be updated)
|
||||||
|
*/
|
||||||
|
"(^(?<cnum>[0-9]+.?) )?((?<rarity>[SCURML]) )?(?<name>.*)$"
|
||||||
|
);
|
||||||
for(String line : contents.get("cards")) {
|
for(String line : contents.get("cards")) {
|
||||||
if (StringUtils.isBlank(line))
|
Matcher matcher = pattern.matcher(line);
|
||||||
continue;
|
if (matcher.matches()) {
|
||||||
|
String collectorNumber = matcher.group("cnum");
|
||||||
// Optional collector number at the start.
|
CardRarity r = CardRarity.smartValueOf(matcher.group("rarity"));
|
||||||
String[] split = line.split(" ", 2);
|
String cardName = matcher.group("name");
|
||||||
int collectorNumber = -1;
|
|
||||||
if (split.length >= 2 && StringUtils.isNumeric(split[0])) {
|
|
||||||
collectorNumber = Integer.parseInt(split[0]);
|
|
||||||
line = split[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
// You may omit rarity for early development
|
|
||||||
CardRarity r = CardRarity.smartValueOf(line.substring(0, 1));
|
|
||||||
boolean hadRarity = r != CardRarity.Unknown && line.charAt(1) == ' ';
|
|
||||||
String cardName = hadRarity ? line.substring(2) : line;
|
|
||||||
CardInSet cis = new CardInSet(cardName, collectorNumber, r);
|
CardInSet cis = new CardInSet(cardName, collectorNumber, r);
|
||||||
processedCards.add(cis);
|
processedCards.add(cis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (contents.containsKey("tokens")) {
|
if (contents.containsKey("tokens")) {
|
||||||
for(String line : contents.get("tokens")) {
|
for(String line : contents.get("tokens")) {
|
||||||
|
|||||||
@@ -45,21 +45,20 @@ public abstract class ImageFetcher {
|
|||||||
final String filename = ImageUtil.getImageKey(paperCard, backFace, true);
|
final String filename = ImageUtil.getImageKey(paperCard, backFace, true);
|
||||||
destFile = new File(ForgeConstants.CACHE_CARD_PICS_DIR + "/" + filename + ".jpg");
|
destFile = new File(ForgeConstants.CACHE_CARD_PICS_DIR + "/" + filename + ".jpg");
|
||||||
|
|
||||||
// First try to download the LQ Set URL, then fetch from scryfall/magiccards.info
|
// First try to download the LQ Set URL, then fetch from scryfall
|
||||||
StringBuilder setDownload = new StringBuilder(ForgeConstants.URL_PIC_DOWNLOAD);
|
StringBuilder setDownload = new StringBuilder(ForgeConstants.URL_PIC_DOWNLOAD);
|
||||||
setDownload.append(ImageUtil.getDownloadUrl(paperCard, backFace));
|
setDownload.append(ImageUtil.getDownloadUrl(paperCard, backFace));
|
||||||
downloadUrls.add(setDownload.toString());
|
downloadUrls.add(setDownload.toString());
|
||||||
|
|
||||||
final StaticData data = StaticData.instance();
|
final StaticData data = StaticData.instance();
|
||||||
final int cardNum = data.getCommonCards().getCardCollectorNumber(paperCard.getName(), paperCard.getEdition());
|
final String cardNum = data.getCommonCards().getCardCollectorNumber(paperCard.getName(), paperCard.getEdition());
|
||||||
if (cardNum != -1) {
|
if (cardNum != null) {
|
||||||
String suffix = "";
|
String suffix = "";
|
||||||
if (paperCard.getRules().getOtherPart() != null) {
|
if (paperCard.getRules().getOtherPart() != null) {
|
||||||
suffix = (backFace ? "b" : "a");
|
suffix = (backFace ? "b" : "a");
|
||||||
}
|
}
|
||||||
final String editionMciCode = data.getEditions().getMciCodeByCode(paperCard.getEdition());
|
final String editionMciCode = data.getEditions().getMciCodeByCode(paperCard.getEdition());
|
||||||
downloadUrls.add(String.format("https://img.scryfall.com/cards/normal/en/%s/%d%s.jpg", editionMciCode, cardNum, suffix));
|
downloadUrls.add(String.format("https://img.scryfall.com/cards/normal/en/%s/%s%s.jpg", editionMciCode, cardNum, suffix));
|
||||||
downloadUrls.add(String.format("https://magiccards.info/scans/en/%s/%d%s.jpg", editionMciCode, cardNum, suffix));
|
|
||||||
}
|
}
|
||||||
} else if (prefix.equals(ImageKeys.TOKEN_PREFIX)) {
|
} else if (prefix.equals(ImageKeys.TOKEN_PREFIX)) {
|
||||||
if (tokenImages == null) {
|
if (tokenImages == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user