From c9603d1994a68535ffae267f23608a016f86aa84 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 11 Feb 2018 23:30:15 +0100 Subject: [PATCH] * Some fixes to token image downloading. --- .../viewer/CollectionViewerPanel.java | 23 +-- .../collection/viewer/MageBook.java | 104 +++++------- .../card/dl/sources/TokensMtgImageSource.java | 158 ++++++++---------- .../dl/sources/WizardCardsImageSource.java | 2 +- .../plugins/card/images/DownloadPictures.java | 113 ++++++------- .../plugins/card/utils/CardImageUtils.java | 39 +++-- .../src/main/resources/card-pictures-tok.txt | 15 +- .../src/mage/cards/w/WandOfTheElements.java | 4 + .../src/main/java/mage/constants/SubType.java | 12 +- .../emblems/GideonOfTheTrialsEmblem.java | 2 +- .../token/RekindlingPhoenixToken.java | 1 + .../TilonallisSummonerElementalToken.java | 1 + .../token/WandOfTheElementsFirstToken.java | 7 +- .../token/WandOfTheElementsSecondToken.java | 5 +- 14 files changed, 231 insertions(+), 255 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/CollectionViewerPanel.java b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/CollectionViewerPanel.java index 296f85bead..d7079e160c 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/CollectionViewerPanel.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/CollectionViewerPanel.java @@ -24,7 +24,7 @@ * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. -*/ + */ package mage.client.deckeditor.collection.viewer; import java.awt.Color; @@ -48,7 +48,6 @@ import mage.client.util.gui.FastSearchUtil; import mage.client.util.sets.ConstructedFormats; import org.apache.log4j.Logger; - /** * Pane with big card and mage book. * @@ -75,7 +74,7 @@ public final class CollectionViewerPanel extends JPanel { this.hidePopup(); this.bigCard = null; } - + public void initComponents() { buttonsPanel = new javax.swing.JPanel(); buttonsPanel.setOpaque(false); @@ -117,6 +116,7 @@ public final class CollectionViewerPanel extends JPanel { btnSetFastSearch.setPreferredSize(new java.awt.Dimension(32, 32)); btnSetFastSearch.setMaximumSize(new java.awt.Dimension(32, 32)); btnSetFastSearch.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(java.awt.event.ActionEvent evt) { FastSearchUtil.showFastSearchForStringComboBox(formats, FastSearchUtil.DEFAULT_EXPANSION_SEARCH_MESSAGE); } @@ -169,20 +169,21 @@ public final class CollectionViewerPanel extends JPanel { next.addActionListener(e -> mageBook.next()); buttonPanel.add(next); - JLabel label4 = new JLabel("Show cards or tokens:"); - label3.setAlignmentX(Component.LEFT_ALIGNMENT); - label3.setForeground(Color.white); - buttonsPanel.add(label4); + JLabel labelCardTokenSwitch = new JLabel("Show cards or tokens:"); + labelCardTokenSwitch.setAlignmentX(Component.LEFT_ALIGNMENT); + labelCardTokenSwitch.setForeground(Color.white); + buttonsPanel.add(labelCardTokenSwitch); JCheckBox cardsOrTokens = new JCheckBox("Display Cards"); cardsOrTokens.setSelected(true); + cardsOrTokens.setForeground(Color.white); cardsOrTokens.setToolTipText("Select to show Cards or Tokens(and emblems) for the chosen set"); cardsOrTokens.addActionListener(e -> mageBook.cardsOrTokens(cardsOrTokens.isSelected())); buttonsPanel.add(cardsOrTokens); formats.addActionListener(e -> { if (mageBook != null) { - String format = (String)formats.getSelectedItem(); + String format = (String) formats.getSelectedItem(); MageFrame.getPreferences().put(CollectionViewerPanel.FORMAT_CONFIG_KEY, format); mageBook.updateDispayedSets(format); } @@ -233,11 +234,13 @@ public final class CollectionViewerPanel extends JPanel { c = c.getParent(); } if (c != null) { - ((CollectionViewerPane)c).removeFrame(); + ((CollectionViewerPane) c).removeFrame(); } } + private final class MageBookContainer extends JPanel { + public MageBookContainer() { super(); initComponents(); @@ -246,7 +249,7 @@ public final class CollectionViewerPanel extends JPanel { public void initComponents() { jPanel = new JPanel(); jScrollPane1 = new JScrollPane(jPanel); - jScrollPane1.getViewport().setBackground(new Color(0,0,0,0)); + jScrollPane1.getViewport().setBackground(new Color(0, 0, 0, 0)); jPanel.setLayout(new GridBagLayout()); // centers mage book jPanel.setBackground(new Color(0, 0, 0, 0)); diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java index d89b6568cc..3e5d446f6d 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java @@ -27,6 +27,19 @@ */ package mage.client.deckeditor.collection.viewer; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.FileNotFoundException; +import java.io.InputStream; +import static java.lang.Math.min; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; +import javax.imageio.ImageIO; +import javax.swing.*; import mage.cards.*; import mage.cards.repository.CardCriteria; import mage.cards.repository.CardInfo; @@ -42,29 +55,15 @@ import mage.client.util.sets.ConstructedFormats; import mage.components.ImagePanel; import mage.components.ImagePanelStyle; import mage.constants.Rarity; -import mage.view.CardView; -import org.apache.log4j.Logger; -import org.mage.card.arcane.ManaSymbols; - -import javax.imageio.ImageIO; -import javax.swing.*; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.*; -import java.util.List; - import mage.game.command.Emblem; import mage.game.permanent.PermanentToken; import mage.game.permanent.token.Token; +import mage.view.CardView; import mage.view.EmblemView; import mage.view.PermanentView; +import org.apache.log4j.Logger; +import org.mage.card.arcane.ManaSymbols; import org.mage.plugins.card.images.CardDownloadData; - -import static java.lang.Math.min; import static org.mage.plugins.card.images.DownloadPictures.getTokenCardUrls; /** @@ -144,7 +143,6 @@ public class MageBook extends JComponent { int captionHeight = Math.max(30, pageLeft.getHeight()); // caption size = next-prev images - // Top Panel (left page + (caption / stats) + right page jPanelTop = new JPanel(); jPanelTop.setLayout(new BorderLayout()); @@ -290,11 +288,9 @@ public class MageBook extends JComponent { public int showTokens() { jLayeredPane.removeAll(); - List tokens = getTokens(currentPage, currentSet); - int size = tokens.size(); - if (tokens != null && tokens.size() > 0) { + int size = tokens.size(); Rectangle rectangle = new Rectangle(); rectangle.translate(OFFSET_X, OFFSET_Y); for (int i = 0; i < min(conf.CARDS_PER_PAGE / 2, size); i++) { @@ -316,35 +312,34 @@ public class MageBook extends JComponent { jLayeredPane.repaint(); } - + return tokens.size(); } public void showEmblems(int numTokens) { List emblems = getEmblems(currentPage, currentSet, numTokens); - int size = emblems.size(); - System.out.println ("Size of origins in " + currentSet + " = " + emblems.size()); - + // System.out.println ("Size of origins in " + currentSet + " = " + emblems.size()); if (emblems != null && emblems.size() > 0) { + int size = emblems.size(); Rectangle rectangle = new Rectangle(); rectangle.translate(OFFSET_X, OFFSET_Y); // calculate the x offset of the second (right) page int second_page_x = (conf.WIDTH - 2 * LEFT_RIGHT_PAGES_WIDTH) - (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X; - // Already have numTokens tokens presented. Appending the emblems to the end of these. + // Already have numTokens tokens presented. Appending the emblems to the end of these. numTokens = numTokens % conf.CARDS_PER_PAGE; if (numTokens < conf.CARDS_PER_PAGE / 2) { for (int z = 0; z < numTokens && z < conf.CARDS_PER_PAGE / 2; z++) { rectangle = CardPosition.translatePosition(z, rectangle, conf); } } else { - rectangle.setLocation(second_page_x, OFFSET_Y); + rectangle.setLocation(second_page_x, OFFSET_Y); for (int z = 0; z < numTokens - conf.CARDS_PER_PAGE / 2; z++) { rectangle = CardPosition.translatePosition(z, rectangle, conf); } } - + int lastI = 0; for (int i = 0; i < size && i + numTokens < conf.CARDS_PER_PAGE / 2; i++) { Emblem emblem = emblems.get(i); @@ -388,8 +383,7 @@ public class MageBook extends JComponent { int dx = implemented ? 15 : 5; label.setBounds(rectangle.x + dx, rectangle.y + cardDimensions.frameHeight + 7, 110, 30); jLayeredPane.add(label); - */ - + */ // card number label JLabel cardNumber = new JLabel(); int dy = -5; // image panel have empty space in bottom (bug?), need to move label up @@ -436,26 +430,25 @@ public class MageBook extends JComponent { return cards.subList(start, end); } - private void updateCardStats(String setCode, boolean isCardsShow){ + private void updateCardStats(String setCode, boolean isCardsShow) { // sets do not have total cards number, it's a workaround ExpansionSet set = Sets.findSet(setCode); - if (set != null){ + if (set != null) { setCaption.setText(set.getCode() + " - " + set.getName()); - }else{ + } else { setCaption.setText("ERROR"); setInfo.setText("ERROR"); return; } - if (!isCardsShow){ + if (!isCardsShow) { // tokens or emblems, stats not need setInfo.setText(""); return; } // cards stats - int startNumber = 9999; int endNumber = 0; @@ -463,11 +456,11 @@ public class MageBook extends JComponent { // first run for numbers list LinkedList haveNumbers = new LinkedList<>(); - for (ExpansionSet.SetCardInfo card: cards){ + for (ExpansionSet.SetCardInfo card : cards) { int cardNumber = card.getCardNumberAsInt(); // skip xmage special numbers for cards (TODO: replace full art cards numbers from 180+20 to 180b, 180c and vice versa like scryfall) - if(cardNumber > 500){ + if (cardNumber > 500) { continue; } @@ -479,19 +472,19 @@ public class MageBook extends JComponent { // second run for empty numbers int countHave = haveNumbers.size(); int countNotHave = 0; - if (cards.size() > 0){ - for(int i = startNumber; i <= endNumber; i++){ - if(!haveNumbers.contains(i)){ - countNotHave++; - } - } + if (cards.size() > 0) { + for (int i = startNumber; i <= endNumber; i++) { + if (!haveNumbers.contains(i)) { + countNotHave++; + } + } } // result setInfo.setText(String.format("Have %d cards of %d", countHave, countHave + countNotHave)); if (countNotHave > 0) { setInfo.setForeground(new Color(150, 0, 0)); - }else{ + } else { setInfo.setForeground(jLayeredPane.getForeground()); } } @@ -520,21 +513,10 @@ public class MageBook extends JComponent { if (newToken != null && newToken instanceof mage.game.permanent.token.Token) { ((Token) newToken).setExpansionSetCodeForImage(set); ((Token) newToken).setOriginalExpansionSetCode(set); + ((Token) newToken).setTokenType(token.getType()); tokens.add((Token) newToken); } - } catch (ClassNotFoundException ex) { - // Swallow exception - } catch (NoSuchMethodException ex) { - // Swallow exception - } catch (SecurityException ex) { - // Swallow exception - } catch (InstantiationException ex) { - // Swallow exception - } catch (IllegalAccessException ex) { - // Swallow exception - } catch (IllegalArgumentException ex) { - // Swallow exception - } catch (InvocationTargetException ex) { + } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { // Swallow exception } } @@ -571,7 +553,7 @@ public class MageBook extends JComponent { Object newEmblem = cons.newInstance(); if (newEmblem != null && newEmblem instanceof mage.game.command.Emblem) { ((Emblem) newEmblem).setExpansionSetCodeForImage(set); - + emblems.add((Emblem) newEmblem); } } catch (ClassNotFoundException ex) { @@ -593,12 +575,12 @@ public class MageBook extends JComponent { } int start = 0; int end = emblems.size(); - - if ((page + 1) * conf.CARDS_PER_PAGE < numTokens + emblems.size()) { + + if ((page + 1) * conf.CARDS_PER_PAGE < numTokens + emblems.size()) { end = (page + 1) * conf.CARDS_PER_PAGE - numTokens; pageRight.setVisible(true); } - + if (emblems.size() > conf.CARDS_PER_PAGE) { pageLeft.setVisible(true); pageRight.setVisible(true); diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/TokensMtgImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/TokensMtgImageSource.java index 7d019c7a6f..efaa3ecfb8 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/TokensMtgImageSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/TokensMtgImageSource.java @@ -39,6 +39,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Level; +import mage.constants.SubType; import org.apache.log4j.Logger; import org.mage.plugins.card.images.CardDownloadData; import org.mage.plugins.card.images.DownloadPictures; @@ -83,35 +84,6 @@ public enum TokensMtgImageSource implements CardImageSource { return null; } - private static final String[] EMBLEMS = { - "Ajani", - "Arlinn", - "Chandra", - "Dack", - "Daretti", - "Dovin", - "Domri", - "Elspeth", - "Garruk", - "Gideon", - "Huatli", - "Jace", - "Kiora", - "Koth", - "Liliana", - "Narset", - "Nixilis", - "Sarkhan", - "Sorin", - "Tamiyo", - "Teferi", - "Venser", - // Custom Emblems - "Yoda", - "Obi-Wan Kenobi", - "Aurra Sing" - }; - private static final Map SET_NAMES_REPLACEMENT = new HashMap() { { put("con", "CFX"); @@ -119,6 +91,16 @@ public enum TokensMtgImageSource implements CardImageSource { } }; + private String getEmblemName(String originalName) { + + for (SubType subType : SubType.getPlaneswalkerTypes(true)) { + if (originalName.toLowerCase().contains(subType.toString().toLowerCase())) { + return subType.getDescription() + " Emblem"; + } + } + return null; + } + @Override public String generateTokenUrl(CardDownloadData card) throws IOException { String name = card.getName(); @@ -127,12 +109,7 @@ public enum TokensMtgImageSource implements CardImageSource { // handle emblems if (name.toLowerCase().contains("emblem")) { - for (String emblem : EMBLEMS) { - if (name.toLowerCase().contains(emblem.toLowerCase())) { - name = emblem + " Emblem"; - break; - } - } + name = getEmblemName(name); } // we should replace some set names @@ -152,20 +129,16 @@ public enum TokensMtgImageSource implements CardImageSource { String key = set + "/" + name; List list = tokensData.get(key); if (list == null) { - logger.info("Could not find data for token " + name + ", set " + set + "."); + logger.warn("Could not find data for token " + name + ", set " + set + "."); return null; } TokenData tokenData; if (type == 0) { - if (list.size() > 1) { - logger.info("Multiple images were found for token " + name + ", set " + set + '.'); - } - logger.info("Token found: " + name + ", set " + set + '.'); tokenData = list.get(0); } else { if (type > list.size()) { - logger.warn("Not enough images for token with type " + type + ", name " + name + ", set " + set + '.'); + logger.warn("Not enough images variants for token with type number " + type + ", name " + name + ", set " + set + '.'); return null; } tokenData = list.get(card.getType() - 1); @@ -177,6 +150,57 @@ public enum TokensMtgImageSource implements CardImageSource { return url; } + @Override + public int getTotalImages() { + return getTokenImages(); + } + + @Override + public int getTokenImages() { + try { + getTokensData(); + } catch (IOException ex) { + logger.error(getSourceName() + ": Loading available data failed. " + ex.getMessage()); + } + return tokensData.size(); + } + + @Override + public boolean isTokenSource() { + return true; + } + + @Override + public void doPause(String httpImageUrl) { + } + + @Override + public ArrayList getSupportedSets() { + ArrayList supportedSetsCopy = new ArrayList<>(); + supportedSetsCopy.addAll(supportedSets); + return supportedSetsCopy; + } + + @Override + public boolean isImageProvided(String setCode, String cardName) { + String searchName = cardName; + if (cardName.toLowerCase().contains("emblem")) { + searchName = getEmblemName(cardName); + } + try { + getTokensData(); + } catch (IOException ex) { + java.util.logging.Logger.getLogger(TokensMtgImageSource.class.getName()).log(Level.SEVERE, null, ex); + } + String key = setCode + "/" + searchName; + return (tokensData.containsKey(key)); + } + + @Override + public boolean isSetSupportedComplete(String setCode) { + return false; + } + private HashMap> getTokensData() throws IOException { synchronized (tokensDataSync) { if (tokensData == null) { @@ -193,7 +217,7 @@ public enum TokensMtgImageSource implements CardImageSource { list = new ArrayList<>(); tokensData.put(key, list); supportedSets.add(tokenData.getExpansionSetCode()); - logger.info("Added key: " + key); + logger.debug("Added key: " + key); } list.add(tokenData); } @@ -207,6 +231,7 @@ public enum TokensMtgImageSource implements CardImageSource { try (InputStream inputStream = url.openStream()) { List siteTokensData = parseTokensData(inputStream); for (TokenData siteData : siteTokensData) { + // logger.info("TOK: " + siteData.getExpansionSetCode() + "/" + siteData.getName()); String key = siteData.getExpansionSetCode() + "/" + siteData.getName(); supportedSets.add(siteData.getExpansionSetCode()); ArrayList list = tokensData.get(key); @@ -267,7 +292,7 @@ public enum TokensMtgImageSource implements CardImageSource { } String[] split = line.split(","); // replace special comma for cards like 'Ashaya‚ the Awoken World' - String name = split[0].replace('‚', ','); + String name = split[0].replace('‚', ',').replace("‚", ","); String number = split[1]; TokenData token = new TokenData(name, number, set); newTokensData.add(token); @@ -305,51 +330,4 @@ public enum TokensMtgImageSource implements CardImageSource { } } - @Override - public int getTotalImages() { - return getTokenImages(); - } - - @Override - public int getTokenImages() { - try { - getTokensData(); - } catch (IOException ex) { - logger.error(getSourceName() + ": Loading available data failed. " + ex.getMessage()); - } - return tokensData.size(); - } - - @Override - public boolean isTokenSource() { - return true; - } - - @Override - public void doPause(String httpImageUrl) { - } - - @Override - public ArrayList getSupportedSets() { - ArrayList supportedSetsCopy = new ArrayList<>(); - supportedSetsCopy.addAll(supportedSets); - return supportedSetsCopy; - } - - @Override - public boolean isImageProvided(String setCode, String cardName) { - try { - getTokensData(); - } catch (IOException ex) { - java.util.logging.Logger.getLogger(TokensMtgImageSource.class.getName()).log(Level.SEVERE, null, ex); - } - String key = setCode + "/" + cardName; - return (tokensData.containsKey(key)); - } - - @Override - public boolean isSetSupportedComplete(String setCode) { - return false; - } - } 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 1e65987a7d..f13d7fbf1c 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 @@ -352,7 +352,7 @@ public enum WizardCardsImageSource implements CardImageSource { setsAliases.put("EVG", "Duel Decks: Elves vs. Goblins"); setsAliases.put("EXO", "Exodus"); setsAliases.put("FEM", "Fallen Empires"); - setsAliases.put("FNMP", "Friday Night Magic"); +// setsAliases.put("FNMP", "Friday Night Magic"); setsAliases.put("FRF", "Fate Reforged"); setsAliases.put("FUT", "Future Sight"); setsAliases.put("GPT", "Guildpact"); diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java b/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java index 26ce8adc73..1af10cfa48 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java @@ -2,24 +2,17 @@ package org.mage.plugins.card.images; import java.awt.*; import java.awt.event.ItemEvent; -import java.awt.image.BufferedImage; import java.io.*; import java.net.*; import java.nio.file.AccessDeniedException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import javax.imageio.IIOImage; -import javax.imageio.ImageIO; -import javax.imageio.ImageWriteParam; -import javax.imageio.ImageWriter; -import javax.imageio.stream.FileImageOutputStream; import javax.swing.*; import mage.cards.ExpansionSet; import mage.cards.Sets; @@ -38,13 +31,11 @@ import org.apache.log4j.Logger; import org.mage.plugins.card.dl.sources.*; import org.mage.plugins.card.properties.SettingsManager; import org.mage.plugins.card.utils.CardImageUtils; - import static org.mage.plugins.card.utils.CardImageUtils.getImagesDir; public class DownloadPictures extends DefaultBoundedRangeModel implements Runnable { // don't forget to remove new sets from ignore.urls to download (propeties file in resources) - private static DownloadPictures instance; private static final Logger logger = Logger.getLogger(DownloadPictures.class); @@ -300,7 +291,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab if (expansionSet != null) { setNames.add(expansionSet.getName()); } else { - logger.error(cardImageSource.getSourceName() + ": Expansion set for code " + setCode + " not found!"); + logger.warn("Source: " + cardImageSource.getSourceName() + ": Expansion set for code " + setCode + " not found in xmage sets!"); } } @@ -352,7 +343,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab if (cardImageSource.isTokenSource() && cardImageSource.isImageProvided(data.getSet(), data.getName())) { numberTokenImagesAvailable++; cardsToDownload.add(data); - }else{ + } else { //logger.warn("Source do not support token (set " + data.getSet() + ", token " + data.getName() + ")"); } } else { @@ -433,7 +424,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab } CardInfo secondSideCard = CardRepository.instance.findCard(card.getSecondSideName()); - if (secondSideCard == null){ + if (secondSideCard == null) { throw new IllegalStateException("Can''t find second side card in database: " + card.getSecondSideName()); } @@ -473,6 +464,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab logger.debug(card.getName() + " (is_token=" + card.isToken() + "). Image is here:" + file.getAbsolutePath() + " (exists=" + file.exists() + ')'); if (!file.exists()) { logger.debug("Missing: " + file.getAbsolutePath()); + // logger.info("Missing image: " + (card.isToken() ? "TOKEN " : "CARD ") + card.getSet() + "/" + card.getName() + " type: " + card.getType()); cardsToDownload.add(card); } }); @@ -517,6 +509,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab CardDownloadData card = new CardDownloadData(params[3], set, "0", false, type, "", "", true); card.setTokenClassName(tokenClassName); list.add(card); + // logger.debug("Token: " + set + "/" + card.getName() + " type: " + type); } else if (params[1].toLowerCase().equals("generate") && params[2].startsWith("EMBLEM:")) { String set = params[2].substring(7); CardDownloadData card = new CardDownloadData("Emblem " + params[3], set, "0", false, type, "", "", true, fileName); @@ -696,7 +689,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab TFile destFile; try { - if (card == null){ + if (card == null) { synchronized (sync) { update(cardIndex + 1, count); } @@ -705,29 +698,31 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab // gen temp file (download to images folder) String tempPath = getImagesDir() + File.separator + "downloading" + File.separator; - if(useSpecifiedPaths){ - fileTempImage = new TFile(tempPath + actualFilename + "-" + card.hashCode() + ".jpg"); - }else{ - fileTempImage = new TFile(tempPath + CardImageUtils.prepareCardNameForFile(card.getName()) + "-" + card.hashCode() + ".jpg"); + if (useSpecifiedPaths) { + fileTempImage = new TFile(tempPath + actualFilename + "-" + card.hashCode() + ".jpg"); + } else { + fileTempImage = new TFile(tempPath + CardImageUtils.prepareCardNameForFile(card.getName()) + "-" + card.hashCode() + ".jpg"); } - if(!fileTempImage.getParentFile().exists()){ - fileTempImage.getParentFile().mkdirs(); + TFile parentFile = fileTempImage.getParentFile(); + if (parentFile != null) { + if (!parentFile.exists()) { + parentFile.mkdirs(); + } } // gen dest file name - if(useSpecifiedPaths) - { - if(card.isToken()){ + if (useSpecifiedPaths) { + if (card.isToken()) { destFile = new TFile(CardImageUtils.buildImagePathToSet(card) + actualFilename + ".jpg"); - }else{ + } else { destFile = new TFile(CardImageUtils.buildImagePathToTokens() + actualFilename + ".jpg"); } - }else{ + } else { destFile = new TFile(CardImageUtils.buildImagePathToCard(card)); } // FILE already exists (in zip or in dir) - if (destFile.exists()){ + if (destFile.exists()) { synchronized (sync) { update(cardIndex + 1, count); } @@ -753,9 +748,9 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab if(!destFile.getParentFile().exists()){ destFile.getParentFile().mkdirs(); } - */ + */ - /* + /* // WTF start?! TODO: wtf File existingFile = new File(imagePath.replaceFirst("\\w{3}.zip", "")); if (existingFile.exists()) { @@ -775,9 +770,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab return; } // WTF end?! - */ - - + */ // START to download cardImageSource.doPause(url.getPath()); URLConnection httpConn = url.openConnection(p); @@ -785,7 +778,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab httpConn.connect(); int responseCode = ((HttpURLConnection) httpConn).getResponseCode(); - if (responseCode == 200){ + if (responseCode == 200) { // download OK // save data to temp BufferedOutputStream out; @@ -803,18 +796,18 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab // stop download, save current state and exit TFile archive = destFile.getTopLevelArchive(); ///* not need to unmout/close - it's auto action - if (archive != null && archive.exists()){ + if (archive != null && archive.exists()) { logger.info("User canceled download. Closing archive file: " + destFile.toString()); try { TVFS.umount(archive); - }catch (Exception e) { + } catch (Exception e) { logger.error("Can't close archive file: " + e.getMessage(), e); } }//*/ try { TFile.rm(fileTempImage); - }catch (Exception e) { + } catch (Exception e) { logger.error("Can't delete temp file: " + e.getMessage(), e); } return; @@ -827,25 +820,24 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab out.close(); // TODO: add two faces card correction? (WTF) - // SAVE final data if (fileTempImage.exists()) { - if (!destFile.getParentFile().exists()){ + if (!destFile.getParentFile().exists()) { destFile.getParentFile().mkdirs(); } new TFile(fileTempImage).cp_rp(destFile); try { TFile.rm(fileTempImage); - }catch (Exception e) { + } catch (Exception e) { logger.error("Can't delete temp file: " + e.getMessage(), e); } } - }else{ + } else { // download ERROR logger.warn("Image download for " + card.getName() - + (!card.getDownloadName().equals(card.getName()) ? " downloadname: " + card.getDownloadName() : "") - + " (" + card.getSet() + ") failed - responseCode: " + responseCode + " url: " + url.toString() + + (!card.getDownloadName().equals(card.getName()) ? " downloadname: " + card.getDownloadName() : "") + + " (" + card.getSet() + ") failed - responseCode: " + responseCode + " url: " + url.toString() ); if (logger.isDebugEnabled()) { @@ -928,8 +920,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab logger.debug("Returned HTML ERROR:\n" + convertStreamToString(((HttpURLConnection) httpConn).getErrorStream())); } } - */ - + */ } catch (AccessDeniedException e) { logger.error("Can't access to files: " + card.getName() + "(" + card.getSet() + "). Try rebooting your system to remove the file lock."); } catch (Exception e) { @@ -942,25 +933,25 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab } } - private void writeImageToFile(BufferedImage image, TFile file) throws IOException { - Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); - - ImageWriter writer = (ImageWriter) iter.next(); - ImageWriteParam iwp = writer.getDefaultWriteParam(); - iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); - iwp.setCompressionQuality(0.96f); - - File tempFile = new File(getImagesDir() + File.separator + image.hashCode() + file.getName()); - FileImageOutputStream output = new FileImageOutputStream(tempFile); - writer.setOutput(output); - IIOImage image2 = new IIOImage(image, null, null); - writer.write(null, image2, iwp); - writer.dispose(); - output.close(); - - new TFile(tempFile).cp_rp(file); - tempFile.delete(); - } +// private void writeImageToFile(BufferedImage image, TFile file) throws IOException { +// Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); +// +// ImageWriter writer = (ImageWriter) iter.next(); +// ImageWriteParam iwp = writer.getDefaultWriteParam(); +// iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); +// iwp.setCompressionQuality(0.96f); +// +// File tempFile = new File(getImagesDir() + File.separator + image.hashCode() + file.getName()); +// FileImageOutputStream output = new FileImageOutputStream(tempFile); +// writer.setOutput(output); +// IIOImage image2 = new IIOImage(image, null, null); +// writer.write(null, image2, iwp); +// writer.dispose(); +// output.close(); +// +// new TFile(tempFile).cp_rp(file); +// tempFile.delete(); +// } } private void update(int card, int count) { 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 5c98e07d9e..ab0ab5cd66 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 @@ -56,8 +56,7 @@ public final class CardImageUtils { */ public static String generateFullTokenImagePath(CardDownloadData card) { if (card.isToken()) { - String filePath = getTokenImagePath(card); - return filePath; + return getTokenImagePath(card); } return ""; } @@ -67,23 +66,29 @@ public final class CardImageUtils { TFile file = new TFile(filename); if (!file.exists()) { - filename = generateTokenDescriptorImagePath(card); - } - - file = new TFile(filename); - if (!file.exists()) { - CardDownloadData updated = new CardDownloadData(card); - updated.setName(card.getName() + " 1"); - filename = buildImagePathToCard(updated); - file = new TFile(filename); - if (!file.exists()) { - updated = new CardDownloadData(card); - updated.setName(card.getName() + " 2"); - filename = buildImagePathToCard(updated); + String tokenDescriptorfilename = generateTokenDescriptorImagePath(card); + if (!tokenDescriptorfilename.isEmpty()) { + file = new TFile(filename); + if (file.exists()) { + return tokenDescriptorfilename; + } } } - return filename; + +// makes no longer sense +// file = new TFile(filename); +// if (!file.exists()) { +// CardDownloadData updated = new CardDownloadData(card); +// updated.setName(card.getName() + " 1"); +// filename = buildImagePathToCard(updated); +// file = new TFile(filename); +// if (!file.exists()) { +// updated = new CardDownloadData(card); +// updated.setName(card.getName() + " 2"); +// filename = buildImagePathToCard(updated); +// } +// } } private static String searchForCardImage(CardDownloadData card) { @@ -208,7 +213,7 @@ public final class CardImageUtils { if (card.getUsesVariousArt()) { finalFileName = cardName + '.' + card.getCollectorId() + ".full.jpg"; } else { - if (card.getUsesVariousArt()){ + if (card.getUsesVariousArt()) { // only various arts can be same name, but different postfixes (a,b,c,d,e) int len = card.getCollectorId().length(); if (Character.isLetter(card.getCollectorId().charAt(len - 1))) { diff --git a/Mage.Client/src/main/resources/card-pictures-tok.txt b/Mage.Client/src/main/resources/card-pictures-tok.txt index 20e8bfe080..72643ebf22 100644 --- a/Mage.Client/src/main/resources/card-pictures-tok.txt +++ b/Mage.Client/src/main/resources/card-pictures-tok.txt @@ -45,10 +45,10 @@ #|Generate|TOK:PTC|Wolf|| #|Generate|TOK:PTC|Wurm|| #|Generate|TOK:WMCQ|Angel|| -|Generate|EMBLEM!:AKH|Emblem Gideon|||GideonOfTheTrialsEmblem| |Generate|EMBLEM!:BFZ|Emblem Gideon|||GideonAllyOfZendikarEmblem| |Generate|EMBLEM!:BFZ|Emblem Kiora|||KioraMasterOfTheDepthsEmblem| |Generate|EMBLEM!:BFZ|Emblem Nixilis|||ObNixilisReignitedEmblem| +|Generate|EMBLEM!:AKH|Emblem Gideon|||GideonOfTheTrialsEmblem| |Generate|EMBLEM!:C14|Emblem Daretti|||DarettiScrapSavantEmblem| |Generate|EMBLEM!:C14|Emblem Daretti||Emblem Daretti|DarettiScrapSavantEmblem| |Generate|EMBLEM!:C14|Emblem Nixilis|||ObNixilisOfTheBlackOathEmblem| @@ -73,7 +73,7 @@ |Generate|EMBLEM!:ORI|Emblem Liliana|||LilianaDefiantNecromancerEmblem| |Generate|EMBLEM!:SOI|Emblem Arlinn|||ArlinnEmbracedByTheMoonEmblem| |Generate|EMBLEM!:SOI|Emblem Jace|||JaceUnravelerOfSecretsEmblem| -|Generate|EMBLEM-:THS|Elspeth, Suns Champion||Emblem Elspeth|ElspethSunsChampionEmblem| +|Generate|EMBLEM:THS|Elspeth, Suns Champion||Emblem Elspeth|ElspethSunsChampionEmblem| |Generate|EMBLEM:AVR|Tamiyo, the Moon Sage||Emblem Tamiyo|TamiyoTheMoonSageEmblem| |Generate|EMBLEM:BNG|Kiora, the Crashing Wave||Emblem Kiora|KioraEmblem| |Generate|EMBLEM:DDI|Koth of the Hammer||Emblem Koth|KothOfTheHammerEmblem| @@ -484,8 +484,8 @@ |Generate|TOK:DKA|Zombie|||ZombieToken| |Generate|TOK:DRB|Saproling|||SaprolingToken| |Generate|TOK:DST|Beast|||BeastToken| -|Generate|TOK:DST|Elemental|||WandOfTheElementsFirstToken| -|Generate|TOK:DST|Elemental|||WandOfTheElementsSecondToken| +|Generate|TOK:DST|Elemental|1||WandOfTheElementsFirstToken| +|Generate|TOK:DST|Elemental|2||WandOfTheElementsSecondToken| |Generate|TOK:DST|InsectWirefly|||WireflyToken| |Generate|TOK:DST|Insect|||InsectToken| |Generate|TOK:DST|Myr|||MyrToken| @@ -731,7 +731,7 @@ |Generate|TOK:M15|Beast|2||GarrukApexPredatorBeastToken| |Generate|TOK:M15|Dragon|||BroodKeeperDragonToken| |Generate|TOK:M15|Goblin|1||GoblinTokenWithHaste| -|Generate|TOK:M15|Goblin|2||GoblinToken| +# |Generate|TOK:M15|Goblin|2||GoblinToken| #does not exist |Generate|TOK:M15|Insect|||InsectToken| |Generate|TOK:M15|Land Mine|||LandMineToken| |Generate|TOK:M15|Sliver|||SliverToken| @@ -1000,8 +1000,7 @@ |Generate|TOK:SOM|Cat|||CatToken| |Generate|TOK:SOM|Goblin|||GoblinToken| |Generate|TOK:SOM|Golem|||GolemToken| -|Generate|TOK:SOM|Insect|1||InsectToken| -|Generate|TOK:SOM|Insect|2||InsectInfectToken| +|Generate|TOK:SOM|Insect|||InsectInfectToken| |Generate|TOK:SOM|Myr|||MyrToken| |Generate|TOK:SOM|Soldier|||SoldierToken| |Generate|TOK:SOM|Wolf|||WolfToken| @@ -1068,7 +1067,7 @@ |Generate|TOK:USG|Minion|||MinionToken| |Generate|TOK:USG|Saproling|||SaprolingToken| |Generate|TOK:UST|Dragon|||DragonTokenGold| -|Generate|TOK:UST|StormCrow|||StormCrowToken| +|Generate|TOK:UST|Storm Crow|||StormCrowToken| |Generate|TOK:V10|Wolf|||WolfToken| |Generate|TOK:V11|Faerie Rogue|||OonaQueenFaerieToken| |Generate|TOK:V12|Spirit|||SpiritToken| diff --git a/Mage.Sets/src/mage/cards/w/WandOfTheElements.java b/Mage.Sets/src/mage/cards/w/WandOfTheElements.java index 97d1bcc88b..4c3ad4fe03 100644 --- a/Mage.Sets/src/mage/cards/w/WandOfTheElements.java +++ b/Mage.Sets/src/mage/cards/w/WandOfTheElements.java @@ -59,9 +59,13 @@ public class WandOfTheElements extends CardImpl { public WandOfTheElements(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}"); + + // {T}, Sacrifice an Island: Create a 2/2 blue Elemental creature token with flying. Ability firstAbility = new SimpleActivatedAbility(Zone.BATTLEFIELD, new CreateTokenEffect(new WandOfTheElementsFirstToken()), new TapSourceCost()); firstAbility.addCost(new SacrificeTargetCost(new TargetControlledPermanent(islandFilter))); this.addAbility(firstAbility); + + // {T}, Sacrifice a Mountain: Create a 3/3 red Elemental creature token. Ability secondAbility = new SimpleActivatedAbility(Zone.BATTLEFIELD, new CreateTokenEffect(new WandOfTheElementsSecondToken()), new TapSourceCost()); secondAbility.addCost(new SacrificeTargetCost(new TargetControlledPermanent(mountainFilter))); this.addAbility(secondAbility); diff --git a/Mage/src/main/java/mage/constants/SubType.java b/Mage/src/main/java/mage/constants/SubType.java index e700b9d4f9..ff02fe05d8 100644 --- a/Mage/src/main/java/mage/constants/SubType.java +++ b/Mage/src/main/java/mage/constants/SubType.java @@ -198,7 +198,7 @@ public enum SubType { LHURGOYF("Lhurgoyf", SubTypeSet.CreatureType), LICID("Licid", SubTypeSet.CreatureType), LIZARD("Lizard", SubTypeSet.CreatureType), - LOBSTER("Lobster", SubTypeSet.CreatureType, true), // Unglued + LOBSTER("Lobster", SubTypeSet.CreatureType, true), // Unglued // M MANTELLIAN("Mantellian", SubTypeSet.CreatureType, true), // Star Wars MANTICORE("Manticore", SubTypeSet.CreatureType), @@ -442,6 +442,16 @@ public enum SubType { return subTypeSet; } + public static Set getPlaneswalkerTypes(boolean withCustomSets) { + Set subTypes = EnumSet.noneOf(SubType.class); + for (SubType subType : values()) { + if (subType.getSubTypeSet() == SubTypeSet.PlaneswalkerType && (withCustomSets || !subType.customSet)) { + subTypes.add(subType); + } + } + return subTypes; + } + public static Set getCreatureTypes(boolean customSet) { Set subTypes = EnumSet.noneOf(SubType.class); for (SubType s : values()) { diff --git a/Mage/src/main/java/mage/game/command/emblems/GideonOfTheTrialsEmblem.java b/Mage/src/main/java/mage/game/command/emblems/GideonOfTheTrialsEmblem.java index 4451fc7711..d16b95c050 100644 --- a/Mage/src/main/java/mage/game/command/emblems/GideonOfTheTrialsEmblem.java +++ b/Mage/src/main/java/mage/game/command/emblems/GideonOfTheTrialsEmblem.java @@ -47,7 +47,7 @@ import mage.game.events.GameEvent; public class GideonOfTheTrialsEmblem extends Emblem { public GideonOfTheTrialsEmblem() { - this.setName("Emblem - Gideon of the Trials"); + this.setName("Emblem - Gideon"); Ability ability = new SimpleStaticAbility(Zone.COMMAND, new GideonOfTheTrialsCantLoseEffect()); this.getAbilities().add(ability); } diff --git a/Mage/src/main/java/mage/game/permanent/token/RekindlingPhoenixToken.java b/Mage/src/main/java/mage/game/permanent/token/RekindlingPhoenixToken.java index ccfcdd2e37..c72d50f494 100644 --- a/Mage/src/main/java/mage/game/permanent/token/RekindlingPhoenixToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/RekindlingPhoenixToken.java @@ -51,6 +51,7 @@ public class RekindlingPhoenixToken extends Token { public RekindlingPhoenixToken() { super("Elemental", "0/1 red Elemental creature token with \"At the beginning of your upkeep, sacrifice this creature and return target card named Rekindling Phoenix from your graveyard to the battlefield. It gains haste until end of turn.\""); + setTokenType(1); cardType.add(CardType.CREATURE); subtype.add(SubType.THRULL); color.setRed(true); diff --git a/Mage/src/main/java/mage/game/permanent/token/TilonallisSummonerElementalToken.java b/Mage/src/main/java/mage/game/permanent/token/TilonallisSummonerElementalToken.java index bc1320f5e0..dc3051a073 100644 --- a/Mage/src/main/java/mage/game/permanent/token/TilonallisSummonerElementalToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/TilonallisSummonerElementalToken.java @@ -39,6 +39,7 @@ public class TilonallisSummonerElementalToken extends Token { public TilonallisSummonerElementalToken() { super("Elemental", "1/1 red Elemental creature tokens"); + setTokenType(2); cardType.add(CardType.CREATURE); subtype.add(SubType.ELEMENTAL); diff --git a/Mage/src/main/java/mage/game/permanent/token/WandOfTheElementsFirstToken.java b/Mage/src/main/java/mage/game/permanent/token/WandOfTheElementsFirstToken.java index b309c31469..50999484da 100644 --- a/Mage/src/main/java/mage/game/permanent/token/WandOfTheElementsFirstToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/WandOfTheElementsFirstToken.java @@ -25,12 +25,12 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.game.permanent.token; -import mage.constants.CardType; -import mage.constants.SubType; + import mage.MageInt; import mage.abilities.keyword.FlyingAbility; +import mage.constants.CardType; +import mage.constants.SubType; /** * @@ -40,6 +40,7 @@ public class WandOfTheElementsFirstToken extends Token { public WandOfTheElementsFirstToken() { super("Elemental", "2/2 blue Elemental creature token with flying"); + setTokenType(1); cardType.add(CardType.CREATURE); this.subtype.add(SubType.ELEMENTAL); this.color.setBlue(true); diff --git a/Mage/src/main/java/mage/game/permanent/token/WandOfTheElementsSecondToken.java b/Mage/src/main/java/mage/game/permanent/token/WandOfTheElementsSecondToken.java index a4ba68b311..d69534aba0 100644 --- a/Mage/src/main/java/mage/game/permanent/token/WandOfTheElementsSecondToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/WandOfTheElementsSecondToken.java @@ -25,11 +25,11 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.game.permanent.token; + +import mage.MageInt; import mage.constants.CardType; import mage.constants.SubType; -import mage.MageInt; /** * @@ -39,6 +39,7 @@ public class WandOfTheElementsSecondToken extends Token { public WandOfTheElementsSecondToken() { super("Elemental", "3/3 red Elemental creature token"); + setTokenType(2); cardType.add(CardType.CREATURE); this.subtype.add(SubType.ELEMENTAL); this.color.setRed(true);