DEADSOFTWARE

Add desktop debug option
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / CaveGame.java
index 031b6135ae3fb58153427d52e76814d598898124..42533236e2794d906b6392480ecbd593f4dc5c25 100644 (file)
@@ -1,30 +1,41 @@
 package ru.deadsoftware.cavedroid;
 
+import com.badlogic.gdx.Application;
 import com.badlogic.gdx.Game;
 import com.badlogic.gdx.Gdx;
 import ru.deadsoftware.cavedroid.game.GameItems;
 import ru.deadsoftware.cavedroid.game.GameScreen;
 import ru.deadsoftware.cavedroid.misc.Assets;
+import ru.deadsoftware.cavedroid.misc.utils.AssetLoader;
+
+import javax.annotation.Nullable;
 
 public class CaveGame extends Game {
 
     private static final String TAG = "CaveGame";
 
-    public static final String VERSION = "alpha 0.4";
+    public static final String VERSION = "alpha 0.5.2";
 
     private final MainConfig mMainConfig;
     private final MainComponent mMainComponent;
+    private final AssetLoader mAssetLoader;
 
     private final String mGameFolder;
     private final boolean mTouch;
     private boolean mDebug;
 
-    public CaveGame(String gameFolder, boolean touch) {
+    @Nullable
+    private final String mAssetsPackPath;
+
+    public CaveGame(String gameFolder, boolean touch, @Nullable String assetsPackPath) {
         mGameFolder = gameFolder;
         mTouch = touch;
+        mAssetsPackPath = assetsPackPath;
 
         mMainComponent = DaggerMainComponent.builder().caveGame(this).build();
+
         mMainConfig = mMainComponent.getMainConfig();
+        mAssetLoader = mMainComponent.getAssetLoader();
     }
 
     public void setDebug(boolean debug) {
@@ -41,11 +52,18 @@ public class CaveGame extends Game {
         mMainConfig.setWidth(width);
         mMainConfig.setHeight(height);
         mMainConfig.setShowInfo(mDebug);
+        mMainConfig.setAssetsPackPath(mAssetsPackPath);
+
+        if (mDebug) {
+            Gdx.app.setLogLevel(Application.LOG_DEBUG);
+        } else {
+            Gdx.app.setLogLevel(Application.LOG_ERROR);
+        }
     }
 
-    public void newGame() {
+    public void newGame(int gameMode) {
         GameScreen gameScreen = mMainComponent.getGameScreen();
-        gameScreen.newGame();
+        gameScreen.newGame(gameMode);
         setScreen(gameScreen);
     }
 
@@ -56,6 +74,9 @@ public class CaveGame extends Game {
     }
 
     public void quitGame() {
+        if (screen != null) {
+            screen.dispose();
+        }
         setScreen(mMainComponent.getMenuScreen());
     }
 
@@ -64,12 +85,18 @@ public class CaveGame extends Game {
         Gdx.app.log(TAG, mGameFolder);
         Gdx.files.absolute(mGameFolder).mkdirs();
 
-        Assets.load();
-        GameItems.load();
-
         initConfig();
 
+        Assets.load(mAssetLoader);
+        GameItems.load(mAssetLoader);
+
         setScreen(mMainComponent.getMenuScreen());
     }
 
+    @Override
+    public void dispose() {
+        if (screen != null) {
+            screen.dispose();
+        }
+    }
 }