From 3bf0f800332363509d73ccb030eb9d1b028dffb4 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Fri, 7 Aug 2020 11:29:49 +0400 Subject: [PATCH] Images download: fixed broken download dialog --- .../card/dl/sources/MythicspoilerComSource.java | 2 +- .../card/dl/sources/ScryfallImageSource.java | 6 ++---- .../card/dl/sources/WizardCardsImageSource.java | 2 +- .../plugins/card/images/CardDownloadData.java | 15 +++++++++------ .../mage/plugins/card/utils/CardImageUtils.java | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MythicspoilerComSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MythicspoilerComSource.java index f642b3e06f..d7c9eec394 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MythicspoilerComSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MythicspoilerComSource.java @@ -396,7 +396,7 @@ public enum MythicspoilerComSource implements CardImageSource { String collectorId = card.getCollectorId(); String cardSet = card.getSet(); if (collectorId == null || cardSet == null) { - throw new Exception("Wrong parameters for image: collector id: " + collectorId + ",card set: " + cardSet); + throw new Exception("Wrong parameters for image: collector id: " + collectorId + ", card set: " + cardSet); } if (card.isFlippedSide()) { //doesn't support rotated images return null; diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/ScryfallImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/ScryfallImageSource.java index 255aac82c0..968eff235e 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/ScryfallImageSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/ScryfallImageSource.java @@ -4,8 +4,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import mage.cards.ExpansionSet; -import mage.cards.Sets; import mage.client.util.CardLanguage; import mage.util.CardUtil; import org.apache.log4j.Logger; @@ -30,7 +28,7 @@ public enum ScryfallImageSource implements CardImageSource { private final Map languageAliases; private CardLanguage currentLanguage = CardLanguage.ENGLISH; // working language - private Map preparedUrls = new HashMap<>(); + private final Map preparedUrls = new HashMap<>(); ScryfallImageSource() { // LANGUAGES @@ -68,7 +66,7 @@ public enum ScryfallImageSource implements CardImageSource { // TOKENS TRY // tokens support only direct links - if (baseUrl == null && isToken) { + if (isToken) { baseUrl = ScryfallImageSupportTokens.findTokenLink(card.getSet(), card.getName(), card.getType()); alternativeUrl = null; } diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/WizardCardsImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/WizardCardsImageSource.java index f8a7c35fa9..368b6e7f79 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/WizardCardsImageSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/WizardCardsImageSource.java @@ -461,7 +461,7 @@ public enum WizardCardsImageSource implements CardImageSource { String collectorId = card.getCollectorId(); String cardSet = card.getSet(); if (collectorId == null || cardSet == null) { - throw new Exception("Wrong parameters for image: collector id: " + collectorId + ",card set: " + cardSet); + throw new Exception("Wrong parameters for image: collector id: " + collectorId + ", card set: " + cardSet); } if (card.isFlippedSide()) { //doesn't support rotated images return null; diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/images/CardDownloadData.java b/Mage.Client/src/main/java/org/mage/plugins/card/images/CardDownloadData.java index 08c0a25587..6913d5223f 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/images/CardDownloadData.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/images/CardDownloadData.java @@ -1,11 +1,11 @@ package org.mage.plugins.card.images; +import mage.util.CardUtil; + import java.util.Locale; import java.util.Objects; -import mage.util.CardUtil; /** - * * @author North */ public class CardDownloadData { @@ -106,10 +106,7 @@ public class CardDownloadData { if (this.secondSide != other.secondSide) { return false; } - if (this.isType2 != other.isType2) { - return false; - } - return true; + return this.isType2 == other.isType2; } @Override @@ -134,6 +131,12 @@ public class CardDownloadData { return CardUtil.parseCardNumberAsInt(collectorId); } + public String getCollectorIdAsFileName() { + // return file names compatible card number (e.g. replace special symbols) + return collectorId + .replace("*", "star"); + } + public String getCollectorIdPostfix() { return getCollectorId().replaceAll(getCollectorIdAsInt().toString(), ""); } diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/utils/CardImageUtils.java b/Mage.Client/src/main/java/org/mage/plugins/card/utils/CardImageUtils.java index 0645e2d731..77bbf87f9b 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/utils/CardImageUtils.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/utils/CardImageUtils.java @@ -203,7 +203,7 @@ public final class CardImageUtils { String finalFileName = ""; if (card.getUsesVariousArt()) { // different arts uses name + collector id - finalFileName = cardName + prefixType + '.' + card.getCollectorId() + ".full.jpg"; + finalFileName = cardName + prefixType + '.' + card.getCollectorIdAsFileName() + ".full.jpg"; } else { // basic arts uses name finalFileName = cardName + prefixType + ".full.jpg";