mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
[Mobile] add OtherImageLoader for otherCache
This commit is contained in:
@@ -83,7 +83,7 @@ public class ImageCache {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.build(new ImageLoader());
|
.build(new ImageLoader());
|
||||||
private static final LoadingCache<String, Texture> otherCache = CacheBuilder.newBuilder().build(new ImageLoader());
|
private static final LoadingCache<String, Texture> otherCache = CacheBuilder.newBuilder().build(new OtherImageLoader());
|
||||||
public static final Texture defaultImage;
|
public static final Texture defaultImage;
|
||||||
public static FImage BlackBorder = FSkinImage.IMG_BORDER_BLACK;
|
public static FImage BlackBorder = FSkinImage.IMG_BORDER_BLACK;
|
||||||
public static FImage WhiteBorder = FSkinImage.IMG_BORDER_WHITE;
|
public static FImage WhiteBorder = FSkinImage.IMG_BORDER_WHITE;
|
||||||
@@ -119,10 +119,11 @@ public class ImageCache {
|
|||||||
|
|
||||||
public static Texture getImage(InventoryItem ii) {
|
public static Texture getImage(InventoryItem ii) {
|
||||||
String imageKey = ii.getImageKey(false);
|
String imageKey = ii.getImageKey(false);
|
||||||
boolean isCardImage = imageKey.startsWith(ImageKeys.CARD_PREFIX) || imageKey.startsWith(ImageKeys.TOKEN_PREFIX);
|
if (imageKey != null) {
|
||||||
if (isCardImage)
|
if(imageKey.startsWith(ImageKeys.CARD_PREFIX) || imageKey.startsWith(ImageKeys.TOKEN_PREFIX))
|
||||||
getImage(ii.getImageKey(false), true);
|
return getImage(ii.getImageKey(false), true, false);
|
||||||
return getOtherImages(ii.getImageKey(false));
|
}
|
||||||
|
return getImage(ii.getImageKey(false), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,7 +133,7 @@ public class ImageCache {
|
|||||||
public static FImage getIcon(IHasIcon ihi) {
|
public static FImage getIcon(IHasIcon ihi) {
|
||||||
String imageKey = ihi.getIconImageKey();
|
String imageKey = ihi.getIconImageKey();
|
||||||
final Texture icon;
|
final Texture icon;
|
||||||
if (missingIconKeys.contains(imageKey) || (icon = getOtherImages(ihi.getIconImageKey())) == null) {
|
if (missingIconKeys.contains(imageKey) || (icon = getImage(ihi.getIconImageKey(), false, true)) == null) {
|
||||||
missingIconKeys.add(imageKey);
|
missingIconKeys.add(imageKey);
|
||||||
return FSkinImage.UNKNOWN;
|
return FSkinImage.UNKNOWN;
|
||||||
}
|
}
|
||||||
@@ -181,6 +182,9 @@ public class ImageCache {
|
|||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public static Texture getImage(String imageKey, boolean useDefaultIfNotFound) {
|
public static Texture getImage(String imageKey, boolean useDefaultIfNotFound) {
|
||||||
|
return getImage(imageKey, useDefaultIfNotFound, false);
|
||||||
|
}
|
||||||
|
public static Texture getImage(String imageKey, boolean useDefaultIfNotFound, boolean useOtherCache) {
|
||||||
if (StringUtils.isEmpty(imageKey)) {
|
if (StringUtils.isEmpty(imageKey)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -199,7 +203,7 @@ public class ImageCache {
|
|||||||
Texture image;
|
Texture image;
|
||||||
if (useDefaultIfNotFound) {
|
if (useDefaultIfNotFound) {
|
||||||
// Load from file and add to cache if not found in cache initially.
|
// Load from file and add to cache if not found in cache initially.
|
||||||
image = cache.getIfPresent(imageKey);
|
image = useOtherCache ? otherCache.getIfPresent(imageKey) : cache.getIfPresent(imageKey);
|
||||||
|
|
||||||
if (image != null) { return image; }
|
if (image != null) { return image; }
|
||||||
|
|
||||||
@@ -214,7 +218,7 @@ public class ImageCache {
|
|||||||
imageLoaded = true;
|
imageLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try { image = cache.get(imageKey); }
|
try { image = useOtherCache ? otherCache.get(imageKey) : cache.get(imageKey); }
|
||||||
catch (final Exception ex) {
|
catch (final Exception ex) {
|
||||||
image = null;
|
image = null;
|
||||||
}
|
}
|
||||||
@@ -224,6 +228,9 @@ public class ImageCache {
|
|||||||
if (image == null) {
|
if (image == null) {
|
||||||
if (useDefaultIfNotFound) {
|
if (useDefaultIfNotFound) {
|
||||||
image = defaultImage;
|
image = defaultImage;
|
||||||
|
if (useOtherCache)
|
||||||
|
otherCache.put(imageKey, defaultImage);
|
||||||
|
else
|
||||||
cache.put(imageKey, defaultImage);
|
cache.put(imageKey, defaultImage);
|
||||||
if (imageBorder.get(image.toString()) == null)
|
if (imageBorder.get(image.toString()) == null)
|
||||||
imageBorder.put(image.toString(), Pair.of(Color.valueOf("#171717").toString(), false)); //black border
|
imageBorder.put(image.toString(), Pair.of(Color.valueOf("#171717").toString(), false)); //black border
|
||||||
@@ -231,18 +238,6 @@ public class ImageCache {
|
|||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
public static Texture getOtherImages(String imageKey) {
|
|
||||||
if (StringUtils.isEmpty(imageKey)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Texture image;
|
|
||||||
|
|
||||||
try { image = otherCache.get(imageKey); }
|
|
||||||
catch (final Exception ex) {
|
|
||||||
image = null;
|
|
||||||
}
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
public static void preloadCache(Iterable<String> keys) {
|
public static void preloadCache(Iterable<String> keys) {
|
||||||
if (FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.UI_DISABLE_CARD_IMAGES))
|
if (FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.UI_DISABLE_CARD_IMAGES))
|
||||||
return;
|
return;
|
||||||
|
|||||||
35
forge-gui-mobile/src/forge/assets/OtherImageLoader.java
Normal file
35
forge-gui-mobile/src/forge/assets/OtherImageLoader.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package forge.assets;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
|
||||||
|
import forge.Forge;
|
||||||
|
import forge.ImageKeys;
|
||||||
|
|
||||||
|
final class OtherImageLoader extends CacheLoader<String, Texture> {
|
||||||
|
@Override
|
||||||
|
public Texture load(String key) {
|
||||||
|
File file = ImageKeys.getImageFile(key);
|
||||||
|
if (file != null) {
|
||||||
|
FileHandle fh = new FileHandle(file);
|
||||||
|
try {
|
||||||
|
if (Forge.isTextureFilteringEnabled()) {
|
||||||
|
Texture t = new Texture(fh, true);
|
||||||
|
t.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear);
|
||||||
|
return t;
|
||||||
|
} else {
|
||||||
|
return new Texture(fh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Forge.log("Could not read image file " + fh.path() + "\n\nException:\n" + ex.toString());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user