mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
de-duplicate filename construction
This commit is contained in:
@@ -187,7 +187,6 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
private int semiPermanentAttackBoost = 0;
|
||||
private int semiPermanentDefenseBoost = 0;
|
||||
|
||||
private int randomPicture = 0;
|
||||
private int xManaCostPaid = 0;
|
||||
|
||||
private int multiKickerMagnitude = 0;
|
||||
@@ -4567,29 +4566,6 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
return this.getNetAttack();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Setter for the field <code>randomPicture</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param n
|
||||
* a int.
|
||||
*/
|
||||
public final void setRandomPicture(final int n) {
|
||||
this.randomPicture = n;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Getter for the field <code>randomPicture</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public final int getRandomPicture() {
|
||||
return this.randomPicture;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addMultiKickerMagnitude.
|
||||
|
||||
@@ -23,12 +23,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.card.CardCharacteristics;
|
||||
import forge.card.CardInSet;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardSplitType;
|
||||
import forge.card.MagicColor;
|
||||
import forge.card.ability.AbilityUtils;
|
||||
import forge.card.ability.ApiType;
|
||||
@@ -36,75 +31,35 @@ import forge.card.spellability.AbilityManaPart;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.GuiDisplayUtil;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* CardUtil class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class CardUtil {
|
||||
/**
|
||||
* Do not instantiate.
|
||||
*/
|
||||
private CardUtil() {
|
||||
// This space intentionally left blank.
|
||||
// disable instantiation
|
||||
private CardUtil() { }
|
||||
|
||||
static final Map<String, String> colorMap;
|
||||
static {
|
||||
colorMap = new HashMap<String, String>();
|
||||
colorMap.put(Constant.Color.BLACK.toString(), "B");
|
||||
colorMap.put(Constant.Color.BLUE.toString(), "U");
|
||||
colorMap.put(Constant.Color.GREEN.toString(), "G");
|
||||
colorMap.put(Constant.Color.RED.toString(), "R");
|
||||
colorMap.put(Constant.Color.WHITE.toString(), "W");
|
||||
colorMap.put(Constant.Color.COLORLESS.toString(), "C");
|
||||
}
|
||||
|
||||
// returns "G", longColor is Constant.Color.Green and the like
|
||||
/**
|
||||
* <p>
|
||||
* getShortColor.
|
||||
* </p>
|
||||
*
|
||||
* @param longColor
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String getShortColor(final String longColor) {
|
||||
final Map<String, String> map = new HashMap<String, String>();
|
||||
map.put(Constant.Color.BLACK.toString(), "B");
|
||||
map.put(Constant.Color.BLUE.toString(), "U");
|
||||
map.put(Constant.Color.GREEN.toString(), "G");
|
||||
map.put(Constant.Color.RED.toString(), "R");
|
||||
map.put(Constant.Color.WHITE.toString(), "W");
|
||||
|
||||
final Object o = map.get(longColor);
|
||||
if (o == null) {
|
||||
if (!colorMap.containsKey(longColor)) {
|
||||
throw new RuntimeException("CardUtil : getShortColor() invalid argument - " + longColor);
|
||||
}
|
||||
|
||||
return (String) o;
|
||||
return colorMap.get(longColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getColors.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.Card} object.
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public static List<String> getColors(final Card c) {
|
||||
return c.determineColor().toStringList();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* isStackingKeyword.
|
||||
* </p>
|
||||
*
|
||||
* @param keyword
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
public static boolean isStackingKeyword(final String keyword) {
|
||||
String kw = new String(keyword);
|
||||
if (kw.startsWith("HIDDEN")) {
|
||||
@@ -114,97 +69,21 @@ public final class CardUtil {
|
||||
return !kw.startsWith("Protection") && !Constant.Keywords.NON_STACKING_LIST.contains(kw);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* buildFilename.
|
||||
* </p>
|
||||
*
|
||||
* @param card
|
||||
* a {@link forge.Card} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String buildFilename(final Card card) {
|
||||
final boolean token = card.isToken() && !card.isCopiedToken();
|
||||
|
||||
final String set = card.getCurSetCode();
|
||||
CardInSet neededSet = card.getRules().getEditionInfo(set);
|
||||
final int cntPictures = neededSet == null ? 1 : neededSet.getCopiesCount();
|
||||
return CardUtil.buildFilename(GuiDisplayUtil.cleanString(card.getName()), card.getCurSetCode(), card.getRandomPicture(), cntPictures, token);
|
||||
}
|
||||
|
||||
/**
|
||||
* buildFilename for lightweight card. Searches for a matching file on disk,
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
* @return the string
|
||||
*/
|
||||
public static String buildFilename(final IPaperCard card) {
|
||||
CardRules cr = card.getRules();
|
||||
final int maxIndex = cr.getEditionInfo(card.getEdition()).getCopiesCount();
|
||||
// picture is named AssaultBattery.full.jpg
|
||||
String imageName = cr.getSplitType() != CardSplitType.Split ? card.getName() : buildSplitCardFilename(cr);
|
||||
return CardUtil.buildFilename(GuiDisplayUtil.cleanString(imageName), card.getEdition(), card.getArtIndex(), maxIndex, false);
|
||||
}
|
||||
|
||||
public static String buildSplitCardFilename(CardRules cr) {
|
||||
return cr.getMainPart().getName() + cr.getOtherPart().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the filename.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
* @param nameToUse
|
||||
* the name to use
|
||||
* @return the string
|
||||
*/
|
||||
public static String buildFilename(final IPaperCard card, final String nameToUse) {
|
||||
final int maxIndex = card.getRules().getEditionInfo(card.getEdition()).getCopiesCount();
|
||||
return CardUtil.buildFilename(GuiDisplayUtil.cleanString(nameToUse), card.getEdition(), card.getArtIndex(), maxIndex, false);
|
||||
}
|
||||
|
||||
public static String buildFilename(final String cleanCardName, final String setName, final int artIndex,
|
||||
final int artIndexMax, final boolean isToken) {
|
||||
return String.format("%s%s%s%s.full",
|
||||
isToken ? ImageCache.TOKEN_PREFIX : "",
|
||||
StringUtils.isBlank(setName) ? "" : setName + "/",
|
||||
cleanCardName,
|
||||
artIndexMax <= 1 ? "" : String.valueOf(artIndex + 1));
|
||||
}
|
||||
|
||||
public static String getShortColorsString(final ArrayList<String> colors) {
|
||||
String colorDesc = "";
|
||||
StringBuilder colorDesc = new StringBuilder();
|
||||
for (final String col : colors) {
|
||||
if (col.equalsIgnoreCase("White")) {
|
||||
colorDesc += "W";
|
||||
} else if (col.equalsIgnoreCase("Blue")) {
|
||||
colorDesc += "U";
|
||||
} else if (col.equalsIgnoreCase("Black")) {
|
||||
colorDesc += "B";
|
||||
} else if (col.equalsIgnoreCase("Red")) {
|
||||
colorDesc += "R";
|
||||
} else if (col.equalsIgnoreCase("Green")) {
|
||||
colorDesc += "G";
|
||||
} else if (col.equalsIgnoreCase("Colorless")) {
|
||||
colorDesc = "C";
|
||||
colorDesc.append(getShortColor(col));
|
||||
}
|
||||
}
|
||||
return colorDesc;
|
||||
return colorDesc.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* getThisTurnEntered.
|
||||
*
|
||||
* @param to
|
||||
* zone going to
|
||||
* @param from
|
||||
* zone coming from
|
||||
* @param valid
|
||||
* a isValid expression
|
||||
* @param src
|
||||
* a Card object
|
||||
* @param to zone going to
|
||||
* @param from zone coming from
|
||||
* @param valid a isValid expression
|
||||
* @param src a Card object
|
||||
* @return a List<Card> that matches the given criteria
|
||||
*/
|
||||
public static List<Card> getThisTurnEntered(final ZoneType to, final ZoneType from, final String valid,
|
||||
@@ -223,15 +102,6 @@ public final class CardUtil {
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* getThisTurnCast.
|
||||
*
|
||||
* @param valid
|
||||
* a String object
|
||||
* @param src
|
||||
* a Card object
|
||||
* @return a List<Card> that matches the given criteria
|
||||
*/
|
||||
public static List<Card> getThisTurnCast(final String valid, final Card src) {
|
||||
List<Card> res = new ArrayList<Card>();
|
||||
|
||||
@@ -242,15 +112,6 @@ public final class CardUtil {
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* getLastTurnCast.
|
||||
*
|
||||
* @param valid
|
||||
* a String object
|
||||
* @param src
|
||||
* a Card object
|
||||
* @return a List<Card> that matches the given criteria
|
||||
*/
|
||||
public static List<Card> getLastTurnCast(final String valid, final Card src) {
|
||||
List<Card> res = new ArrayList<Card>();
|
||||
|
||||
@@ -262,10 +123,7 @@ public final class CardUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* getLKICopy.
|
||||
*
|
||||
* @param in
|
||||
* a Card to copy.
|
||||
* @param in a Card to copy.
|
||||
* @return a copy of C with LastKnownInfo stuff retained.
|
||||
*/
|
||||
public static Card getLKICopy(final Card in) {
|
||||
@@ -314,17 +172,6 @@ public final class CardUtil {
|
||||
return newCopy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the radiance.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @param origin
|
||||
* the origin
|
||||
* @param valid
|
||||
* the valid
|
||||
* @return the radiance
|
||||
*/
|
||||
public static List<Card> getRadiance(final Card source, final Card origin, final String[] valid) {
|
||||
final List<Card> res = new ArrayList<Card>();
|
||||
|
||||
@@ -344,11 +191,6 @@ public final class CardUtil {
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the face down characteristic.
|
||||
*
|
||||
* @return the face down characteristic
|
||||
*/
|
||||
public static CardCharacteristics getFaceDownCharacteristic() {
|
||||
final ArrayList<String> types = new ArrayList<String>();
|
||||
types.add("Creature");
|
||||
@@ -365,22 +207,6 @@ public final class CardUtil {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// add Colors and
|
||||
/**
|
||||
* <p>
|
||||
* reflectableMana.
|
||||
* </p>
|
||||
*
|
||||
* @param abMana
|
||||
* a {@link forge.card.spellability.AbilityMana} object.
|
||||
* @param af
|
||||
* a {@link forge.card.ability.AbilityFactory} object.
|
||||
* @param colors
|
||||
* a {@link java.util.ArrayList} object.
|
||||
* @param parents
|
||||
* a {@link java.util.ArrayList} object.
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public static Set<String> getReflectableManaColors(final SpellAbility abMana, final SpellAbility sa,
|
||||
Set<String> colors, final List<Card> parents) {
|
||||
// Here's the problem with reflectable Mana. If more than one is out,
|
||||
@@ -508,8 +334,4 @@ public final class CardUtil {
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // end class CardUtil
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.mortennobel.imagescaling.ResampleOp;
|
||||
|
||||
import forge.gui.GuiDisplayUtil;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.properties.NewConstants;
|
||||
@@ -55,16 +54,17 @@ public class ImageCache {
|
||||
static private final LoadingCache<String, BufferedImage> CACHE = CacheBuilder.newBuilder().softValues().build(new ImageLoader());
|
||||
|
||||
public static BufferedImage getImage(final Card card, final int width, final int height) {
|
||||
final String key = card.canBeShownTo(Singletons.getControl().getPlayer()) ? ImageCache.getKey(card) : NewConstants.CACHE_MORPH_IMAGE_FILE;
|
||||
final String key;
|
||||
if (!card.canBeShownTo(Singletons.getControl().getPlayer()) || card.isFaceDown()) {
|
||||
key = TOKEN_PREFIX + NewConstants.CACHE_MORPH_IMAGE_FILE;
|
||||
} else {
|
||||
key = card.getImageFilename();
|
||||
}
|
||||
return scaleImage(key, width, height);
|
||||
}
|
||||
|
||||
|
||||
public static BufferedImage getImage(final InventoryItem ii, final int width, final int height) {
|
||||
// TODO: move all the path-building logics here from the very objects. They don't have to know where their picture is
|
||||
String key = getKey(ii);
|
||||
|
||||
return scaleImage(key, width, height);
|
||||
return scaleImage(ii.getImageFilename(), width, height);
|
||||
}
|
||||
|
||||
public static BufferedImage getImage(final String key, final int width, final int height) {
|
||||
@@ -128,18 +128,4 @@ public class ImageCache {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the map key for a card, without any suffixes for the image size.
|
||||
*/
|
||||
public static String getKey(final Card card) {
|
||||
if ((card.isToken() && !card.isCopiedToken()) || card.isFaceDown()) {
|
||||
return ImageCache.TOKEN_PREFIX + GuiDisplayUtil.cleanString(card.getImageFilename());
|
||||
}
|
||||
return card.getImageFilename(); // key;
|
||||
}
|
||||
|
||||
public static String getKey(final InventoryItem ii) {
|
||||
return ii.getImageFilename();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,17 +42,9 @@ final class ImageLoader extends CacheLoader<String, BufferedImage> {
|
||||
|
||||
BufferedImage ret = _findFile(key, path, filename);
|
||||
|
||||
// try without set prefix and/or '.full' suffix
|
||||
if (null == ret && (filename.contains("/") || filename.contains(".full"))) {
|
||||
String bareFilename = filename;
|
||||
if (bareFilename.contains("/")) {
|
||||
bareFilename = filename.substring(filename.indexOf('/') + 1);
|
||||
}
|
||||
if (bareFilename.endsWith(".full")) {
|
||||
bareFilename = bareFilename.substring(0, bareFilename.length() - 5);
|
||||
}
|
||||
|
||||
ret = _findFile(key, path, bareFilename);
|
||||
// try without set prefix
|
||||
if (null == ret && filename.contains("/")) {
|
||||
ret = _findFile(key, path, filename.substring(filename.indexOf('/') + 1));
|
||||
}
|
||||
|
||||
if (null == ret) {
|
||||
|
||||
@@ -38,12 +38,9 @@ public final class CardRules implements ICardCharacteristics {
|
||||
private final CardSplitType splitType;
|
||||
private final ICardFace mainPart;
|
||||
private final ICardFace otherPart;
|
||||
|
||||
private CardAiHints aiHints;
|
||||
private final Map<String, CardInSet> setsPrinted = new TreeMap<String, CardInSet>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
|
||||
|
||||
private CardAiHints aiHints;
|
||||
|
||||
public CardRules(ICardFace[] faces, CardSplitType altMode, CardAiHints cah, Map<String, CardInSet> sets) {
|
||||
splitType = altMode;
|
||||
@@ -68,25 +65,18 @@ public final class CardRules implements ICardCharacteristics {
|
||||
return !(getType().isVanguard() || getType().isScheme() || getType().isPlane() || getType().isPhenomenon());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the splitType
|
||||
*/
|
||||
public CardSplitType getSplitType() {
|
||||
return splitType;
|
||||
}
|
||||
|
||||
public ICardFace getMainPart() {
|
||||
// TODO Auto-generated method stub
|
||||
return mainPart;
|
||||
}
|
||||
|
||||
|
||||
public ICardFace getOtherPart() {
|
||||
return otherPart;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
switch(splitType.getAggregationMethod()) {
|
||||
case AGGREGATE:
|
||||
@@ -121,7 +111,6 @@ public final class CardRules implements ICardCharacteristics {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ColorSet getColor() {
|
||||
switch(splitType.getAggregationMethod()) {
|
||||
@@ -132,14 +121,12 @@ public final class CardRules implements ICardCharacteristics {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override public int getIntPower() { return mainPart.getIntPower(); }
|
||||
@Override public int getIntToughness() { return mainPart.getIntToughness(); }
|
||||
@Override public String getPower() { return mainPart.getPower(); }
|
||||
@Override public String getToughness() { return mainPart.getToughness(); }
|
||||
@Override public int getInitialLoyalty() { return mainPart.getInitialLoyalty(); }
|
||||
|
||||
|
||||
@Override
|
||||
public String getOracleText() {
|
||||
switch(splitType.getAggregationMethod()) {
|
||||
@@ -150,14 +137,12 @@ public final class CardRules implements ICardCharacteristics {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getSets() { return this.setsPrinted.keySet(); }
|
||||
public CardInSet getEditionInfo(final String setCode) {
|
||||
final CardInSet result = this.setsPrinted.get(setCode);
|
||||
return result; // if returns null, String.format("Card '%s' was never printed in set '%s'", this.getName(), setCode);
|
||||
}
|
||||
|
||||
|
||||
// vanguard card fields, they don't use sides.
|
||||
private int deltaHand;
|
||||
private int deltaLife;
|
||||
@@ -180,38 +165,19 @@ public final class CardRules implements ICardCharacteristics {
|
||||
public String getPictureOtherSideUrl() { return dlUrlOtherSide; }
|
||||
public void setDlUrls(String[] dlUrls) { this.dlUrl = dlUrls[0]; this.dlUrlOtherSide = dlUrls[1]; }
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.card.ICardCharacteristics#getReplacements()
|
||||
*/
|
||||
public final List<String> getReplacements() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.card.ICardCharacteristics#getTriggers()
|
||||
*/
|
||||
public final List<String> getTriggers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.card.ICardCharacteristics#getStaticAbilities()
|
||||
*/
|
||||
public final List<String> getStaticAbilities() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.card.ICardCharacteristics#getAbilities()
|
||||
*/
|
||||
public final List<String> getAbilities() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import forge.card.spellability.Target;
|
||||
import forge.card.trigger.TriggerHandler;
|
||||
import forge.game.player.Player;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.IPaperCard;
|
||||
|
||||
/**
|
||||
@@ -223,8 +224,6 @@ public class CardFactory {
|
||||
c.setCurSetCode(cp.getEdition());
|
||||
c.setRarity(cp.getRarity());
|
||||
|
||||
|
||||
c.setRandomPicture(cp.getArtIndex() + 1);
|
||||
String originalPicture = cp.getImageFilename();
|
||||
//System.out.println(c.getName() + " -> " + originalPicture);
|
||||
c.setImageFilename(originalPicture);
|
||||
@@ -235,9 +234,9 @@ public class CardFactory {
|
||||
c.setState(CardCharacteristicName.Flipped);
|
||||
c.setImageFilename(originalPicture); // should assign a 180 degrees rotated picture here?
|
||||
}
|
||||
else if (c.isDoubleFaced()) {
|
||||
else if (c.isDoubleFaced() && cp instanceof CardPrinted) {
|
||||
c.setState(CardCharacteristicName.Transformed);
|
||||
c.setImageFilename(CardUtil.buildFilename(cp, cp.getRules().getOtherPart().getName()));
|
||||
c.setImageFilename(((CardPrinted)cp).getBackFaceImageFilename());
|
||||
}
|
||||
else if (c.getRules().getSplitType() == CardSplitType.Split) {
|
||||
c.setState(CardCharacteristicName.LeftSplit);
|
||||
@@ -246,17 +245,14 @@ public class CardFactory {
|
||||
c.setRarity(cp.getRarity());
|
||||
c.setState(CardCharacteristicName.RightSplit);
|
||||
c.setImageFilename(originalPicture);
|
||||
} else {
|
||||
c.setImageFilename(CardUtil.buildFilename(c));
|
||||
}
|
||||
|
||||
|
||||
c.setCurSetCode(cp.getEdition());
|
||||
c.setRarity(cp.getRarity());
|
||||
c.setState(CardCharacteristicName.Original);
|
||||
}
|
||||
return c;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
private static void buildAbilities(final Card card) {
|
||||
|
||||
@@ -34,8 +34,8 @@ import javax.swing.filechooser.FileFilter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.gui.download.GuiDownloadSetPicturesLQ;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.util.FileSection;
|
||||
import forge.util.FileSectionManual;
|
||||
import forge.util.FileUtil;
|
||||
@@ -48,27 +48,15 @@ import freemarker.template.TemplateException;
|
||||
|
||||
/**
|
||||
* This class knows how to make a file out of a deck object and vice versa.
|
||||
*
|
||||
*/
|
||||
public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSerializer<Deck> {
|
||||
|
||||
/**
|
||||
* Instantiates a new deck serializer.
|
||||
*
|
||||
* @param deckDir0 the deck dir0
|
||||
*/
|
||||
private final boolean moveWronglyNamedDecks;
|
||||
private static final String FILE_EXTENSION = ".dck";
|
||||
|
||||
/** @param deckDir0 {@link java.io.File} */
|
||||
public DeckSerializer(final File deckDir0) {
|
||||
this(deckDir0, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param deckDir0 {@link java.io.File}
|
||||
* @param moveWrongDecks boolean
|
||||
*/
|
||||
public DeckSerializer(final File deckDir0, boolean moveWrongDecks) {
|
||||
super(deckDir0, Deck.FN_NAME_SELECTOR);
|
||||
moveWronglyNamedDecks = moveWrongDecks;
|
||||
@@ -149,17 +137,11 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
|
||||
final List<String> list = new ArrayList<String>();
|
||||
for (final Entry<CardPrinted, Integer> card : d.getMain()) {
|
||||
// System.out.println(card.getSets().get(card.getSets().size() - 1).URL);
|
||||
for( int i = card.getValue().intValue(); i > 0; --i ) {
|
||||
String url = GuiDownloadSetPicturesLQ.getCardPictureUrl(card.getKey(), card.getKey().getName());
|
||||
for (int i = card.getValue().intValue(); i > 0; --i ) {
|
||||
String url = NewConstants.URL_PIC_DOWNLOAD + card.getKey().getImageUrlPath(false);
|
||||
list.add(url);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* List<String> nameList = new ArrayList<String>(); for (Card card :
|
||||
* d.getMain().toForgeCardList().toArray()) {
|
||||
* //System.out.println(card.getSets().get(card.getSets().size() -
|
||||
* 1).URL); nameList.add(card.getName()); }
|
||||
*/
|
||||
|
||||
final TreeMap<String, Integer> map = new TreeMap<String, Integer>();
|
||||
for (final Entry<CardPrinted, Integer> entry : d.getMain().getOrderedList()) {
|
||||
@@ -173,11 +155,9 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
|
||||
root.put("height", height);
|
||||
root.put("width", width);
|
||||
root.put("cardlistWidth", width - 11);
|
||||
// root.put("nameList", nameList);
|
||||
root.put("cardList", map);
|
||||
|
||||
/* Merge data-model with template */
|
||||
// StringWriter sw = new StringWriter();
|
||||
temp.process(root, out);
|
||||
out.flush();
|
||||
} catch (final IOException e) {
|
||||
@@ -187,30 +167,10 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* writeDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @param f
|
||||
* a {@link java.io.File} object.
|
||||
*/
|
||||
public static void writeDeck(final Deck d, final File f) {
|
||||
FileUtil.writeFile(f, d.save());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Write deck to HTML.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.deck.Deck} object.
|
||||
* @param f
|
||||
* a {@link java.io.File} object.
|
||||
*/
|
||||
public static void writeDeckHtml(final Deck d, final File f) {
|
||||
try {
|
||||
final BufferedWriter writer = new BufferedWriter(new FileWriter(f));
|
||||
@@ -221,43 +181,20 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.deck.IDeckSerializer#save(forge.item.CardCollectionBase,
|
||||
* java.io.File)
|
||||
*/
|
||||
@Override
|
||||
public void save(final Deck unit) {
|
||||
FileUtil.writeFile(this.makeFileFor(unit), unit.save());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.deck.IDeckSerializer#erase(forge.item.CardCollectionBase,
|
||||
* java.io.File)
|
||||
*/
|
||||
@Override
|
||||
public void erase(final Deck unit) {
|
||||
this.makeFileFor(unit).delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make file name.
|
||||
*
|
||||
* @param deck the deck
|
||||
* @return a File
|
||||
*/
|
||||
public File makeFileFor(final Deck deck) {
|
||||
return new File(this.getDirectory(), deck.getBestFileName() + FILE_EXTENSION);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.deck.io.DeckSerializerBase#read(java.io.File)
|
||||
*/
|
||||
@Override
|
||||
protected Deck read(final File file) {
|
||||
final Map<String, List<String>> sections = FileSection.parseSections(FileUtil.readFile(file));
|
||||
@@ -269,11 +206,6 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file {@link java.io.File}
|
||||
* @param result {@link forge.deck.Deck}
|
||||
*/
|
||||
private void adjustFileLocation(final File file, final Deck result) {
|
||||
if (result == null) {
|
||||
file.delete();
|
||||
@@ -285,23 +217,11 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.deck.io.DeckSerializerBase#getFileFilter()
|
||||
*/
|
||||
@Override
|
||||
protected FilenameFilter getFileFilter() {
|
||||
return DeckSerializer.DCK_FILE_FILTER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read deck metadata.
|
||||
*
|
||||
* @param map the map
|
||||
* @param canThrow the can throw
|
||||
* @return the deck file header
|
||||
*/
|
||||
public static DeckFileHeader readDeckMetadata(final Map<String, List<String>> map, final boolean canThrow) {
|
||||
if (map == null) {
|
||||
return null;
|
||||
@@ -323,5 +243,4 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.google.common.collect.Lists;
|
||||
import forge.Card;
|
||||
import forge.CardLists;
|
||||
import forge.CardPredicates;
|
||||
import forge.CardUtil;
|
||||
import forge.Singletons;
|
||||
import forge.card.trigger.TriggerHandler;
|
||||
import forge.card.trigger.TriggerType;
|
||||
@@ -100,8 +99,7 @@ public class GameNew {
|
||||
if (preferences.getPrefBoolean(FPref.UI_RANDOM_CARD_ART)) {
|
||||
final int cntVariants = cardPrinted.getRules().getEditionInfo(cardPrinted.getEdition()).getCopiesCount();
|
||||
if (cntVariants > 1) {
|
||||
card.setRandomPicture(generator.nextInt(cntVariants - 1) + 1);
|
||||
card.setImageFilename(CardUtil.buildFilename(card));
|
||||
card.setImageFilename(cardPrinted.getImageFilename(generator.nextInt(cntVariants)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,6 @@ import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -172,20 +170,6 @@ public final class GuiDisplayUtil {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String cleanString(final String in) {
|
||||
final StringBuffer out = new StringBuffer();
|
||||
char c;
|
||||
for (int i = 0; i < in.length(); i++) {
|
||||
c = in.charAt(i);
|
||||
if ((c == ' ') || (c == '-') || (c == '_')) {
|
||||
out.append('_');
|
||||
} else if (Character.isLetterOrDigit(c)) {
|
||||
out.append(c);
|
||||
}
|
||||
}
|
||||
return out.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public static void updateGUI() {
|
||||
for (Player p : Singletons.getModel().getGame().getRegisteredPlayers()) {
|
||||
|
||||
@@ -456,9 +440,6 @@ public final class GuiDisplayUtil {
|
||||
c.setCurSetCode(c.getMostRecentSet());
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(c.getImageFilename()))
|
||||
c.setImageFilename(CardUtil.buildFilename(c));
|
||||
|
||||
cl.add(c);
|
||||
}
|
||||
return cl;
|
||||
|
||||
@@ -221,7 +221,7 @@ public class GuiImportPicture extends JDialog {
|
||||
fName = GuiImportPicture.this.listFiles.get(i).getName();
|
||||
start = fName.indexOf("full");
|
||||
fName = fName.substring(0, start - 1) + fName.substring(start + 4, fName.length() - 4);
|
||||
fName = GuiDisplayUtil.cleanString(fName) + ".jpg";
|
||||
//fName = GuiDisplayUtil.cleanString(fName) + ".jpg";
|
||||
final File file = new File(NewConstants.CACHE_CARD_PICS_DIR, fName);
|
||||
if (!file.exists()) {
|
||||
GuiImportPicture.this.filesForCopy = GuiImportPicture.this.filesForCopy + 1;
|
||||
@@ -322,7 +322,7 @@ public class GuiImportPicture extends JDialog {
|
||||
fName = GuiImportPicture.this.listFiles.get(i).getName();
|
||||
start = fName.indexOf("full");
|
||||
fName = fName.substring(0, start - 1) + fName.substring(start + 4, fName.length() - 4);
|
||||
fName = GuiDisplayUtil.cleanString(fName) + ".jpg";
|
||||
//fName = GuiDisplayUtil.cleanString(fName) + ".jpg";
|
||||
final File file = new File(NewConstants.CACHE_CARD_PICS_DIR, fName);
|
||||
if (!file.exists()) {
|
||||
GuiImportPicture.this.filesForCopy = GuiImportPicture.this.filesForCopy + 1;
|
||||
|
||||
@@ -19,57 +19,34 @@ package forge.gui.download;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardSplitType;
|
||||
import forge.card.ICardCharacteristics;
|
||||
import forge.gui.GuiDisplayUtil;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_DownloadPictures_LQ class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class GuiDownloadPicturesLQ extends GuiDownloader {
|
||||
private ArrayList<DownloadObject> downloads;
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Write javadoc for this method.
|
||||
*/
|
||||
public GuiDownloadPicturesLQ() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getNeededCards.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.gui.download.GuiDownloader.DownloadObject} objects.
|
||||
*/
|
||||
@Override
|
||||
protected final ArrayList<DownloadObject> getNeededImages() {
|
||||
downloads = new ArrayList<DownloadObject>();
|
||||
ArrayList<DownloadObject> downloads = new ArrayList<DownloadObject>();
|
||||
Set<String> filenames = new HashSet<String>();
|
||||
|
||||
for (final IPaperCard c : CardDb.instance().getUniqueCards()) {
|
||||
for (final CardPrinted c : CardDb.instance().getUniqueCards()) {
|
||||
CardRules cardRules = c.getRules();
|
||||
if (cardRules != null && cardRules.getSplitType() == CardSplitType.Split && cardRules.getOtherPart() != null) {
|
||||
this.createDLObjects(cardRules.getPictureUrl(), String.format("%s%s", cardRules.getMainPart().getName(), cardRules.getOtherPart().getName()));
|
||||
} else {
|
||||
this.createDLObjects(cardRules.getPictureUrl(), cardRules.getMainPart().getName());
|
||||
}
|
||||
addDLObject(cardRules.getPictureUrl(), c.getImageFilename(), downloads, filenames);
|
||||
|
||||
ICardCharacteristics secondSide = cardRules.getOtherPart();
|
||||
if (secondSide != null && cardRules.getSplitType() == CardSplitType.Transform) {
|
||||
this.createDLObjects(cardRules.getPictureOtherSideUrl(), secondSide.getName());
|
||||
String backFaceImage = c.getBackFaceImageFilename();
|
||||
if (backFaceImage != null) {
|
||||
addDLObject(cardRules.getPictureOtherSideUrl(), backFaceImage, downloads, filenames);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,23 +58,20 @@ public class GuiDownloadPicturesLQ extends GuiDownloader {
|
||||
}
|
||||
|
||||
return downloads;
|
||||
} // getNeededImages()
|
||||
|
||||
private void createDLObjects(final String url, final String cardName) {
|
||||
|
||||
if (url != null && !url.isEmpty()) {
|
||||
final String[] urls = url.split("\\\\");
|
||||
|
||||
final String sName = GuiDisplayUtil.cleanString(cardName);
|
||||
addDownloadObject(urls[0], new File(NewConstants.CACHE_CARD_PICS_DIR, sName + ".jpg"));
|
||||
|
||||
for (int j = 1; j < urls.length; j++) {
|
||||
addDownloadObject(urls[j], new File(NewConstants.CACHE_CARD_PICS_DIR, sName + j + ".jpg"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addDownloadObject(String url, File destFile) {
|
||||
private void addDLObject(String url, String filename, ArrayList<DownloadObject> downloads, Set<String> filenames) {
|
||||
if (StringUtils.isEmpty(url) || filenames.contains(filename)) {
|
||||
return;
|
||||
}
|
||||
filenames.add(filename);
|
||||
|
||||
// remove set path prefix from card filename
|
||||
if (filename.contains("/")) {
|
||||
filename = filename.substring(filename.indexOf('/') + 1);
|
||||
}
|
||||
|
||||
File destFile = new File(NewConstants.CACHE_CARD_PICS_DIR, filename + ".jpg");
|
||||
if (!destFile.exists()) {
|
||||
downloads.add(new DownloadObject(url, destFile));
|
||||
}
|
||||
|
||||
@@ -24,15 +24,9 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.CardUtil;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardSplitType;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.util.Base64Coder;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class GuiDownloadSetPicturesLQ extends GuiDownloader {
|
||||
@@ -40,68 +34,39 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
|
||||
super();
|
||||
}
|
||||
|
||||
private final void addCardToList(ArrayList<DownloadObject> cList, CardPrinted c, String nameToUse) {
|
||||
File file = new File(NewConstants.CACHE_CARD_PICS_DIR, CardUtil.buildFilename(c, nameToUse) + ".jpg");
|
||||
if (!file.exists()) {
|
||||
cList.add(new DownloadObject(getCardPictureUrl(c, nameToUse), file));
|
||||
}
|
||||
|
||||
final String setCode3 = c.getEdition();
|
||||
final CardEdition thisSet = Singletons.getModel().getEditions().get(setCode3);
|
||||
System.out.println(String.format("%s [%s - %s]", nameToUse, setCode3, thisSet.getName()));
|
||||
}
|
||||
|
||||
private static String cleanMWS(String in) {
|
||||
final StringBuffer out = new StringBuffer();
|
||||
char c;
|
||||
for (int i = 0; i < in.length(); i++) {
|
||||
c = in.charAt(i);
|
||||
if ((c == '"') || (c == '/') || (c == ':') || (c == '?')) {
|
||||
out.append("");
|
||||
} else {
|
||||
out.append(c);
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static String getCardPictureUrl(final CardPrinted c, final String cardName) {
|
||||
String setCode3 = c.getEdition();
|
||||
String setCode2 = Singletons.getModel().getEditions().get(setCode3).getCode2();
|
||||
int artsCnt = c.getRules().getEditionInfo(setCode3).getCopiesCount();
|
||||
String filename = CardUtil.buildFilename(cleanMWS(cardName), null, c.getArtIndex(), artsCnt, false) + ".jpg";
|
||||
|
||||
return NewConstants.URL_PIC_DOWNLOAD + setCode2 + "/" + Base64Coder.encodeString(filename, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final ArrayList<DownloadObject> getNeededImages() {
|
||||
final ArrayList<DownloadObject> cList = new ArrayList<DownloadObject>();
|
||||
ArrayList<DownloadObject> downloads = new ArrayList<DownloadObject>();
|
||||
|
||||
Iterable<CardPrinted> allPrinted = Iterables.concat(CardDb.instance().getAllCards(), CardDb.variants().getAllCards());
|
||||
|
||||
for (final CardPrinted c : allPrinted) {
|
||||
for (final CardPrinted c : Iterables.concat(CardDb.instance().getAllCards(), CardDb.variants().getAllCards())) {
|
||||
final String setCode3 = c.getEdition();
|
||||
if (StringUtils.isBlank(setCode3) || "???".equals(setCode3)) {
|
||||
continue; // we don't want cards from unknown sets
|
||||
// we don't want cards from unknown sets
|
||||
continue;
|
||||
}
|
||||
|
||||
CardRules cr = c.getRules();
|
||||
String firstPartName = cr.getSplitType() == CardSplitType.Split ? CardUtil.buildSplitCardFilename(cr) : c.getName();
|
||||
addCardToList(cList, c, firstPartName);
|
||||
addDLObject(c.getImageUrlPath(false), c.getImageFilename(), downloads);
|
||||
|
||||
if (cr.getSplitType() == CardSplitType.Transform) {
|
||||
addCardToList(cList, c, cr.getOtherPart().getName());
|
||||
String backFaceImage = c.getBackFaceImageFilename();
|
||||
if (backFaceImage != null) {
|
||||
addDLObject(c.getImageUrlPath(true), backFaceImage, downloads);
|
||||
}
|
||||
}
|
||||
|
||||
// add missing tokens to the list of things to download
|
||||
// Add missing tokens to the list of things to download.
|
||||
for (final DownloadObject element : GuiDownloader.readFileWithNames(NewConstants.IMAGE_LIST_TOKENS_FILE, NewConstants.CACHE_TOKEN_PICS_DIR)) {
|
||||
if (!element.getDestination().exists()) {
|
||||
cList.add(element);
|
||||
downloads.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
return cList;
|
||||
return downloads;
|
||||
}
|
||||
|
||||
private void addDLObject(String urlPath, String filename, ArrayList<DownloadObject> downloads) {
|
||||
File destFile = new File(NewConstants.CACHE_CARD_PICS_DIR, filename + ".jpg");
|
||||
if (!destFile.exists()) {
|
||||
downloads.add(new DownloadObject(NewConstants.URL_PIC_DOWNLOAD + urlPath, destFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,11 +68,8 @@ import forge.gui.toolbox.JXButtonPanel;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
/** */
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class GuiDownloader extends DefaultBoundedRangeModel implements Runnable {
|
||||
|
||||
/** */
|
||||
public static final Proxy.Type[] TYPES = Proxy.Type.values(); /** */
|
||||
|
||||
// Actions and commands
|
||||
@@ -109,17 +106,16 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
private final JRadioButton radProxyHTTP = new FRadioButton("HTTP Proxy");
|
||||
|
||||
// Proxy info
|
||||
private int type; /** */
|
||||
private int type;
|
||||
|
||||
// Progress variables
|
||||
private ArrayList<DownloadObject> cards; /** */
|
||||
private int card; /** */
|
||||
private boolean cancel; /** */
|
||||
private final long[] times = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /** */
|
||||
private int tptr = 0; /** */
|
||||
private long lTime = System.currentTimeMillis(); /** */
|
||||
private ArrayList<DownloadObject> cards;
|
||||
private int card;
|
||||
private boolean cancel;
|
||||
private final long[] times = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
private int tptr = 0;
|
||||
private long lTime = System.currentTimeMillis();
|
||||
|
||||
/** Constructor. */
|
||||
protected GuiDownloader() {
|
||||
String radConstraints = "w 100%!, h 30px!, gap 2% 0 0 10px";
|
||||
JXButtonPanel grpPanel = new JXButtonPanel();
|
||||
@@ -158,7 +154,11 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
SwingWorker<Void, Void> thrGetImages = new SwingWorker<Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception {
|
||||
try {
|
||||
GuiDownloader.this.cards = GuiDownloader.this.getNeededImages();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -181,13 +181,11 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
else {
|
||||
barProgress.setMaximum(this.cards.size());
|
||||
barProgress.setString(
|
||||
this.cards.size() == 1
|
||||
? "1 item found."
|
||||
: this.cards.size() + " items found.");
|
||||
|
||||
this.cards.size() == 1 ? "1 item found." : this.cards.size() + " items found.");
|
||||
btnStart.setVisible(true);
|
||||
btnStart.addActionListener(actStartDownload);
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -208,13 +206,6 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
FOverlay.SINGLETON_INSTANCE.getPanel().removeAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getAverageTimePerObject.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
protected final int getAverageTimePerObject() {
|
||||
int numNonzero = 10;
|
||||
|
||||
@@ -237,14 +228,6 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
return tTime / Math.max(1, numNonzero);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* update.
|
||||
* </p>
|
||||
*
|
||||
* @param card
|
||||
* a int.
|
||||
*/
|
||||
private void update(final int card) {
|
||||
this.card = card;
|
||||
|
||||
@@ -299,12 +282,6 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
EventQueue.invokeLater(new Worker(card));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* run.
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
public final void run() {
|
||||
BufferedInputStream in;
|
||||
BufferedOutputStream out;
|
||||
@@ -334,15 +311,16 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
final File fileDest = this.cards.get(this.card).getDestination();
|
||||
final File base = fileDest.getParentFile();
|
||||
|
||||
//System.out.println(String.format("Downloading %s to %s", url, fileDest.getPath()));
|
||||
try {
|
||||
// test for folder existence
|
||||
if (!base.exists() && !base.mkdir()) { // create folder if not found
|
||||
System.out.println("Can't create folder" + base.getAbsolutePath());
|
||||
}
|
||||
// Don't allow redirections here!
|
||||
|
||||
URL imageUrl = new URL(url);
|
||||
HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();
|
||||
// don't allow redirections here -- they indicate 'file not found' on the server
|
||||
conn.setInstanceFollowRedirects(false);
|
||||
conn.connect();
|
||||
|
||||
@@ -394,13 +372,6 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
}
|
||||
} // run
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getNeededCards.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.gui.download.GuiDownloader.DownloadObject} objects.
|
||||
*/
|
||||
protected abstract ArrayList<DownloadObject> getNeededImages();
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,6 @@ import forge.gui.framework.ICDoc;
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public enum CSubmenuDownloaders implements ICDoc {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private final Command cmdLicensing = new Command() { @Override
|
||||
|
||||
@@ -23,12 +23,14 @@ import java.util.Map;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.Card;
|
||||
import forge.CardUtil;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardSplitType;
|
||||
import forge.card.ICardFace;
|
||||
import forge.card.cardfactory.CardFactory;
|
||||
import forge.game.player.Player;
|
||||
import forge.util.Base64Coder;
|
||||
|
||||
|
||||
/**
|
||||
@@ -54,9 +56,6 @@ public final class CardPrinted implements Comparable<IPaperCard>, InventoryItemF
|
||||
private final transient CardRarity rarity; // rarity is given in ctor when
|
||||
// set is assigned
|
||||
|
||||
// image filename is calculated only after someone request it
|
||||
private transient String imageFilename = null;
|
||||
|
||||
// field RO accessors
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -121,30 +120,59 @@ public final class CardPrinted implements Comparable<IPaperCard>, InventoryItemF
|
||||
return this.rarity;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.item.InventoryItemFromSet#getImageFilename()
|
||||
*/
|
||||
/* (non-Javadoc)
|
||||
* @see forge.item.ICardPrinted#getImageFilename()
|
||||
*/
|
||||
@Override
|
||||
public String getImageFilename() {
|
||||
if (this.imageFilename == null) {
|
||||
this.imageFilename = CardUtil.buildFilename(this);
|
||||
private static String toMWSFilename(String in) {
|
||||
final StringBuffer out = new StringBuffer();
|
||||
char c;
|
||||
for (int i = 0; i < in.length(); i++) {
|
||||
c = in.charAt(i);
|
||||
if ((c == '"') || (c == '/') || (c == ':') || (c == '?')) {
|
||||
out.append("");
|
||||
} else {
|
||||
out.append(c);
|
||||
}
|
||||
return this.imageFilename;
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImageFilename() {
|
||||
return getImageFilename(getArtIndex());
|
||||
}
|
||||
|
||||
public String getImageUrlPath(boolean backFace) {
|
||||
return getImageLocator(backFace ? card.getOtherPart().getName() : name, getArtIndex(), true);
|
||||
}
|
||||
|
||||
public String getImageFilename(int artIdx) {
|
||||
return getImageLocator(getArtIndex(), false);
|
||||
}
|
||||
|
||||
private String getImageLocator(String nameToUse, int artIdx, boolean base64encode) {
|
||||
int cntPictures = card.getEditionInfo(edition).getCopiesCount();
|
||||
nameToUse = toMWSFilename(nameToUse);
|
||||
if (cntPictures > 1 && cntPictures > artIdx) {
|
||||
nameToUse += String.valueOf(artIdx + 1);
|
||||
}
|
||||
nameToUse += ".full";
|
||||
return String.format("%s/%s",
|
||||
Singletons.getModel().getEditions().getCode2ByCode(edition),
|
||||
base64encode ? Base64Coder.encodeString(nameToUse + ".jpg", true) : nameToUse);
|
||||
}
|
||||
|
||||
private String getImageLocator(int artIdx, boolean base64encode) {
|
||||
return getImageLocator(CardSplitType.Split == card.getSplitType() ? card.getMainPart().getName() + card.getOtherPart().getName() : name,
|
||||
artIdx, base64encode);
|
||||
}
|
||||
|
||||
public String getBackFaceImageFilename() {
|
||||
ICardFace backFace = card.getOtherPart();
|
||||
if (null == backFace) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getImageLocator(card.getOtherPart().getName(), getArtIndex(), false);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.item.InventoryItem#getType()
|
||||
*/
|
||||
/* (non-Javadoc)
|
||||
* @see forge.item.ICardPrinted#getItemType()
|
||||
*/
|
||||
@Override
|
||||
public String getItemType() {
|
||||
return "Card";
|
||||
@@ -152,7 +180,6 @@ public final class CardPrinted implements Comparable<IPaperCard>, InventoryItemF
|
||||
|
||||
/**
|
||||
* Lambda to get rules for selects from list of printed cards.
|
||||
*
|
||||
*/
|
||||
public static final Function<CardPrinted, CardRules> FN_GET_RULES = new Function<CardPrinted, CardRules>() {
|
||||
@Override
|
||||
|
||||
@@ -1,31 +1,33 @@
|
||||
package forge.item;
|
||||
|
||||
import forge.Card;
|
||||
import forge.ImageCache;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.cardfactory.CardFactory;
|
||||
import forge.game.player.Player;
|
||||
|
||||
public class CardToken implements InventoryItemFromSet, IPaperCard {
|
||||
|
||||
private String name;
|
||||
private String edition;
|
||||
private CardEdition edition;
|
||||
private String imageFileName;
|
||||
private CardRules card;
|
||||
|
||||
|
||||
// Constructor is private. All non-foiled instances are stored in CardDb
|
||||
public CardToken(final CardRules c, final String edition0, final String imageFileName) {
|
||||
public CardToken(final CardRules c, CardEdition edition0, final String imageFileName) {
|
||||
this.card = c;
|
||||
this.name = c.getName();
|
||||
this.edition = edition0;
|
||||
this.imageFileName = imageFileName;
|
||||
this.imageFileName = String.format("%s%s%s",
|
||||
null == edition || CardEdition.UNKNOWN == edition ? "" : edition.getCode(),
|
||||
ImageCache.TOKEN_PREFIX, imageFileName);
|
||||
}
|
||||
|
||||
@Override public String getName() { return name; }
|
||||
@Override public String getDescription() { return name; }
|
||||
|
||||
@Override public String getEdition() { return edition; }
|
||||
@Override public String getEdition() { return edition.getCode(); }
|
||||
|
||||
@Override public int getArtIndex() { return 0; } // This might change however
|
||||
@Override public boolean isFoil() { return false; }
|
||||
@@ -44,7 +46,5 @@ public class CardToken implements InventoryItemFromSet, IPaperCard {
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
@Override public boolean isToken() { return true; }
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.Card;
|
||||
@@ -13,10 +15,6 @@ import forge.card.CardRules;
|
||||
import forge.game.player.Player;
|
||||
import forge.util.PredicateString;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public interface IPaperCard {
|
||||
|
||||
/**
|
||||
@@ -24,28 +22,10 @@ public interface IPaperCard {
|
||||
*/
|
||||
public abstract static class Predicates {
|
||||
|
||||
/**
|
||||
* Rarity.
|
||||
*
|
||||
* @param isEqual
|
||||
* the is equal
|
||||
* @param value
|
||||
* the value
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardPrinted> rarity(final boolean isEqual, final CardRarity value) {
|
||||
return new PredicateRarity(value, isEqual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Printed in sets.
|
||||
*
|
||||
* @param value
|
||||
* the value
|
||||
* @param shouldContain
|
||||
* the should contain
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardPrinted> printedInSets(final List<String> value, final boolean shouldContain) {
|
||||
if ((value == null) || value.isEmpty()) {
|
||||
return com.google.common.base.Predicates.alwaysTrue();
|
||||
@@ -53,51 +33,21 @@ public interface IPaperCard {
|
||||
return new PredicateSets(value, shouldContain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Printed in sets.
|
||||
*
|
||||
* @param value
|
||||
* the value
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardPrinted> printedInSets(final String value) {
|
||||
if ((value == null) || value.isEmpty()) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return com.google.common.base.Predicates.alwaysTrue();
|
||||
}
|
||||
return new PredicateSets(Arrays.asList(new String[] { value }), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Name.
|
||||
*
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardPrinted> name(final String what) {
|
||||
return new PredicateName(PredicateString.StringOp.EQUALS_IC, what);
|
||||
}
|
||||
|
||||
/**
|
||||
* Name.
|
||||
*
|
||||
* @param op
|
||||
* the op
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardPrinted> name(final PredicateString.StringOp op, final String what) {
|
||||
return new PredicateName(op, what);
|
||||
}
|
||||
|
||||
/**
|
||||
* Names except.
|
||||
*
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardPrinted> namesExcept(final List<String> what) {
|
||||
return new PredicateNamesExcept(what);
|
||||
}
|
||||
|
||||
@@ -27,10 +27,6 @@ import forge.card.BoosterData;
|
||||
import forge.card.BoosterGenerator;
|
||||
import forge.card.CardEdition;
|
||||
|
||||
/**
|
||||
* TODO Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class TournamentPack extends OpenablePack {
|
||||
|
||||
/** The Constant fnFromSet. */
|
||||
@@ -46,7 +42,6 @@ public class TournamentPack extends OpenablePack {
|
||||
super(name0, boosterData);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final String getImageFilename() {
|
||||
return ImageCache.TOURNAMENTPACK_PREFIX + contents.getEdition();
|
||||
@@ -56,7 +51,6 @@ public class TournamentPack extends OpenablePack {
|
||||
return contents.getCommon() < 30;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final String getItemType() {
|
||||
return !isStarterDeck() ? "Tournament Pack" : "Starter Deck";
|
||||
@@ -68,20 +62,8 @@ public class TournamentPack extends OpenablePack {
|
||||
return gen.getBoosterPack(this.contents);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
/**
|
||||
* Clone.
|
||||
*
|
||||
* @return Object
|
||||
*/
|
||||
@Override
|
||||
public final Object clone() {
|
||||
return new TournamentPack(name, contents);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ public final class NewConstants {
|
||||
public static final String CACHE_FATPACK_PICS_DIR = _PICS_DIR + "fatpacks/";
|
||||
public static final String CACHE_PRECON_PICS_DIR = _PICS_DIR + "precons/";
|
||||
public static final String CACHE_TOURNAMENTPACK_PICS_DIR = _PICS_DIR + "tournamentpacks/";
|
||||
public static final String CACHE_MORPH_IMAGE_FILE = CACHE_TOKEN_PICS_DIR + "morph.jpg";
|
||||
public static final String QUEST_CARD_PRICE_FILE = _DB_DIR + "all-prices.txt";
|
||||
public static final String CACHE_MORPH_IMAGE_FILE = "morph";
|
||||
|
||||
public static final String[] PROFILE_DIRS = {
|
||||
_USER_PREFS_DIR,
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.quest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import forge.Card;
|
||||
import forge.card.CardEdition;
|
||||
@@ -122,6 +123,20 @@ public class QuestUtil {
|
||||
return list;
|
||||
}
|
||||
|
||||
private static String toTokenFilename(final String in) {
|
||||
final StringBuffer out = new StringBuffer();
|
||||
char c;
|
||||
for (int i = 0; i < in.length(); i++) {
|
||||
c = in.charAt(i);
|
||||
if ((c == ' ') || (c == '-') || (c == '_')) {
|
||||
out.append('_');
|
||||
} else if (Character.isLetterOrDigit(c)) {
|
||||
out.append(c);
|
||||
}
|
||||
}
|
||||
return out.toString().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* createToken.
|
||||
@@ -143,8 +158,8 @@ public class QuestUtil {
|
||||
script.add("Types:" + properties[5].replace(';', ' '));
|
||||
script.add("Oracle:"); // tokens don't have texts yet
|
||||
// c.setManaCost(properties[1]);
|
||||
String fileName = properties[1] + "_" + properties[2] + "_" + properties[3] + "_" + properties[4];
|
||||
final CardToken c = new CardToken(CardRulesReader.parseSingleCard(script), CardEdition.UNKNOWN.getCode(), fileName);
|
||||
String fileName = properties[1] + "_" + properties[2] + "_" + properties[3] + "_" + toTokenFilename(properties[4]);
|
||||
final CardToken c = new CardToken(CardRulesReader.parseSingleCard(script), CardEdition.UNKNOWN, fileName);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class QuestPetStats {
|
||||
if (null == petCard) {
|
||||
List<String> cardLines = FileUtil.readFile(new File(NewConstants.CARD_DATA_PETS_DIR, cardFile));
|
||||
CardRules rules = CardRulesReader.parseSingleCard(cardLines);
|
||||
petCard = new CardToken(rules, CardEdition.UNKNOWN.getCode(), picture.replace('_', ' '));
|
||||
petCard = new CardToken(rules, CardEdition.UNKNOWN, picture);
|
||||
}
|
||||
return petCard;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class CopyFiles extends SwingWorker<Void, Integer> {
|
||||
name = this.fileList.get(i).getName();
|
||||
source = this.fileList.get(i).getAbsolutePath();
|
||||
cName = name.substring(0, name.length() - 8);
|
||||
cName = GuiDisplayUtil.cleanString(cName) + ".jpg";
|
||||
//cName = GuiDisplayUtil.cleanString(cName) + ".jpg";
|
||||
final File sourceFile = new File(source);
|
||||
final File reciever = new File(NewConstants.CACHE_CARD_PICS_DIR, cName);
|
||||
reciever.delete();
|
||||
|
||||
Reference in New Issue
Block a user