* GUI: fixed hybrid mana symbols download and render (#10082);

This commit is contained in:
Oleg Agafonov 2023-02-27 14:48:01 +04:00
parent 84ca77f5cb
commit 4274b75225
2 changed files with 42 additions and 27 deletions

View file

@ -67,7 +67,7 @@ public final class ManaSymbols {
}
private static final Map<String, Dimension> setImagesExist = new HashMap<>();
private static final Pattern REPLACE_SYMBOLS_PATTERN = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
private static final Pattern REPLACE_SYMBOLS_PATTERN = Pattern.compile("\\{([^}/]*)/?([^}/]*)/?([^}/]*)\\}");
private static final String[] symbols = new String[]{
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
@ -78,7 +78,8 @@ public final class ManaSymbols {
"S", "T", "Q",
"U", "UB", "UR", "UP", "2U",
"W", "WB", "WU", "WP", "2W",
"X", "C", "E"};
"X", "C", "E",
"BGP", "BRP", "GUP", "GWP", "RGP", "RWP", "UBP", "URP", "WBP", "WUP"};
private static final JLabel labelRender = new JLabel(); // render mana text
@ -651,7 +652,7 @@ public final class ManaSymbols {
replaced = replaced.replace(CardInfo.SPLIT_MANA_SEPARATOR_FULL, CardInfo.SPLIT_MANA_SEPARATOR_RENDER);
replaced = REPLACE_SYMBOLS_PATTERN.matcher(replaced).replaceAll(
"<img src='" + filePathToUrl(htmlImagesPath) + "$1$2" + ".png' alt='$1$2' width="
"<img src='" + filePathToUrl(htmlImagesPath) + "$1$2$3" + ".png' alt='$1$2$3' width="
+ symbolSize + " height=" + symbolSize + '>');
// replace hint icons

View file

@ -1,11 +1,13 @@
package org.mage.plugins.card.dl.sources;
import com.google.common.collect.AbstractIterator;
import java.io.File;
import static java.lang.String.format;
import java.util.Iterator;
import mage.client.constants.Constants;
import org.mage.plugins.card.dl.DownloadJob;
import java.io.File;
import java.util.Iterator;
import static java.lang.String.format;
import static org.mage.plugins.card.dl.DownloadJob.fromURL;
import static org.mage.plugins.card.dl.DownloadJob.toFile;
import static org.mage.plugins.card.utils.CardImageUtils.getImagesDir;
@ -13,10 +15,11 @@ import static org.mage.plugins.card.utils.CardImageUtils.getImagesDir;
/**
* The class GathererSymbols.
*
* @version V0.0 25.08.2010
* @author Clemens Koza
* @version V0.0 25.08.2010
*/
public class GathererSymbols implements Iterable<DownloadJob> {
//TODO chaos and planeswalker symbol
//chaos: https://gatherer.wizards.com/Images/Symbols/chaos.gif
@ -27,11 +30,11 @@ public class GathererSymbols implements Iterable<DownloadJob> {
private static final String[] sizes = {"small", "medium", "large"};
private static final String[] symbols = {"W", "U", "B", "R", "G",
"W/U", "U/B", "B/R", "R/G", "G/W", "W/B", "U/R", "B/G", "R/W", "G/U",
"W/U/P", "U/B/P", "B/R/P", "R/G/P", "G/W/P", "W/B/P", "U/R/P", "B/G/P", "R/W/P", "G/U/P",
"2/W", "2/U", "2/B", "2/R", "2/G",
"WP", "UP", "BP", "RP", "GP",
"X", "S", "T", "Q", "C", "E"};
"W/U", "U/B", "B/R", "R/G", "G/W", "W/B", "U/R", "B/G", "R/W", "G/U",
"W/U/P", "U/B/P", "B/R/P", "R/G/P", "G/W/P", "W/B/P", "U/R/P", "B/G/P", "R/W/P", "G/U/P",
"2/W", "2/U", "2/B", "2/R", "2/G",
"WP", "UP", "BP", "RP", "GP",
"X", "S", "T", "Q", "C", "E"};
private static final int minNumeric = 0, maxNumeric = 16;
public GathererSymbols() {
@ -53,10 +56,13 @@ public class GathererSymbols implements Iterable<DownloadJob> {
while (true) {
String sym;
if (symIndex < symbols.length) {
// take next char symbol
sym = symbols[symIndex++];
} else if (numeric <= maxNumeric) {
// take next numeric symbol
sym = String.valueOf(numeric++);
} else {
// switch to next size
sizeIndex++;
if (sizeIndex == sizes.length) {
return endOfData();
@ -70,26 +76,34 @@ public class GathererSymbols implements Iterable<DownloadJob> {
String symbol = sym.replaceAll("/", "");
File dst = new File(dir, symbol + ".gif");
/**
* Handle a bug on Gatherer where a few symbols are missing
* at the large size. Fall back to using the medium symbol
* for those cases.
*/
// workaround for miss icons on Gatherer (no cards with it, so no icons)
// TODO: comment and try download without workaround, keep fix for symbols with "Resource not found" error
switch (symbol) {
case "WUP":
case "BRP":
case "BGP":
case "WBP":
case "UBP":
case "URP":
// skip icon download
continue;
}
// workaround for miss large size icons on Gatherer (replace it by medium size)
// TODO: comment and try download without workaround, keep fix for symbols with "Resource not found" error
int modSizeIndex = sizeIndex;
if (sizeIndex == 2) {
switch (sym) {
case "WP":
case "UP":
case "BP":
case "RP":
case "GP":
case "E":
case "C":
switch (symbol) {
case "GUP":
case "GWP":
case "RGP":
case "RWP":
// need replace to medium size
modSizeIndex = 1;
break;
default:
// Nothing to do, symbol is available in the large size
// normal size
break;
}
}