mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Add support for checking for assets when opening android app
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
package forge.screens;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.badlogic.gdx.Application.ApplicationType;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
|
||||
@@ -7,10 +12,14 @@ import forge.Forge.Graphics;
|
||||
import forge.assets.FSkin;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.assets.FSkinTexture;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.toolbox.FContainer;
|
||||
import forge.toolbox.FProgressBar;
|
||||
import forge.util.BuildInfo;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
public class SplashScreen extends FContainer {
|
||||
private TextureRegion background;
|
||||
@@ -21,6 +30,8 @@ public class SplashScreen extends FContainer {
|
||||
progressBar = new FProgressBar();
|
||||
progressBar.setDescription("Welcome to Forge");
|
||||
|
||||
checkForAssets();
|
||||
|
||||
final ForgePreferences prefs = new ForgePreferences();
|
||||
FSkin.loadLight(prefs.getPref(FPref.UI_SKIN), this);
|
||||
}
|
||||
@@ -75,4 +86,28 @@ public class SplashScreen extends FContainer {
|
||||
progressBar.setBounds(x + padding, y, w - 2 * padding, pbHeight);
|
||||
g.draw(progressBar);
|
||||
}
|
||||
|
||||
//if not forge-gui-mobile-dev, check whether assets are up to date
|
||||
private void checkForAssets() {
|
||||
if (Gdx.app.getType() == ApplicationType.Desktop) { return; }
|
||||
|
||||
String versionStr = BuildInfo.getVersionString();
|
||||
File versionFile = new File(ForgeConstants.ASSETS_DIR + "version.txt");
|
||||
if (!versionFile.exists()) {
|
||||
try {
|
||||
versionFile.createNewFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Gdx.app.exit(); //can't continue if this fails
|
||||
}
|
||||
}
|
||||
else if (versionStr.equals(TextUtil.join(FileUtil.readFile(versionFile), "\n"))) {
|
||||
return; //if version matches what had been previously saved, no need to download assets
|
||||
}
|
||||
|
||||
//save version string to file once assets finish downloading
|
||||
//so they don't need to be re-downloaded until you upgrade again
|
||||
FileUtil.writeFile(versionFile, versionStr);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user