mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Assets class
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
package forge.adventure.util;
|
package forge.adventure.util;
|
||||||
|
|
||||||
import com.badlogic.gdx.assets.AssetManager;
|
|
||||||
import com.badlogic.gdx.assets.loaders.resolvers.AbsoluteFileHandleResolver;
|
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||||
import com.badlogic.gdx.utils.Json;
|
import com.badlogic.gdx.utils.Json;
|
||||||
import com.badlogic.gdx.utils.JsonWriter;
|
import com.badlogic.gdx.utils.JsonWriter;
|
||||||
import forge.adventure.data.ConfigData;
|
import forge.adventure.data.ConfigData;
|
||||||
import forge.adventure.data.SettingData;
|
import forge.adventure.data.SettingData;
|
||||||
|
import forge.assets.Assets;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.gui.GuiBase;
|
import forge.gui.GuiBase;
|
||||||
import forge.localinstance.properties.ForgeConstants;
|
import forge.localinstance.properties.ForgeConstants;
|
||||||
@@ -27,7 +26,7 @@ public class Config {
|
|||||||
private static Config currentConfig;
|
private static Config currentConfig;
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
private final HashMap<String, FileHandle> Cache = new HashMap<String, FileHandle>();
|
private final HashMap<String, FileHandle> Cache = new HashMap<String, FileHandle>();
|
||||||
private final AssetManager textureAtlasManager = new AssetManager(new AbsoluteFileHandleResolver());
|
private final Assets atlasAssets = new Assets();
|
||||||
private final ConfigData configData;
|
private final ConfigData configData;
|
||||||
private final String[] adventures;
|
private final String[] adventures;
|
||||||
private SettingData settingsData;
|
private SettingData settingsData;
|
||||||
@@ -122,11 +121,11 @@ public class Config {
|
|||||||
|
|
||||||
public TextureAtlas getAtlas(String spriteAtlas) {
|
public TextureAtlas getAtlas(String spriteAtlas) {
|
||||||
String fileName = getFile(spriteAtlas).path();
|
String fileName = getFile(spriteAtlas).path();
|
||||||
if (!textureAtlasManager.contains(fileName, TextureAtlas.class)) {
|
if (!atlasAssets.manager().contains(fileName, TextureAtlas.class)) {
|
||||||
textureAtlasManager.load(fileName, TextureAtlas.class);
|
atlasAssets.manager().load(fileName, TextureAtlas.class);
|
||||||
textureAtlasManager.finishLoadingAsset(fileName);
|
atlasAssets.manager().finishLoadingAsset(fileName);
|
||||||
}
|
}
|
||||||
return textureAtlasManager.get(fileName);
|
return atlasAssets.manager().get(fileName);
|
||||||
}
|
}
|
||||||
public SettingData getSettingData()
|
public SettingData getSettingData()
|
||||||
{
|
{
|
||||||
@@ -145,6 +144,6 @@ public class Config {
|
|||||||
|
|
||||||
}
|
}
|
||||||
public void disposeTextureAtlasManager() {
|
public void disposeTextureAtlasManager() {
|
||||||
textureAtlasManager.dispose();
|
atlasAssets.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
forge-gui-mobile/src/forge/assets/Assets.java
Normal file
16
forge-gui-mobile/src/forge/assets/Assets.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package forge.assets;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.assets.AssetManager;
|
||||||
|
import com.badlogic.gdx.assets.loaders.resolvers.AbsoluteFileHandleResolver;
|
||||||
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
|
|
||||||
|
public class Assets implements Disposable {
|
||||||
|
public AssetManager manager = new AssetManager(new AbsoluteFileHandleResolver());
|
||||||
|
public AssetManager manager() {
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
manager.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,9 +20,7 @@ package forge.assets;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.badlogic.gdx.assets.AssetManager;
|
import com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter;
|
||||||
import com.badlogic.gdx.assets.loaders.TextureLoader;
|
|
||||||
import com.badlogic.gdx.assets.loaders.resolvers.AbsoluteFileHandleResolver;
|
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
import com.badlogic.gdx.graphics.TextureData;
|
import com.badlogic.gdx.graphics.TextureData;
|
||||||
@@ -73,10 +71,10 @@ public class ImageCache {
|
|||||||
private static final ObjectSet<String> missingIconKeys = new ObjectSet<>();
|
private static final ObjectSet<String> missingIconKeys = new ObjectSet<>();
|
||||||
private static List<String> borderlessCardlistKey = FileUtil.readFile(ForgeConstants.BORDERLESS_CARD_LIST_FILE);
|
private static List<String> borderlessCardlistKey = FileUtil.readFile(ForgeConstants.BORDERLESS_CARD_LIST_FILE);
|
||||||
static int maxCardCapacity = 400; //default card capacity
|
static int maxCardCapacity = 400; //default card capacity
|
||||||
static AssetManager cardTextureManager = new AssetManager(new AbsoluteFileHandleResolver());
|
static Assets cardAssets = new Assets();
|
||||||
static AssetManager otherTextureManager = new AssetManager(new AbsoluteFileHandleResolver());
|
static Assets otherAssets = new Assets();
|
||||||
static TextureLoader.TextureParameter defaultParameter = new TextureLoader.TextureParameter();
|
static TextureParameter defaultParameter = new TextureParameter();
|
||||||
static TextureLoader.TextureParameter filtered = new TextureLoader.TextureParameter();
|
static TextureParameter filtered = new TextureParameter();
|
||||||
public static void initCache(int capacity) {
|
public static void initCache(int capacity) {
|
||||||
//init filter
|
//init filter
|
||||||
filtered.genMipMaps = true;
|
filtered.genMipMaps = true;
|
||||||
@@ -117,11 +115,11 @@ public class ImageCache {
|
|||||||
}
|
}
|
||||||
public static void disposeTextures(){
|
public static void disposeTextures(){
|
||||||
CardRenderer.clearcardArtCache();
|
CardRenderer.clearcardArtCache();
|
||||||
cardTextureManager.clear();
|
cardAssets.manager().clear();
|
||||||
}
|
}
|
||||||
public static void disposeTextureManager() {
|
public static void disposeTextureManager() {
|
||||||
cardTextureManager.dispose();
|
cardAssets.dispose();
|
||||||
otherTextureManager.dispose();
|
otherAssets.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Texture getImage(InventoryItem ii) {
|
public static Texture getImage(InventoryItem ii) {
|
||||||
@@ -262,26 +260,26 @@ public class ImageCache {
|
|||||||
return null;
|
return null;
|
||||||
if (!otherCache && Forge.enableUIMask.equals("Full") && isBorderless(imageKey))
|
if (!otherCache && Forge.enableUIMask.equals("Full") && isBorderless(imageKey))
|
||||||
return generatedCards.get(imageKey);
|
return generatedCards.get(imageKey);
|
||||||
return otherCache ? otherTextureManager.get(file.getPath(), Texture.class, false) : cardTextureManager.get(file.getPath(), Texture.class, false);
|
return otherCache ? otherAssets.manager().get(file.getPath(), Texture.class, false) : cardAssets.manager().get(file.getPath(), Texture.class, false);
|
||||||
}
|
}
|
||||||
static Texture loadAsset(String imageKey, File file, boolean otherCache) {
|
static Texture loadAsset(String imageKey, File file, boolean otherCache) {
|
||||||
if (file == null)
|
if (file == null)
|
||||||
return null;
|
return null;
|
||||||
if (!otherCache && cardTextureManager.getLoadedAssets() > maxCardCapacity) {
|
if (!otherCache && cardAssets.manager().getLoadedAssets() > maxCardCapacity) {
|
||||||
//when maxCardCapacity is reached, clear to refresh
|
//when maxCardCapacity is reached, clear to refresh
|
||||||
cardTextureManager.clear();
|
cardAssets.manager().clear();
|
||||||
CardRenderer.clearcardArtCache();
|
CardRenderer.clearcardArtCache();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String fileName = file.getPath();
|
String fileName = file.getPath();
|
||||||
if (otherCache) {
|
if (otherCache) {
|
||||||
otherTextureManager.load(fileName, Texture.class, Forge.isTextureFilteringEnabled() ? filtered : defaultParameter);
|
otherAssets.manager().load(fileName, Texture.class, Forge.isTextureFilteringEnabled() ? filtered : defaultParameter);
|
||||||
otherTextureManager.finishLoadingAsset(fileName);
|
otherAssets.manager().finishLoadingAsset(fileName);
|
||||||
return otherTextureManager.get(fileName, Texture.class, false);
|
return otherAssets.manager().get(fileName, Texture.class, false);
|
||||||
} else {
|
} else {
|
||||||
cardTextureManager.load(fileName, Texture.class, Forge.isTextureFilteringEnabled() ? filtered : defaultParameter);
|
cardAssets.manager().load(fileName, Texture.class, Forge.isTextureFilteringEnabled() ? filtered : defaultParameter);
|
||||||
cardTextureManager.finishLoadingAsset(fileName);
|
cardAssets.manager().finishLoadingAsset(fileName);
|
||||||
Texture t = cardTextureManager.get(fileName, Texture.class, false);
|
Texture t = cardAssets.manager().get(fileName, Texture.class, false);
|
||||||
if (Forge.enableUIMask.equals("Full")) {
|
if (Forge.enableUIMask.equals("Full")) {
|
||||||
boolean borderless = isBorderless(imageKey);
|
boolean borderless = isBorderless(imageKey);
|
||||||
updateBorders(t.toString(), borderless ? Pair.of(Color.valueOf("#171717").toString(), false): isCloserToWhite(getpixelColor(t)));
|
updateBorders(t.toString(), borderless ? Pair.of(Color.valueOf("#171717").toString(), false): isCloserToWhite(getpixelColor(t)));
|
||||||
@@ -390,9 +388,7 @@ public class ImageCache {
|
|||||||
if (t == null || fh == null)
|
if (t == null || fh == null)
|
||||||
return t;
|
return t;
|
||||||
final Texture[] n = new Texture[1];
|
final Texture[] n = new Texture[1];
|
||||||
FThreads.invokeInEdtNowOrLater(new Runnable() {
|
FThreads.invokeInEdtNowOrLater(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Pixmap pImage = new Pixmap(fh);
|
Pixmap pImage = new Pixmap(fh);
|
||||||
int w = pImage.getWidth();
|
int w = pImage.getWidth();
|
||||||
int h = pImage.getHeight();
|
int h = pImage.getHeight();
|
||||||
@@ -401,7 +397,7 @@ public class ImageCache {
|
|||||||
drawPixelstoMask(pImage, pMask);
|
drawPixelstoMask(pImage, pMask);
|
||||||
TextureData textureData = new PixmapTextureData(
|
TextureData textureData = new PixmapTextureData(
|
||||||
pMask, //pixmap to use
|
pMask, //pixmap to use
|
||||||
Pixmap.Format.RGBA8888,
|
Format.RGBA8888,
|
||||||
textureFilter, //use mipmaps
|
textureFilter, //use mipmaps
|
||||||
false, true);
|
false, true);
|
||||||
n[0] = new Texture(textureData);
|
n[0] = new Texture(textureData);
|
||||||
@@ -409,7 +405,6 @@ public class ImageCache {
|
|||||||
n[0].setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear);
|
n[0].setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear);
|
||||||
pImage.dispose();
|
pImage.dispose();
|
||||||
pMask.dispose();
|
pMask.dispose();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return n[0];
|
return n[0];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user