Prevent missing themes from crashing the game

This commit is contained in:
Lonami Exo 2017-02-11 14:13:01 +01:00
parent 18f864f418
commit af39913cfb
2 changed files with 9 additions and 1 deletions

View file

@ -61,7 +61,11 @@ public class Klooni extends Game {
// Use only one instance for the theme, so anyone using it uses the most up-to-date
Theme.skin = skin; // Not the best idea
theme = Theme.getTheme(prefs.getString("themeName", "default"));
final String themeName = prefs.getString("themeName", "default");
if (Theme.exists(themeName))
theme = Theme.getTheme(themeName);
else
theme = Theme.getTheme("default");
Gdx.input.setCatchBackKey(true); // To show the pause menu
setScreen(new MainMenuScreen(this));

View file

@ -52,6 +52,10 @@ public class Theme {
//region Static methods
public static boolean exists(final String name) {
return Gdx.files.internal("themes/"+name+".theme").exists();
}
// Gets all the available themes on the available on the internal game storage
public static Theme[] getThemes() {
FileHandle[] handles = Gdx.files.internal("themes").list();