Added forge.profile.properties setting to specify custom names for edition folders in pics directory

This commit is contained in:
Maxmtg
2013-03-17 12:38:15 +00:00
parent 6d04c7d1f3
commit 476ad7af91
6 changed files with 34 additions and 6 deletions

View File

@@ -226,11 +226,18 @@ public class ImageCache {
}
if (includeSet) {
return String.format("%s/%s", Singletons.getModel().getEditions().getCode2ByCode(cp.getEdition()), fname);
String editionAliased = isDownloadUrl ? Singletons.getModel().getEditions().getCode2ByCode(edition) : getSetFolder(edition);
return String.format("%s/%s", editionAliased, fname);
} else {
return fname;
}
}
public static String getSetFolder(String edition) {
return !NewConstants.CACHE_CARD_PICS_SUBDIR.containsKey(edition)
? Singletons.getModel().getEditions().getCode2ByCode(edition) // by default 2-letter codes from MWS are used
: NewConstants.CACHE_CARD_PICS_SUBDIR.get(edition); // may use custom paths though
}
public static String getImageName(CardPrinted cp) {
return CardSplitType.Split != cp.getRules().getSplitType() ? cp.getName() : cp.getRules().getMainPart().getName() + cp.getRules().getOtherPart().getName();

View File

@@ -51,9 +51,12 @@ final class ImageLoader extends CacheLoader<String, BufferedImage> {
BufferedImage ret = _findFile(key, path, filename);
// some S00/S2K cards are really part of 6ED/6E
if (null == ret && filename.startsWith("S00") ) {
ret = _findFile(key, path, filename.replace("S00", "6ED"));
// some S00 cards are really part of 6ED
if (null == ret ) {
String s2kAlias = ImageCache.getSetFolder("S00");
if ( filename.startsWith(s2kAlias) ) {
ret = _findFile(key, path, filename.replace(s2kAlias, ImageCache.getSetFolder("6ED")));
}
}
// try without set prefix

View File

@@ -227,6 +227,8 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
System.err.println(String.format("Ignoring unknown type in set definitions: name: %s; type: %s", name, type));
}
}
// if( !code2.equals(code) ) System.out.printf("%s->%s|", code, code);
return new CardEdition(index, code2, code, enumType, name, alias, borderWhite);
}

View File

@@ -50,8 +50,7 @@ public final class CardPrinted implements Comparable<IPaperCard>, InventoryItemF
private final boolean foiled;
// Calculated fields are below:
private final transient CardRarity rarity; // rarity is given in ctor when
// set is assigned
private final transient CardRarity rarity; // rarity is given in ctor when set is assigned
@Override
public String getName() {

View File

@@ -20,11 +20,14 @@ package forge.properties;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import forge.util.FileSection;
/**
* Determines the user data and cache dirs, first looking at the specified file for overrides
* then falling back to platform-specific defaults. Resulting dir strings are guaranteed to end in a slash
@@ -34,10 +37,12 @@ public class ForgeProfileProperties {
public final String userDir;
public final String cacheDir;
public final String cardPicsDir;
public final Map<String, String> cardPicsSubDir;
private static final String _USER_DIR_KEY = "userDir";
private static final String _CACHE_DIR_KEY = "cacheDir";
private static final String _CARD_PICS_DIR_KEY = "cardPicsDir";
private static final String _CARD_PICS_SUB_DIRS_KEY = "cardPicsSubDirs";
public ForgeProfileProperties(String filename) {
Properties props = new Properties();
@@ -54,6 +59,13 @@ public class ForgeProfileProperties {
userDir = _getDir(props, _USER_DIR_KEY, defaults.getLeft());
cacheDir = _getDir(props, _CACHE_DIR_KEY, defaults.getRight());
cardPicsDir = _getDir(props, _CARD_PICS_DIR_KEY, cacheDir + "pics/cards/");
cardPicsSubDir = _getMap(props, _CARD_PICS_SUB_DIRS_KEY);
}
private Map<String,String> _getMap(Properties props, String propertyKey) {
String strMap = props.getProperty(propertyKey, "").trim();
return FileSection.parseToMap(strMap, "->", "|");
}
private static String _getDir(Properties props, String propertyKey, String defaultVal) {

View File

@@ -17,6 +17,9 @@
*/
package forge.properties;
import java.util.Collections;
import java.util.Map;
public final class NewConstants {
public static final String PROFILE_FILE = "forge.profile.properties";
public static final String PROFILE_TEMPLATE_FILE = PROFILE_FILE + ".example";
@@ -50,11 +53,13 @@ public final class NewConstants {
public static final String USER_DIR;
public static final String CACHE_DIR;
public static final String CACHE_CARD_PICS_DIR;
public static final Map<String, String> CACHE_CARD_PICS_SUBDIR;
static {
ForgeProfileProperties profileProps = new ForgeProfileProperties(PROFILE_FILE);
USER_DIR = profileProps.userDir;
CACHE_DIR = profileProps.cacheDir;
CACHE_CARD_PICS_DIR = profileProps.cardPicsDir;
CACHE_CARD_PICS_SUBDIR = Collections.unmodifiableMap(profileProps.cardPicsSubDir);
}
// data that is only in the profile dirs