mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
refactor: removed unused data from images download, improved code
This commit is contained in:
parent
4e77ccb381
commit
0bb837cbe5
7 changed files with 29 additions and 57 deletions
|
|
@ -68,7 +68,7 @@ public enum ScryfallImageSource implements CardImageSource {
|
|||
|
||||
// tokens support only direct links
|
||||
if (isToken) {
|
||||
baseUrl = ScryfallImageSupportTokens.findTokenLink(card.getSet(), card.getName(), card.getType());
|
||||
baseUrl = ScryfallImageSupportTokens.findTokenLink(card.getSet(), card.getName(), card.getImageNumber());
|
||||
alternativeUrl = null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2177,8 +2177,8 @@ public class ScryfallImageSupportTokens {
|
|||
return supportedSets;
|
||||
}
|
||||
|
||||
public static String findTokenLink(String setCode, String tokenName, Integer tokenNumber) {
|
||||
String search = setCode + "/" + tokenName + (!tokenNumber.equals(0) ? "/" + tokenNumber : "");
|
||||
public static String findTokenLink(String setCode, String tokenName, Integer imageNumber) {
|
||||
String search = setCode + "/" + tokenName + (!imageNumber.equals(0) ? "/" + imageNumber : "");
|
||||
return supportedCards.getOrDefault(search, null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public enum TokensMtgImageSource implements CardImageSource {
|
|||
public CardImageUrls generateTokenUrl(CardDownloadData card) throws IOException {
|
||||
String name = card.getName();
|
||||
String set = card.getSet();
|
||||
int type = card.getType();
|
||||
int imageNumber = card.getImageNumber();
|
||||
|
||||
// handle emblems
|
||||
if (name.toLowerCase(Locale.ENGLISH).contains("emblem")) {
|
||||
|
|
@ -110,14 +110,14 @@ public enum TokensMtgImageSource implements CardImageSource {
|
|||
}
|
||||
|
||||
TokenData tokenData;
|
||||
if (type == 0) {
|
||||
if (imageNumber == 0) {
|
||||
tokenData = list.get(0);
|
||||
} else {
|
||||
if (type > list.size()) {
|
||||
LOGGER.warn("Not enough images variants for token with type number " + type + ", name " + name + ", set " + set + '.');
|
||||
if (imageNumber > list.size()) {
|
||||
LOGGER.warn("Not enough images variants for token with type number " + imageNumber + ", name " + name + ", set " + set + '.');
|
||||
return null;
|
||||
}
|
||||
tokenData = list.get(card.getType() - 1);
|
||||
tokenData = list.get(card.getImageNumber() - 1);
|
||||
}
|
||||
|
||||
String url = "https://tokens.mtg.onl/tokens/" + tokenData.getExpansionSetCode().trim() + '_'
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class CardDownloadData {
|
|||
private String fileName = "";
|
||||
private String set;
|
||||
private final String collectorId;
|
||||
private final Integer type;
|
||||
private final Integer imageNumber;
|
||||
private boolean token;
|
||||
private final boolean twoFacedCard;
|
||||
private final boolean secondSide;
|
||||
|
|
@ -23,31 +23,30 @@ public class CardDownloadData {
|
|||
private boolean splitCard;
|
||||
private final boolean usesVariousArt;
|
||||
private String tokenClassName;
|
||||
private boolean isType2;
|
||||
|
||||
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer type) {
|
||||
this(name, setCode, collectorId, usesVariousArt, type, false, "");
|
||||
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer imageNumber) {
|
||||
this(name, setCode, collectorId, usesVariousArt, imageNumber, false, "");
|
||||
}
|
||||
|
||||
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer type, boolean token) {
|
||||
this(name, setCode, collectorId, usesVariousArt, type, token, false, false, "");
|
||||
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer imageNumber, boolean token) {
|
||||
this(name, setCode, collectorId, usesVariousArt, imageNumber, token, false, false, "");
|
||||
}
|
||||
|
||||
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer type, boolean token, String fileName) {
|
||||
this(name, setCode, collectorId, usesVariousArt, type, token, false, false, "");
|
||||
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer imageNumber, boolean token, String fileName) {
|
||||
this(name, setCode, collectorId, usesVariousArt, imageNumber, token, false, false, "");
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer type, boolean token, boolean twoFacedCard, boolean secondSide) {
|
||||
this(name, setCode, collectorId, usesVariousArt, type, token, twoFacedCard, secondSide, "");
|
||||
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer imageNumber, boolean token, boolean twoFacedCard, boolean secondSide) {
|
||||
this(name, setCode, collectorId, usesVariousArt, imageNumber, token, twoFacedCard, secondSide, "");
|
||||
}
|
||||
|
||||
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer type, boolean token, boolean twoFacedCard, boolean secondSide, String tokenClassName) {
|
||||
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer imageNumber, boolean token, boolean twoFacedCard, boolean secondSide, String tokenClassName) {
|
||||
this.name = name;
|
||||
this.set = setCode;
|
||||
this.collectorId = collectorId;
|
||||
this.usesVariousArt = usesVariousArt;
|
||||
this.type = type;
|
||||
this.imageNumber = imageNumber;
|
||||
this.token = token;
|
||||
this.twoFacedCard = twoFacedCard;
|
||||
this.secondSide = secondSide;
|
||||
|
|
@ -60,7 +59,7 @@ public class CardDownloadData {
|
|||
this.fileName = card.fileName;
|
||||
this.set = card.set;
|
||||
this.collectorId = card.collectorId;
|
||||
this.type = card.type;
|
||||
this.imageNumber = card.imageNumber;
|
||||
this.token = card.token;
|
||||
this.twoFacedCard = card.twoFacedCard;
|
||||
this.secondSide = card.secondSide;
|
||||
|
|
@ -69,7 +68,6 @@ public class CardDownloadData {
|
|||
this.splitCard = card.splitCard;
|
||||
this.usesVariousArt = card.usesVariousArt;
|
||||
this.tokenClassName = card.tokenClassName;
|
||||
this.isType2 = card.isType2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -96,10 +94,8 @@ public class CardDownloadData {
|
|||
if (this.twoFacedCard != other.twoFacedCard) {
|
||||
return false;
|
||||
}
|
||||
if (this.secondSide != other.secondSide) {
|
||||
return false;
|
||||
}
|
||||
return this.isType2 == other.isType2;
|
||||
|
||||
return this.secondSide == other.secondSide;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -108,11 +104,10 @@ public class CardDownloadData {
|
|||
hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
|
||||
hash = 47 * hash + (this.set != null ? this.set.hashCode() : 0);
|
||||
hash = 47 * hash + (this.collectorId != null ? this.collectorId.hashCode() : 0);
|
||||
hash = 47 * hash + (this.type != null ? this.type.hashCode() : 0);
|
||||
hash = 47 * hash + (this.imageNumber != null ? this.imageNumber.hashCode() : 0);
|
||||
hash = 47 * hash + (this.token ? 1 : 0);
|
||||
hash = 47 * hash + (this.twoFacedCard ? 1 : 0);
|
||||
hash = 47 * hash + (this.secondSide ? 1 : 0);
|
||||
hash = 47 * hash + (this.isType2 ? 1 : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
|
@ -217,8 +212,8 @@ public class CardDownloadData {
|
|||
this.splitCard = splitCard;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
public Integer getImageNumber() {
|
||||
return imageNumber;
|
||||
}
|
||||
|
||||
public boolean getUsesVariousArt() {
|
||||
|
|
@ -232,12 +227,4 @@ public class CardDownloadData {
|
|||
public void setFlippedSide(boolean flippedSide) {
|
||||
this.flippedSide = flippedSide;
|
||||
}
|
||||
|
||||
public boolean isType2() {
|
||||
return isType2;
|
||||
}
|
||||
|
||||
public void setType2(boolean type2) {
|
||||
isType2 = type2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -368,7 +368,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
for (CardDownloadData data : cardsMissing) {
|
||||
if (data.isToken()) {
|
||||
if (selectedSource.isTokenSource()
|
||||
&& selectedSource.isTokenImageProvided(data.getSet(), data.getName(), data.getType())
|
||||
&& selectedSource.isTokenImageProvided(data.getSet(), data.getName(), data.getImageNumber())
|
||||
&& selectedSets.contains(data.getSet())) {
|
||||
numberTokenImagesAvailable++;
|
||||
cardsDownloadQueue.add(data);
|
||||
|
|
@ -428,23 +428,12 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
}
|
||||
|
||||
private static List<CardDownloadData> prepareMissingCards(List<CardInfo> allCards, boolean redownloadMode) {
|
||||
|
||||
// get filter for Standard Type 2 cards
|
||||
Set<String> type2SetsFilter = new HashSet<>();
|
||||
List<String> constructedFormats = ConstructedFormats.getSetsByFormat(ConstructedFormats.STANDARD);
|
||||
if (constructedFormats != null && !constructedFormats.isEmpty()) {
|
||||
type2SetsFilter.addAll(constructedFormats);
|
||||
} else {
|
||||
logger.warn("No formats defined. Try connecting to a server first!");
|
||||
}
|
||||
|
||||
// prepare checking list
|
||||
List<CardDownloadData> allCardsUrls = Collections.synchronizedList(new ArrayList<>());
|
||||
try {
|
||||
allCards.parallelStream().forEach(card -> {
|
||||
if (!card.getCardNumber().isEmpty() && !"0".equals(card.getCardNumber()) && !card.getSetCode().isEmpty()) {
|
||||
String cardName = card.getName();
|
||||
boolean isType2 = type2SetsFilter.contains(card.getSetCode());
|
||||
CardDownloadData url = new CardDownloadData(cardName, card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, false, card.isDoubleFaced(), card.isNightCard());
|
||||
|
||||
// variations must have diff file names with additional postfix
|
||||
|
|
@ -454,7 +443,6 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
|
||||
url.setFlipCard(card.isFlipCard());
|
||||
url.setSplitCard(card.isSplitCard());
|
||||
url.setType2(isType2);
|
||||
|
||||
// main side
|
||||
allCardsUrls.add(url);
|
||||
|
|
@ -477,7 +465,6 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
secondSideCard.getCardNumber(),
|
||||
card.usesVariousArt(),
|
||||
0, false, card.isDoubleFaced(), true);
|
||||
url.setType2(isType2);
|
||||
allCardsUrls.add(url);
|
||||
}
|
||||
if (card.isFlipCard()) {
|
||||
|
|
@ -492,7 +479,6 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
0, false, card.isDoubleFaced(), card.isNightCard());
|
||||
cardDownloadData.setFlipCard(true);
|
||||
cardDownloadData.setFlippedSide(true);
|
||||
cardDownloadData.setType2(isType2);
|
||||
allCardsUrls.add(cardDownloadData);
|
||||
}
|
||||
if (card.getMeldsToCardName() != null) {
|
||||
|
|
@ -512,7 +498,6 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
meldsToCard.getCardNumber(),
|
||||
card.usesVariousArt(),
|
||||
0, false, false, false);
|
||||
url.setType2(isType2);
|
||||
allCardsUrls.add(url);
|
||||
}
|
||||
if (card.isModalDoubleFacedCard()) {
|
||||
|
|
@ -525,7 +510,6 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
card.getCardNumber(),
|
||||
card.usesVariousArt(),
|
||||
0, false, true, true);
|
||||
cardDownloadData.setType2(isType2);
|
||||
allCardsUrls.add(cardDownloadData);
|
||||
}
|
||||
} else if (card.getCardNumber().isEmpty() || "0".equals(card.getCardNumber())) {
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ public final class ImageCache {
|
|||
tokenFile = getTFile(path);
|
||||
|
||||
// try token from card
|
||||
// TODO: return image from another set on empty image?
|
||||
if (tokenFile == null || !tokenFile.exists()) {
|
||||
CardDownloadData tempInfo = new CardDownloadData(info);
|
||||
tempInfo.setToken(false);
|
||||
|
|
|
|||
|
|
@ -117,8 +117,8 @@ public final class CardImageUtils {
|
|||
String setPath = buildImagePathToSet(card);
|
||||
|
||||
String prefixType = "";
|
||||
if (card.getType() != 0) {
|
||||
prefixType = " " + card.getType();
|
||||
if (card.getImageNumber() != 0) {
|
||||
prefixType = " " + card.getImageNumber();
|
||||
}
|
||||
|
||||
String cardName = card.getFileName();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue