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 com
.badlogic
.gdx
.Graphics
;
7 import ru
.deadsoftware
.cavedroid
.game
.GameScreen
;
8 import ru
.deadsoftware
.cavedroid
.misc
.Assets
;
9 import ru
.deadsoftware
.cavedroid
.misc
.utils
.AssetLoader
;
10 import ru
.deadsoftware
.cavedroid
.prefs
.PreferencesStore
;
12 import javax
.annotation
.Nullable
;
14 public class CaveGame
extends Game
{
16 private static final String TAG
= "CaveGame";
18 public static final String VERSION
= "alpha 0.9.2";
20 private final MainConfig mMainConfig
;
21 private final MainComponent mMainComponent
;
22 private final AssetLoader mAssetLoader
;
24 private final String mGameFolder
;
25 private final boolean mTouch
;
26 private boolean mDebug
;
29 private final String mAssetsPackPath
;
31 public CaveGame(String gameFolder
,
33 PreferencesStore preferencesStore
,
34 @Nullable String assetsPackPath
) {
35 mGameFolder
= gameFolder
;
37 mAssetsPackPath
= assetsPackPath
;
39 mMainComponent
= DaggerMainComponent
42 .preferencesStore(preferencesStore
)
45 mMainConfig
= mMainComponent
.getMainConfig();
46 mAssetLoader
= mMainComponent
.getAssetLoader();
49 public void setDebug(boolean debug
) {
53 private void initConfig() {
55 int height
= (int) (width
* ((float) Gdx
.graphics
.getHeight() / Gdx
.graphics
.getWidth()));
57 mMainConfig
.setMainComponent(mMainComponent
);
58 mMainConfig
.setGameFolder(mGameFolder
);
59 mMainConfig
.setTouch(mTouch
);
60 mMainConfig
.setWidth(width
);
61 mMainConfig
.setHeight(height
);
62 mMainConfig
.setShowInfo(mDebug
);
63 mMainConfig
.setAssetsPackPath(mAssetsPackPath
);
66 Gdx
.app
.setLogLevel(Application
.LOG_DEBUG
);
68 Gdx
.app
.setLogLevel(Application
.LOG_ERROR
);
71 mMainConfig
.setFullscreenToggleListener((value
) -> {
73 Gdx
.graphics
.setFullscreenMode(Gdx
.graphics
.getDisplayMode());
75 Gdx
.graphics
.setWindowedMode(width
, height
);
80 public void newGame(int gameMode
) {
81 GameScreen gameScreen
= mMainComponent
.getGameScreen();
82 gameScreen
.newGame(gameMode
);
83 setScreen(gameScreen
);
86 public void loadGame() {
87 GameScreen gameScreen
= mMainComponent
.getGameScreen();
88 gameScreen
.loadGame();
89 setScreen(gameScreen
);
92 public void quitGame() {
96 setScreen(mMainComponent
.getMenuScreen());
100 public void create() {
101 Gdx
.files
.absolute(mGameFolder
).mkdirs();
104 Gdx
.app
.debug(TAG
, mGameFolder
);
105 Assets
.load(mAssetLoader
);
106 setScreen(mMainComponent
.getMenuScreen());
110 public void dispose() {
111 if (screen
!= null) {