Prevent missing themes from crashing the game
This commit is contained in:
parent
18f864f418
commit
af39913cfb
2 changed files with 9 additions and 1 deletions
|
@ -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));
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue