DEADSOFTWARE

Add my repo for automultibind
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / CaveGame.java
index 1c1679145d6a70bf8a73948ace2e76f3f3ba06c0..9ca34b8e0507a5a42523accf769469847185661a 100644 (file)
@@ -1,11 +1,13 @@
 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 com.badlogic.gdx.Graphics;
 import ru.deadsoftware.cavedroid.game.GameScreen;
 import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.utils.AssetLoader;
+import ru.deadsoftware.cavedroid.prefs.PreferencesStore;
 
 import javax.annotation.Nullable;
 
@@ -13,7 +15,7 @@ public class CaveGame extends Game {
 
     private static final String TAG = "CaveGame";
 
-    public static final String VERSION = "alpha 0.5.2";
+    public static final String VERSION = "alpha 0.9.2";
 
     private final MainConfig mMainConfig;
     private final MainComponent mMainComponent;
@@ -26,12 +28,19 @@ public class CaveGame extends Game {
     @Nullable
     private final String mAssetsPackPath;
 
-    public CaveGame(String gameFolder, boolean touch, @Nullable String assetsPackPath) {
+    public CaveGame(String gameFolder,
+                    boolean touch,
+                    PreferencesStore preferencesStore,
+                    @Nullable String assetsPackPath) {
         mGameFolder = gameFolder;
         mTouch = touch;
         mAssetsPackPath = assetsPackPath;
 
-        mMainComponent = DaggerMainComponent.builder().caveGame(this).build();
+        mMainComponent = DaggerMainComponent
+                .builder()
+                .caveGame(this)
+                .preferencesStore(preferencesStore)
+                .build();
 
         mMainConfig = mMainComponent.getMainConfig();
         mAssetLoader = mMainComponent.getAssetLoader();
@@ -42,7 +51,7 @@ public class CaveGame extends Game {
     }
 
     private void initConfig() {
-        int width = mTouch ? 320 : 480;
+        int width = 480;
         int height = (int) (width * ((float) Gdx.graphics.getHeight() / Gdx.graphics.getWidth()));
 
         mMainConfig.setMainComponent(mMainComponent);
@@ -52,6 +61,20 @@ public class CaveGame extends Game {
         mMainConfig.setHeight(height);
         mMainConfig.setShowInfo(mDebug);
         mMainConfig.setAssetsPackPath(mAssetsPackPath);
+
+        if (mDebug) {
+            Gdx.app.setLogLevel(Application.LOG_DEBUG);
+        } else {
+            Gdx.app.setLogLevel(Application.LOG_ERROR);
+        }
+
+        mMainConfig.setFullscreenToggleListener((value) -> {
+            if (value) {
+                Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
+            } else {
+                Gdx.graphics.setWindowedMode(width, height);
+            }
+        });
     }
 
     public void newGame(int gameMode) {
@@ -75,14 +98,11 @@ public class CaveGame extends Game {
 
     @Override
     public void create() {
-        Gdx.app.log(TAG, mGameFolder);
         Gdx.files.absolute(mGameFolder).mkdirs();
-
         initConfig();
 
+        Gdx.app.debug(TAG, mGameFolder);
         Assets.load(mAssetLoader);
-        GameItems.load(mAssetLoader);
-
         setScreen(mMainComponent.getMenuScreen());
     }
 
@@ -91,5 +111,6 @@ public class CaveGame extends Game {
         if (screen != null) {
             screen.dispose();
         }
+        Assets.dispose();
     }
 }