mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Prevent caching more than one font regardless of switching themes
This commit is contained in:
@@ -53,7 +53,7 @@ public class AssetsDownloader {
|
|||||||
Gdx.app.exit(); //can't continue if this fails
|
Gdx.app.exit(); //can't continue if this fails
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Forge.CURRENT_VERSION.equals(FileUtil.readFileToString(versionFile)) && FSkin.getFontDir() != null) {
|
else if (Forge.CURRENT_VERSION.equals(FileUtil.readFileToString(versionFile)) && FSkin.getSkinDir() != null) {
|
||||||
return; //if version matches what had been previously saved and FSkin isn't requesting assets download, no need to download assets
|
return; //if version matches what had been previously saved and FSkin isn't requesting assets download, no need to download assets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ public class FSkin {
|
|||||||
|
|
||||||
private static ArrayList<String> allSkins;
|
private static ArrayList<String> allSkins;
|
||||||
private static FileHandle preferredDir;
|
private static FileHandle preferredDir;
|
||||||
private static FileHandle preferredFontDir;
|
|
||||||
private static String preferredName;
|
private static String preferredName;
|
||||||
private static boolean loaded = false;
|
private static boolean loaded = false;
|
||||||
|
|
||||||
@@ -91,7 +90,6 @@ public class FSkin {
|
|||||||
if (!dir.exists() || !dir.isDirectory()) {
|
if (!dir.exists() || !dir.isDirectory()) {
|
||||||
//if skins directory doesn't exist, point to internal assets/skin directory instead for the sake of the splash screen
|
//if skins directory doesn't exist, point to internal assets/skin directory instead for the sake of the splash screen
|
||||||
preferredDir = Gdx.files.internal("fallback_skin");
|
preferredDir = Gdx.files.internal("fallback_skin");
|
||||||
preferredFontDir = null;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (splashScreen != null) {
|
if (splashScreen != null) {
|
||||||
@@ -107,9 +105,8 @@ public class FSkin {
|
|||||||
|
|
||||||
// Non-default (preferred) skin name and dir.
|
// Non-default (preferred) skin name and dir.
|
||||||
preferredDir = Gdx.files.absolute(ForgeConstants.SKINS_DIR + preferredName);
|
preferredDir = Gdx.files.absolute(ForgeConstants.SKINS_DIR + preferredName);
|
||||||
preferredFontDir = Gdx.files.absolute(ForgeConstants.CACHE_DIR + "fonts/" + preferredName);
|
if (!preferredDir.exists() || !preferredDir.isDirectory()) {
|
||||||
if (!preferredFontDir.exists() || !preferredFontDir.isDirectory()) {
|
preferredDir.mkdirs();
|
||||||
preferredFontDir.mkdirs();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,18 +284,8 @@ public class FSkin {
|
|||||||
return Gdx.files.absolute(ForgeConstants.DEFAULT_SKINS_DIR + filename);
|
return Gdx.files.absolute(ForgeConstants.DEFAULT_SKINS_DIR + filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static FileHandle getSkinDir() {
|
||||||
* Gets a FileHandle for the directory where fonts should be cached
|
return preferredDir;
|
||||||
*/
|
|
||||||
public static FileHandle getFontDir() {
|
|
||||||
return preferredFontDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a FileHandle for a file within the directory where fonts should be cached
|
|
||||||
*/
|
|
||||||
public static FileHandle getFontFile(String filename) {
|
|
||||||
return preferredFontDir != null ? preferredFontDir.child(filename) : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package forge.assets;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
@@ -19,6 +20,8 @@ import com.badlogic.gdx.graphics.glutils.PixmapTextureData;
|
|||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
|
||||||
import forge.FThreads;
|
import forge.FThreads;
|
||||||
|
import forge.properties.ForgeConstants;
|
||||||
|
import forge.util.FileUtil;
|
||||||
import forge.util.Utils;
|
import forge.util.Utils;
|
||||||
|
|
||||||
public class FSkinFont {
|
public class FSkinFont {
|
||||||
@@ -28,6 +31,10 @@ public class FSkinFont {
|
|||||||
private static final String TTF_FILE = "font1.ttf";
|
private static final String TTF_FILE = "font1.ttf";
|
||||||
private static final Map<Integer, FSkinFont> fonts = new HashMap<Integer, FSkinFont>();
|
private static final Map<Integer, FSkinFont> fonts = new HashMap<Integer, FSkinFont>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
FileUtil.ensureDirectoryExists(ForgeConstants.FONTS_DIR);
|
||||||
|
}
|
||||||
|
|
||||||
public static FSkinFont get(final int unscaledSize) {
|
public static FSkinFont get(final int unscaledSize) {
|
||||||
return _get((int)Utils.scaleMax(unscaledSize));
|
return _get((int)Utils.scaleMax(unscaledSize));
|
||||||
}
|
}
|
||||||
@@ -145,7 +152,7 @@ public class FSkinFont {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String fontName = "f" + fontSize;
|
String fontName = "f" + fontSize;
|
||||||
FileHandle fontFile = FSkin.getFontFile(fontName + ".fnt");
|
FileHandle fontFile = Gdx.files.absolute(ForgeConstants.FONTS_DIR + fontName + ".fnt");
|
||||||
if (fontFile != null && fontFile.exists()) {
|
if (fontFile != null && fontFile.exists()) {
|
||||||
final BitmapFontData data = new BitmapFontData(fontFile, false);
|
final BitmapFontData data = new BitmapFontData(fontFile, false);
|
||||||
FThreads.invokeInEdtNowOrLater(new Runnable() {
|
FThreads.invokeInEdtNowOrLater(new Runnable() {
|
||||||
@@ -203,9 +210,9 @@ public class FSkinFont {
|
|||||||
font = new BitmapFont(fontData, textureRegions, true);
|
font = new BitmapFont(fontData, textureRegions, true);
|
||||||
|
|
||||||
//create .fnt and .png files for font
|
//create .fnt and .png files for font
|
||||||
FileHandle pixmapDir = FSkin.getFontDir();
|
FileHandle pixmapDir = Gdx.files.absolute(ForgeConstants.FONTS_DIR);
|
||||||
if (pixmapDir != null) {
|
if (pixmapDir != null) {
|
||||||
FileHandle fontFile = FSkin.getFontFile(fontName + ".fnt");
|
FileHandle fontFile = pixmapDir.child(fontName + ".fnt");
|
||||||
BitmapFontWriter.setOutputFormat(BitmapFontWriter.OutputFormat.Text);
|
BitmapFontWriter.setOutputFormat(BitmapFontWriter.OutputFormat.Text);
|
||||||
|
|
||||||
String[] pageRefs = BitmapFontWriter.writePixmaps(packer.getPages(), pixmapDir, fontName);
|
String[] pageRefs = BitmapFontWriter.writePixmaps(packer.getPages(), pixmapDir, fontName);
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ public final class ForgeConstants {
|
|||||||
// data that is only in the cached dir
|
// data that is only in the cached dir
|
||||||
private static final String PICS_DIR = CACHE_DIR + "pics/";
|
private static final String PICS_DIR = CACHE_DIR + "pics/";
|
||||||
public static final String DB_DIR = CACHE_DIR + "db/";
|
public static final String DB_DIR = CACHE_DIR + "db/";
|
||||||
|
public static final String FONTS_DIR = CACHE_DIR + "fonts/";
|
||||||
public static final String CACHE_TOKEN_PICS_DIR = PICS_DIR + "tokens/";
|
public static final String CACHE_TOKEN_PICS_DIR = PICS_DIR + "tokens/";
|
||||||
public static final String CACHE_ICON_PICS_DIR = PICS_DIR + "icons/";
|
public static final String CACHE_ICON_PICS_DIR = PICS_DIR + "icons/";
|
||||||
public static final String CACHE_SYMBOLS_DIR = PICS_DIR + "symbols/";
|
public static final String CACHE_SYMBOLS_DIR = PICS_DIR + "symbols/";
|
||||||
|
|||||||
Reference in New Issue
Block a user