Prevent caching more than one font regardless of switching themes

This commit is contained in:
drdev
2014-06-14 14:46:11 +00:00
parent c2f1aae631
commit 29a771dd44
4 changed files with 16 additions and 21 deletions

View File

@@ -53,7 +53,7 @@ public class AssetsDownloader {
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
}

View File

@@ -31,7 +31,6 @@ public class FSkin {
private static ArrayList<String> allSkins;
private static FileHandle preferredDir;
private static FileHandle preferredFontDir;
private static String preferredName;
private static boolean loaded = false;
@@ -91,7 +90,6 @@ public class FSkin {
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
preferredDir = Gdx.files.internal("fallback_skin");
preferredFontDir = null;
}
else {
if (splashScreen != null) {
@@ -107,9 +105,8 @@ public class FSkin {
// Non-default (preferred) skin name and dir.
preferredDir = Gdx.files.absolute(ForgeConstants.SKINS_DIR + preferredName);
preferredFontDir = Gdx.files.absolute(ForgeConstants.CACHE_DIR + "fonts/" + preferredName);
if (!preferredFontDir.exists() || !preferredFontDir.isDirectory()) {
preferredFontDir.mkdirs();
if (!preferredDir.exists() || !preferredDir.isDirectory()) {
preferredDir.mkdirs();
}
}
@@ -287,18 +284,8 @@ public class FSkin {
return Gdx.files.absolute(ForgeConstants.DEFAULT_SKINS_DIR + filename);
}
/**
* Gets a FileHandle for the directory where fonts should be cached
*/
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;
public static FileHandle getSkinDir() {
return preferredDir;
}
/**

View File

@@ -3,6 +3,7 @@ package forge.assets;
import java.util.HashMap;
import java.util.Map;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
@@ -19,6 +20,8 @@ import com.badlogic.gdx.graphics.glutils.PixmapTextureData;
import com.badlogic.gdx.utils.Array;
import forge.FThreads;
import forge.properties.ForgeConstants;
import forge.util.FileUtil;
import forge.util.Utils;
public class FSkinFont {
@@ -28,6 +31,10 @@ public class FSkinFont {
private static final String TTF_FILE = "font1.ttf";
private static final Map<Integer, FSkinFont> fonts = new HashMap<Integer, FSkinFont>();
static {
FileUtil.ensureDirectoryExists(ForgeConstants.FONTS_DIR);
}
public static FSkinFont get(final int unscaledSize) {
return _get((int)Utils.scaleMax(unscaledSize));
}
@@ -145,7 +152,7 @@ public class FSkinFont {
}
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()) {
final BitmapFontData data = new BitmapFontData(fontFile, false);
FThreads.invokeInEdtNowOrLater(new Runnable() {
@@ -203,9 +210,9 @@ public class FSkinFont {
font = new BitmapFont(fontData, textureRegions, true);
//create .fnt and .png files for font
FileHandle pixmapDir = FSkin.getFontDir();
FileHandle pixmapDir = Gdx.files.absolute(ForgeConstants.FONTS_DIR);
if (pixmapDir != null) {
FileHandle fontFile = FSkin.getFontFile(fontName + ".fnt");
FileHandle fontFile = pixmapDir.child(fontName + ".fnt");
BitmapFontWriter.setOutputFormat(BitmapFontWriter.OutputFormat.Text);
String[] pageRefs = BitmapFontWriter.writePixmaps(packer.getPages(), pixmapDir, fontName);

View File

@@ -126,6 +126,7 @@ public final class ForgeConstants {
// data that is only in the cached dir
private static final String PICS_DIR = CACHE_DIR + "pics/";
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_ICON_PICS_DIR = PICS_DIR + "icons/";
public static final String CACHE_SYMBOLS_DIR = PICS_DIR + "symbols/";