DEADSOFTWARE

Add RenderModule code generation
[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 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;
28 @Nullable
29 private final String mAssetsPackPath;
31 public CaveGame(String gameFolder,
32 boolean touch,
33 PreferencesStore preferencesStore,
34 @Nullable String assetsPackPath) {
35 mGameFolder = gameFolder;
36 mTouch = touch;
37 mAssetsPackPath = assetsPackPath;
39 mMainComponent = DaggerMainComponent
40 .builder()
41 .caveGame(this)
42 .preferencesStore(preferencesStore)
43 .build();
45 mMainConfig = mMainComponent.getMainConfig();
46 mAssetLoader = mMainComponent.getAssetLoader();
47 }
49 public void setDebug(boolean debug) {
50 mDebug = debug;
51 }
53 private void initConfig() {
54 int width = 480;
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);
65 if (mDebug) {
66 Gdx.app.setLogLevel(Application.LOG_DEBUG);
67 } else {
68 Gdx.app.setLogLevel(Application.LOG_ERROR);
69 }
71 mMainConfig.setFullscreenToggleListener((value) -> {
72 if (value) {
73 Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
74 } else {
75 Gdx.graphics.setWindowedMode(width, height);
76 }
77 });
78 }
80 public void newGame(int gameMode) {
81 GameScreen gameScreen = mMainComponent.getGameScreen();
82 gameScreen.newGame(gameMode);
83 setScreen(gameScreen);
84 }
86 public void loadGame() {
87 GameScreen gameScreen = mMainComponent.getGameScreen();
88 gameScreen.loadGame();
89 setScreen(gameScreen);
90 }
92 public void quitGame() {
93 if (screen != null) {
94 screen.dispose();
95 }
96 setScreen(mMainComponent.getMenuScreen());
97 }
99 @Override
100 public void create() {
101 Gdx.files.absolute(mGameFolder).mkdirs();
102 initConfig();
104 Gdx.app.debug(TAG, mGameFolder);
105 Assets.load(mAssetLoader);
106 setScreen(mMainComponent.getMenuScreen());
109 @Override
110 public void dispose() {
111 if (screen != null) {
112 screen.dispose();
114 Assets.dispose();