DEADSOFTWARE

Update android.yml
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / CaveGame.java
1 package ru.deadsoftware.cavedroid;
3 import com.badlogic.gdx.Application;
4 import com.badlogic.gdx.Game;
5 import com.badlogic.gdx.Gdx;
6 import ru.deadsoftware.cavedroid.game.GameScreen;
7 import ru.deadsoftware.cavedroid.misc.Assets;
8 import ru.deadsoftware.cavedroid.misc.utils.AssetLoader;
10 import javax.annotation.Nullable;
12 public class CaveGame extends Game {
14 private static final String TAG = "CaveGame";
16 public static final String VERSION = "alpha 0.5.2";
18 private final MainConfig mMainConfig;
19 private final MainComponent mMainComponent;
20 private final AssetLoader mAssetLoader;
22 private final String mGameFolder;
23 private final boolean mTouch;
24 private boolean mDebug;
26 @Nullable
27 private final String mAssetsPackPath;
29 public CaveGame(String gameFolder, boolean touch, @Nullable String assetsPackPath) {
30 mGameFolder = gameFolder;
31 mTouch = touch;
32 mAssetsPackPath = assetsPackPath;
34 mMainComponent = DaggerMainComponent.builder().caveGame(this).build();
36 mMainConfig = mMainComponent.getMainConfig();
37 mAssetLoader = mMainComponent.getAssetLoader();
38 }
40 public void setDebug(boolean debug) {
41 mDebug = debug;
42 }
44 private void initConfig() {
45 int width = mTouch ? 320 : 480;
46 int height = (int) (width * ((float) Gdx.graphics.getHeight() / Gdx.graphics.getWidth()));
48 mMainConfig.setMainComponent(mMainComponent);
49 mMainConfig.setGameFolder(mGameFolder);
50 mMainConfig.setTouch(mTouch);
51 mMainConfig.setWidth(width);
52 mMainConfig.setHeight(height);
53 mMainConfig.setShowInfo(mDebug);
54 mMainConfig.setAssetsPackPath(mAssetsPackPath);
56 if (mDebug) {
57 Gdx.app.setLogLevel(Application.LOG_DEBUG);
58 } else {
59 Gdx.app.setLogLevel(Application.LOG_ERROR);
60 }
61 }
63 public void newGame(int gameMode) {
64 GameScreen gameScreen = mMainComponent.getGameScreen();
65 gameScreen.newGame(gameMode);
66 setScreen(gameScreen);
67 }
69 public void loadGame() {
70 GameScreen gameScreen = mMainComponent.getGameScreen();
71 gameScreen.loadGame();
72 setScreen(gameScreen);
73 }
75 public void quitGame() {
76 if (screen != null) {
77 screen.dispose();
78 }
79 setScreen(mMainComponent.getMenuScreen());
80 }
82 @Override
83 public void create() {
84 Gdx.app.log(TAG, mGameFolder);
85 Gdx.files.absolute(mGameFolder).mkdirs();
86 initConfig();
87 Assets.load(mAssetLoader);
88 setScreen(mMainComponent.getMenuScreen());
89 }
91 @Override
92 public void dispose() {
93 if (screen != null) {
94 screen.dispose();
95 }
96 }
97 }