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 org
.jetbrains
.annotations
.Nullable
;
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 public class CaveGame
extends Game
{
14 private static final String TAG
= "CaveGame";
16 public static final String VERSION
= "alpha 0.9.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
;
27 private final String mAssetsPackPath
;
29 public CaveGame(String gameFolder
,
31 PreferencesStore preferencesStore
,
32 @Nullable String assetsPackPath
) {
33 mGameFolder
= gameFolder
;
35 mAssetsPackPath
= assetsPackPath
;
37 mMainComponent
= DaggerMainComponent
40 .preferencesStore(preferencesStore
)
43 mMainConfig
= mMainComponent
.getMainConfig();
44 mAssetLoader
= mMainComponent
.getAssetLoader();
47 public void setDebug(boolean debug
) {
51 private void initConfig() {
53 int height
= (int) (width
* ((float) Gdx
.graphics
.getHeight() / Gdx
.graphics
.getWidth()));
55 mMainConfig
.setMainComponent(mMainComponent
);
56 mMainConfig
.setGameFolder(mGameFolder
);
57 mMainConfig
.setTouch(mTouch
);
58 mMainConfig
.setWidth(width
);
59 mMainConfig
.setHeight(height
);
60 mMainConfig
.setShowInfo(mDebug
);
61 mMainConfig
.setAssetsPackPath(mAssetsPackPath
);
64 Gdx
.app
.setLogLevel(Application
.LOG_DEBUG
);
66 Gdx
.app
.setLogLevel(Application
.LOG_ERROR
);
69 mMainConfig
.setFullscreenToggleListener((value
) -> {
71 Gdx
.graphics
.setFullscreenMode(Gdx
.graphics
.getDisplayMode());
73 Gdx
.graphics
.setWindowedMode(width
, height
);
78 public void newGame(int gameMode
) {
79 GameScreen gameScreen
= mMainComponent
.getGameScreen();
80 gameScreen
.newGame(gameMode
);
81 setScreen(gameScreen
);
84 public void loadGame() {
85 GameScreen gameScreen
= mMainComponent
.getGameScreen();
86 gameScreen
.loadGame();
87 setScreen(gameScreen
);
90 public void quitGame() {
94 setScreen(mMainComponent
.getMenuScreen());
98 public void create() {
99 Gdx
.files
.absolute(mGameFolder
).mkdirs();
102 Gdx
.app
.debug(TAG
, mGameFolder
);
103 Assets
.load(mAssetLoader
);
104 setScreen(mMainComponent
.getMenuScreen());
108 public void dispose() {
109 if (screen
!= null) {