update booster image list and refine image file searching algorithm

This commit is contained in:
myk
2013-03-08 10:24:17 +00:00
parent c1bf5c18b1
commit 86110ccf5a
2 changed files with 96 additions and 81 deletions

View File

@@ -13,7 +13,8 @@ import forge.properties.NewConstants;
final class ImageLoader extends CacheLoader<String, BufferedImage> {
// image file extensions for various formats in order of likelihood
private static final String[] _FILE_EXTENSIONS = { ".jpg", ".png" };
// the last, empty, string is for keys that come in with an extension already in place
private static final String[] _FILE_EXTENSIONS = { ".jpg", ".png", "" };
@Override
public BufferedImage load(String key) {
@@ -41,9 +42,17 @@ final class ImageLoader extends CacheLoader<String, BufferedImage> {
BufferedImage ret = _findFile(key, path, filename);
// try without set prefix (if any)
if (null == ret && filename.contains("/")) {
ret = _findFile(key, path, filename.substring(filename.indexOf('/') + 1));
// 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);
}
if (null == ret) {
@@ -66,8 +75,9 @@ final class ImageLoader extends CacheLoader<String, BufferedImage> {
private static BufferedImage _findFile(String key, String path, String filename) {
for (String ext : _FILE_EXTENSIONS) {
File file = new File(path, filename + ext);
//System.out.println(String.format("Searching for %s at: %s", key, file.getAbsolutePath()));
if (file.exists()) {
System.out.println(String.format("Found %s at: %s", key, file.getAbsolutePath()));
//System.out.println(String.format("Found %s at: %s", key, file.getAbsolutePath()));
return getImage(file);
}
}