From ded38eb1c84c2fd67e213b8dd3fd33bf1b123dda Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Tue, 13 Sep 2011 14:23:09 +0000 Subject: [PATCH] Fix to "download set LQ images" list of files --- src/main/java/forge/CardUtil.java | 13 ++-- .../forge/Gui_DownloadSetPictures_LQ.java | 70 ++++++------------- src/main/java/forge/card/CardDb.java | 6 +- 3 files changed, 32 insertions(+), 57 deletions(-) diff --git a/src/main/java/forge/CardUtil.java b/src/main/java/forge/CardUtil.java index 2adb8cb1235..8edac406554 100644 --- a/src/main/java/forge/CardUtil.java +++ b/src/main/java/forge/CardUtil.java @@ -499,6 +499,14 @@ public final class CardUtil { return !isNonStackingKeyword(keyword); } + + public static String buildIdealFilename(final String cardName, final int artIndex, final int artIndexMax) + { + String nn = artIndexMax > 1 ? Integer.toString(artIndex+1) : ""; + String mwsCardName = GuiDisplayUtil.cleanStringMWS(cardName); + //3 letter set code with MWS filename format + return String.format("%s%s.full.jpg", mwsCardName, nn); + } /** *

buildFilename.

* @@ -518,10 +526,7 @@ public final class CardUtil { } /** - * buildFilename. - * - * @param card the card to get the filename for - * @return the filename + * buildFilename for lightweight card. Searches for a matching file on disk, */ public static String buildFilename(final CardPrinted card) { int maxIndex = card.getCard().getSetInfo(card.getSet()).getCopiesCount(); diff --git a/src/main/java/forge/Gui_DownloadSetPictures_LQ.java b/src/main/java/forge/Gui_DownloadSetPictures_LQ.java index 71310b5ecbd..598723ea4d2 100644 --- a/src/main/java/forge/Gui_DownloadSetPictures_LQ.java +++ b/src/main/java/forge/Gui_DownloadSetPictures_LQ.java @@ -1,6 +1,10 @@ package forge; import com.esotericsoftware.minlog.Log; + +import forge.card.CardDb; +import forge.card.CardPrinted; +import forge.card.CardSet; import forge.error.ErrorViewer; import forge.properties.ForgeProps; import forge.properties.NewConstants; @@ -8,6 +12,9 @@ import forge.properties.NewConstants; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; + +import org.apache.commons.lang3.StringUtils; + import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -386,66 +393,31 @@ public class Gui_DownloadSetPictures_LQ extends DefaultBoundedRangeModel impleme //File imgBase = ForgeProps.getFile(NewConstants.IMAGE_BASE); String URLBase = "http://cardforge.org/fpics/"; - String imgFN = ""; - for (Card c : AllZone.getCardFactory()) { - ArrayList cSetInfo = c.getSets(); - if (cSetInfo.size() > 0) { - for (int j = 0; j < cSetInfo.size(); j++) { - c.setCurSetCode(cSetInfo.get(j).Code); - String SC3 = c.getCurSetCode(); - String SC2 = SetUtils.getCode2ByCode(c.getCurSetCode()); + for (CardPrinted c : CardDb.instance().getAllCards()) { + String SC3 = c.getSet(); + if (StringUtils.isBlank(SC3) || "???".equals(SC3)) continue; // we don't want cards from unknown sets - int n = 0; - if (cSetInfo.get(j).PicCount > 0) { - n = cSetInfo.get(j).PicCount; + CardSet thisSet = SetUtils.getSetByCode(SC3); + String SC2 = thisSet.getCode2(); - for (int k = 1; k <= n; k++) { - c.setRandomPicture(k); - - imgFN = CardUtil.buildFilename(c); - if (imgFN.equals("none") || (!imgFN.contains(SC3) && !imgFN.contains(SC2))) { - String fn = GuiDisplayUtil.cleanStringMWS(c.getName()) + k + ".full.jpg"; - CList.add(new mCard(SC3 + "/" + fn, URLBase + SC2 + "/" + Base64Coder.encodeString(fn, true), SC3)); - } - } - } else { - c.setRandomPicture(0); - - imgFN = CardUtil.buildFilename(c); - if (imgFN.equals("none") || (!imgFN.contains(SC3) && !imgFN.contains(SC2))) { - String fn = GuiDisplayUtil.cleanStringMWS(c.getName()) + ".full.jpg"; - //if (MyRandom.percentTrue(50)) - CList.add(new mCard(SC3 + "/" + fn, URLBase + SC2 + "/" + Base64Coder.encodeString(fn, true), SC3)); - //else - //CList.add(new mCard(SC3 + "/" + fn, c.getCurSetURL(), SC3)); - - } - - } - } + String imgFN = CardUtil.buildFilename(c); + boolean foundSetImage = imgFN.contains(SC3) || imgFN.contains(SC2); + if (!foundSetImage) { + int artsCnt = c.getCard().getSetInfo(SC3).getCopiesCount(); + String fn = CardUtil.buildIdealFilename(c.getName(), c.getArtIndex(), artsCnt); + //System.out.println(fn); + CList.add(new mCard(SC3 + "/" + fn, URLBase + SC2 + "/" + Base64Coder.encodeString(fn, true), SC3)); } - - //Log.error(iName + ".jpg" + "\t" + URLs[0]); - } - //ArrayList list = new ArrayList(); - //File file; - - //File base = ForgeProps.getFile(IMAGE_TOKEN); - //for (int i = 0; i < cardTokenLQ.length; i++) { - // file = new File(base, cardTokenLQ[i].name.substring(3, cardTokenLQ[i].name.length())); - // if (!file.exists()) CList.add(cardTokenLQ[i]); - //} - //return all card names and urls that are needed mCard[] out = new mCard[CList.size()]; CList.toArray(out); - for (int i = 0; i < out.length; i++) - System.out.println(out[i].name + " " + out[i].url); + for (int i = 0; i < out.length; i++) { System.out.println(out[i].name + " " + out[i].url); } + return out; }//getNeededCards() diff --git a/src/main/java/forge/card/CardDb.java b/src/main/java/forge/card/CardDb.java index f8c5adbc304..6522af441ec 100644 --- a/src/main/java/forge/card/CardDb.java +++ b/src/main/java/forge/card/CardDb.java @@ -153,10 +153,8 @@ public final class CardDb { } // returns a list of all cards from their respective latest editions - public Iterable getAllUniqueCards() { - return uniqueCards.values(); - } - + public Iterable getAllUniqueCards() { return uniqueCards.values(); } + //public Iterable getAllCardRules() { return cards.values(); } // still not needed public Iterable getAllCards() { return allCardsFlat; } }