DEADSOFTWARE

Implement DI for menu and refactor #13
authorfred-boy <fredboy@protonmail.com>
Wed, 6 May 2020 13:29:26 +0000 (20:29 +0700)
committerfred-boy <fredboy@protonmail.com>
Wed, 6 May 2020 14:27:01 +0000 (21:27 +0700)
30 files changed:
core/src/ru/deadsoftware/cavedroid/CaveGame.java
core/src/ru/deadsoftware/cavedroid/MainComponent.java
core/src/ru/deadsoftware/cavedroid/MainConfig.java
core/src/ru/deadsoftware/cavedroid/game/GameComponent.java
core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java
core/src/ru/deadsoftware/cavedroid/game/GameInput.java
core/src/ru/deadsoftware/cavedroid/game/GameInputProcessor.java
core/src/ru/deadsoftware/cavedroid/game/GameModule.java [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java
core/src/ru/deadsoftware/cavedroid/game/GameProc.java
core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
core/src/ru/deadsoftware/cavedroid/game/GameSaver.java
core/src/ru/deadsoftware/cavedroid/game/GameScreen.java
core/src/ru/deadsoftware/cavedroid/game/GameWorld.java
core/src/ru/deadsoftware/cavedroid/game/WorldGen.java
core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java
core/src/ru/deadsoftware/cavedroid/game/mobs/MobsController.java
core/src/ru/deadsoftware/cavedroid/game/objects/DropController.java
core/src/ru/deadsoftware/cavedroid/menu/MenuComponent.java [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java
core/src/ru/deadsoftware/cavedroid/menu/MenuScope.java [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/menu/MenuScreen.java [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/menu/submenus/Menu.java
core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuInput.java [deleted file]
core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuMain.java
core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuNewGame.java
core/src/ru/deadsoftware/cavedroid/misc/states/AppState.java [deleted file]
core/src/ru/deadsoftware/cavedroid/misc/states/GameState.java [deleted file]
core/src/ru/deadsoftware/cavedroid/misc/states/MenuState.java [deleted file]
core/src/ru/deadsoftware/cavedroid/misc/states/package-info.java [deleted file]

index f1fb3eed43b8be66c7f358e028561085358bdcdb..031b6135ae3fb58153427d52e76814d598898124 100644 (file)
@@ -3,6 +3,7 @@ package ru.deadsoftware.cavedroid;
 import com.badlogic.gdx.Game;
 import com.badlogic.gdx.Gdx;
 import ru.deadsoftware.cavedroid.game.GameItems;
+import ru.deadsoftware.cavedroid.game.GameScreen;
 import ru.deadsoftware.cavedroid.misc.Assets;
 
 public class CaveGame extends Game {
@@ -11,6 +12,9 @@ public class CaveGame extends Game {
 
     public static final String VERSION = "alpha 0.4";
 
+    private final MainConfig mMainConfig;
+    private final MainComponent mMainComponent;
+
     private final String mGameFolder;
     private final boolean mTouch;
     private boolean mDebug;
@@ -18,22 +22,41 @@ public class CaveGame extends Game {
     public CaveGame(String gameFolder, boolean touch) {
         mGameFolder = gameFolder;
         mTouch = touch;
+
+        mMainComponent = DaggerMainComponent.builder().caveGame(this).build();
+        mMainConfig = mMainComponent.getMainConfig();
     }
 
     public void setDebug(boolean debug) {
         mDebug = debug;
     }
 
-    private void initConfig(MainConfig mainConfig, MainComponent mainComponent) {
+    private void initConfig() {
         int width = mTouch ? 320 : 480;
         int height = (int) (width * ((float) Gdx.graphics.getHeight() / Gdx.graphics.getWidth()));
 
-        mainConfig.setMainComponent(mainComponent);
-        mainConfig.setGameFolder(mGameFolder);
-        mainConfig.setTouch(mTouch);
-        mainConfig.setWidth(width);
-        mainConfig.setHeight(height);
-        mainConfig.setShowInfo(true);
+        mMainConfig.setMainComponent(mMainComponent);
+        mMainConfig.setGameFolder(mGameFolder);
+        mMainConfig.setTouch(mTouch);
+        mMainConfig.setWidth(width);
+        mMainConfig.setHeight(height);
+        mMainConfig.setShowInfo(mDebug);
+    }
+
+    public void newGame() {
+        GameScreen gameScreen = mMainComponent.getGameScreen();
+        gameScreen.newGame();
+        setScreen(gameScreen);
+    }
+
+    public void loadGame() {
+        GameScreen gameScreen = mMainComponent.getGameScreen();
+        gameScreen.loadGame();
+        setScreen(gameScreen);
+    }
+
+    public void quitGame() {
+        setScreen(mMainComponent.getMenuScreen());
     }
 
     @Override
@@ -44,9 +67,9 @@ public class CaveGame extends Game {
         Assets.load();
         GameItems.load();
 
-        MainComponent mainComponent = DaggerMainComponent.create();
-        initConfig(mainComponent.getGameConfig(), mainComponent);
-        setScreen(mainComponent.getGameScreen());
+        initConfig();
+
+        setScreen(mMainComponent.getMenuScreen());
     }
 
 }
index 74bb1915dbd59c8ea8d723db8b1c87f1d43b48f5..d8a05da03fbdeda134cc144a6af804f881ff48d9 100644 (file)
@@ -2,12 +2,16 @@ package ru.deadsoftware.cavedroid;
 
 import dagger.Component;
 import ru.deadsoftware.cavedroid.game.GameScreen;
+import ru.deadsoftware.cavedroid.menu.MenuScreen;
 
 import javax.inject.Singleton;
 
 @Singleton
-@Component
+@Component(dependencies = CaveGame.class)
 public interface MainComponent {
     GameScreen getGameScreen();
-    MainConfig getGameConfig();
+
+    MenuScreen getMenuScreen();
+
+    MainConfig getMainConfig();
 }
index b48b78df896ebe46b878bc1675dcc44007fdafdc..8cd0ffdac6920e2977f46ac10c156e8be4f4ac7f 100644 (file)
@@ -2,12 +2,16 @@ package ru.deadsoftware.cavedroid;
 
 import ru.deadsoftware.cavedroid.game.GameUiWindow;
 
+import javax.annotation.CheckForNull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
 @Singleton
 public class MainConfig {
 
+    private final CaveGame mCaveGame;
+
+    @CheckForNull
     private MainComponent mMainComponent;
 
     private GameUiWindow mGameUiWindow;
@@ -21,12 +25,19 @@ public class MainConfig {
     private float mHeight;
 
     @Inject
-    public MainConfig() {
+    public MainConfig(CaveGame caveGame) {
+        mCaveGame = caveGame;
+
         mGameUiWindow = GameUiWindow.NONE;
         mGameFolder = "";
     }
 
+    public CaveGame getCaveGame() {
+        return mCaveGame;
+    }
+
     public MainComponent getMainComponent() {
+        assert mMainComponent != null;
         return mMainComponent;
     }
 
index 320f4f6438c2f85d9468c5648f412f30522a5b47..25779f06851e234c83c818872bf290064eccd82d 100644 (file)
@@ -4,8 +4,9 @@ import dagger.Component;
 import ru.deadsoftware.cavedroid.MainComponent;
 
 @GameScope
-@Component(dependencies = MainComponent.class)
+@Component(dependencies = MainComponent.class, modules = GameModule.class)
 public interface GameComponent {
     GameProc getGameProc();
+
     GameInputProcessor getGameInputProcessor();
 }
index 20e95b8799bda3cdcfbcb3513db1d0a6e4921506..c3cdd47b355a5d2434f27c3df622dbb1ea669836 100644 (file)
@@ -16,12 +16,12 @@ class GameFluidsThread extends Thread {
     private static final int[] LAVA_IDS = {9, 64, 65, 66, 67};
 
     private long mFluidLastUpdateTimestamp = 0;
-    
+
     private final GameWorld mGameWorld;
     private final MobsController mMobsController;
 
     private final Thread mMainThread;
-    
+
     GameFluidsThread(GameWorld gameWorld,
                      MobsController mobsController,
                      Thread mainThread) {
index 3a5e3c4ff47044665b0d69cac4384f0c7bd7072c..ca603176453f1ac7e219c6d825c11dfeb1f8f528 100644 (file)
@@ -10,6 +10,7 @@ import ru.deadsoftware.cavedroid.game.mobs.Mob;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 import ru.deadsoftware.cavedroid.game.mobs.Pig;
 import ru.deadsoftware.cavedroid.game.mobs.Player;
+import ru.deadsoftware.cavedroid.game.objects.DropController;
 import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.ControlMode;
 
@@ -22,6 +23,7 @@ public class GameInput {
 
     private final MainConfig mMainConfig;
     private final GameWorld mGameWorld;
+    private final DropController mDropController;
     private final MobsController mMobsController;
     private final Player mPlayer;
 
@@ -45,9 +47,11 @@ public class GameInput {
     @Inject
     public GameInput(MainConfig mainConfig,
                      GameWorld gameWorld,
+                     DropController dropController,
                      MobsController mobsController) {
         mMainConfig = mainConfig;
         mGameWorld = gameWorld;
+        mDropController = dropController;
         mMobsController = mobsController;
 
         mPlayer = mMobsController.getPlayer();
@@ -243,7 +247,7 @@ public class GameInput {
             mTouchedDown = false;
         } else {
             if (insideHotbar(mTouchDownX, mTouchDownY)) {
-//                CaveGame.GAME_STATE = GameState.CREATIVE_INV;
+                mMainConfig.setGameUiWindow(GameUiWindow.CREATIVE_INVENTORY);
                 mTouchedDown = false;
             }
         }
@@ -291,11 +295,11 @@ public class GameInput {
                 mGameWorld.placeToForeground(mCurX, mCurY, 8);
                 break;
 
-//            case Input.Keys.ESCAPE:
-//            case Input.Keys.BACK:
-//                CaveGame.APP_STATE = AppState.SAVE;
-//                CaveGame.GAME_STATE = GameState.PAUSE;
-//                break;
+            case Input.Keys.ESCAPE:
+            case Input.Keys.BACK:
+                GameSaver.save(mMainConfig, mDropController, mMobsController, mGameWorld);
+                mMainConfig.getCaveGame().quitGame();
+                break;
 
             case Input.Keys.F1:
                 mMainConfig.setShowInfo(!mMainConfig.isShowInfo());
index faafd63959c4ede000938d27d503ce13ac0c6f92..51cc897f4a1f891e5cf044325e4c09db572e55ff 100644 (file)
@@ -21,7 +21,7 @@ public class GameInputProcessor extends InputAdapter {
     private final GameInput mGameInput;
     private final GameRenderer mGameRenderer;
     private final MainConfig mMainConfig;
-    
+
     @Inject
     public GameInputProcessor(GameInput gameInput,
                               GameRenderer gameRenderer,
@@ -29,7 +29,7 @@ public class GameInputProcessor extends InputAdapter {
         mGameInput = gameInput;
         mGameRenderer = gameRenderer;
         mMainConfig = mainConfig;
-        
+
         loadTouchButtonsFromJSON();
     }
 
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameModule.java b/core/src/ru/deadsoftware/cavedroid/game/GameModule.java
new file mode 100644 (file)
index 0000000..d7ccc2d
--- /dev/null
@@ -0,0 +1,52 @@
+package ru.deadsoftware.cavedroid.game;
+
+import dagger.Module;
+import dagger.Provides;
+import ru.deadsoftware.cavedroid.MainConfig;
+import ru.deadsoftware.cavedroid.game.mobs.MobsController;
+import ru.deadsoftware.cavedroid.game.objects.DropController;
+
+import javax.annotation.CheckForNull;
+
+@Module
+public class GameModule {
+
+    @CheckForNull
+    private static GameSaver.Data data;
+
+    public static void load(MainConfig mainConfig) {
+        data = GameSaver.load(mainConfig);
+    }
+
+    private static void makeDataNullIfEmpty() {
+        if (data != null && data.isEmpty()) {
+            data = null;
+        }
+    }
+
+    @Provides
+    @GameScope
+    public static DropController provideDropController() {
+        DropController controller = data != null ? data.retrieveDropController() : new DropController();
+        makeDataNullIfEmpty();
+        return controller;
+    }
+
+    @Provides
+    @GameScope
+    public static MobsController provideMobsController() {
+        MobsController controller = data != null ? data.retrieveMobsController() : new MobsController();
+        makeDataNullIfEmpty();
+        return controller;
+    }
+
+    @Provides
+    @GameScope
+    public static GameWorld provideGameWorld(DropController dropController, MobsController mobsController) {
+        int[][] fm = data != null ? data.retrieveForeMap() : null;
+        int[][] bm = data != null ? data.retrieveBackMap() : null;
+        makeDataNullIfEmpty();
+        return new GameWorld(dropController, mobsController, fm, bm);
+    }
+
+}
index 6695d6e76864606e4fe06a6aaaa80e8dcf3e97b1..d6b5a9aa5da8e907c07430e1670cce350a61a757 100644 (file)
@@ -9,6 +9,7 @@ import ru.deadsoftware.cavedroid.game.mobs.Mob;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 import ru.deadsoftware.cavedroid.game.mobs.Player;
 import ru.deadsoftware.cavedroid.game.objects.Drop;
+import ru.deadsoftware.cavedroid.game.objects.DropController;
 
 import javax.inject.Inject;
 import java.util.Iterator;
@@ -24,14 +25,17 @@ class GamePhysics {
     private final GameWorld mGameWorld;
     private final MainConfig mMainConfig;
     private final MobsController mMobsController;
+    private final DropController mDropController;
 
     @Inject
     public GamePhysics(GameWorld gameWorld,
                        MainConfig mainConfig,
-                       MobsController mobsController) {
+                       MobsController mobsController,
+                       DropController dropController) {
         mGameWorld = gameWorld;
         mMainConfig = mainConfig;
         mMobsController = mobsController;
+        mDropController = dropController;
     }
 
     /**
@@ -253,16 +257,18 @@ class GamePhysics {
     }
 
     void update() {
-//        for (Iterator<Drop> it = GP.drops.iterator(); it.hasNext(); ) {
-//            Drop drop = it.next();
-//            dropPhy(drop);
-//            if (Intersector.overlaps(drop, GP.player)) {
-//                drop.pickUpDrop(GP.player);
-//            }
-//            if (drop.isPickedUp()) {
-//                it.remove();
-//            }
-//        }
+        Player player = mMobsController.getPlayer();
+
+        for (Iterator<Drop> it = mDropController.getIterator(); it.hasNext(); ) {
+            Drop drop = it.next();
+            dropPhy(drop);
+            if (Intersector.overlaps(drop, player)) {
+                drop.pickUpDrop(player);
+            }
+            if (drop.isPickedUp()) {
+                it.remove();
+            }
+        }
 
         for (Iterator<Mob> it = mMobsController.getIterator(); it.hasNext(); ) {
             Mob mob = it.next();
@@ -273,7 +279,6 @@ class GamePhysics {
             }
         }
 
-        Player player = mMobsController.getPlayer();
         playerPhy(player);
         if (player.isDead()) {
             player.respawn(mGameWorld);
index ef0821107a4e520b0d56e4c21d145e9203549992..44a46878cff367a12cc83ed0b8b8619be6b16c54 100644 (file)
@@ -1,9 +1,11 @@
 package ru.deadsoftware.cavedroid.game;
 
+import com.badlogic.gdx.utils.Disposable;
+
 import javax.inject.Inject;
 
 @GameScope
-public class GameProc {
+public class GameProc implements Disposable {
 
     public static final int MAX_CREATIVE_SCROLL = GameItems.getItemsSize() / 8;
 
@@ -32,4 +34,8 @@ public class GameProc {
         mGameRenderer.render(delta);
     }
 
+    @Override
+    public void dispose() {
+        mGameWorld.dispose();
+    }
 }
index 018fe1bf750e5b3fba65d98bb1acddcead8af876..864938d83b35db74a152d17f90ef4480a30897d4 100644 (file)
@@ -23,8 +23,6 @@ import static ru.deadsoftware.cavedroid.misc.Assets.textureRegions;
 @GameScope
 public class GameRenderer extends Renderer {
 
-    private static final String TAG = "GameRenderer";
-
     private final MainConfig mMainConfig;
     private final GameInput mGameInput;
     private final GameWorld mGameWorld;
@@ -286,16 +284,17 @@ public class GameRenderer extends Renderer {
 
         if (mMainConfig.isShowInfo()) {
             spriter.begin();
+            Player player = mMobsController.getPlayer();
             drawString("FPS: " + fps, 0, 0);
-            drawString("X: " + mMobsController.getPlayer().getMapX(), 0, 10);
-            drawString("Y: " + mMobsController.getPlayer().getUpperMapY(), 0, 20);
+            drawString("X: " + player.getMapX(), 0, 10);
+            drawString("Y: " + player.getUpperMapY(), 0, 20);
             drawString("CurX: " + mGameInput.getCurX(), 0, 30);
             drawString("CurY: " + mGameInput.getCurY(), 0, 40);
             drawString("Mobs: " + mMobsController.getSize(), 0, 50);
             drawString("Drops: " + mDropController.getSize(), 0, 60);
             drawString("Block: " + GameItems.getBlockKey(mGameWorld.getForeMap(mGameInput.getCurX(), mGameInput.getCurY())), 0, 70);
             drawString("Hand: " + GameItems.getItemKey(mMobsController.getPlayer().inventory[mMobsController.getPlayer().slot]), 0, 80);
-            drawString("Game mode: " + mMobsController.getPlayer().gameMode, 0, 90);
+            drawString("Game mode: " + player.gameMode, 0, 90);
             spriter.end();
         }
 
index 26281f6c81dfa5c16207c91ce810a6e5f3016192..1ff2bad9783788a68d6ff1858dc9185f2a9a6fbe 100644 (file)
 package ru.deadsoftware.cavedroid.game;
 
+import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.files.FileHandle;
+import ru.deadsoftware.cavedroid.MainConfig;
+import ru.deadsoftware.cavedroid.game.mobs.MobsController;
+import ru.deadsoftware.cavedroid.game.objects.DropController;
 
-import java.io.BufferedOutputStream;
-import java.io.DataInputStream;
-import java.io.IOException;
+import javax.annotation.CheckForNull;
+import java.io.*;
 import java.nio.ByteBuffer;
 
-//TODO rewrite saver
 public class GameSaver {
 
-    private static final int VERSION = 0;
+    public static class Data {
+        @CheckForNull
+        private MobsController mMobsController;
+        @CheckForNull
+        private DropController mDropController;
+        @CheckForNull
+        private int[][] mForeMap, mBackMap;
 
+        public Data(MobsController mobsController, DropController dropController, int[][] foreMap, int[][] backMap) {
+            mMobsController = mobsController;
+            mDropController = dropController;
+            mForeMap = foreMap;
+            mBackMap = backMap;
+        }
+
+        public MobsController retrieveMobsController() {
+            assert mMobsController != null;
+            MobsController mobsController = mMobsController;
+            mMobsController = null;
+            return mobsController;
+        }
+
+        public DropController retrieveDropController() {
+            assert mDropController != null;
+            DropController dropController = mDropController;
+            mDropController = null;
+            return dropController;
+        }
+
+        public int[][] retrieveForeMap() {
+            assert mForeMap != null;
+            int[][] foreMap = mForeMap;
+            mForeMap = null;
+            return foreMap;
+        }
+
+        public int[][] retrieveBackMap() {
+            assert mBackMap != null;
+            int[][] backMap = mBackMap;
+            mBackMap = null;
+            return backMap;
+        }
+
+        public boolean isEmpty() {
+            return mMobsController == null && mDropController == null && mForeMap == null && mBackMap == null;
+        }
+    }
+
+    private static final int SAVE_VERSION = 1;
 
     private static byte[] intToBytes(int i) {
         return ByteBuffer.allocate(4).putInt(i).array();
     }
 
     private static void saveMap(FileHandle file, int[][] map) throws IOException {
-        int rl, bl;
+        int run, block;
         int width = map.length;
         int height = map[0].length;
+
         BufferedOutputStream out = new BufferedOutputStream(file.write(false));
-        out.write(intToBytes(VERSION));
+
+        out.write(intToBytes(SAVE_VERSION));
         out.write(intToBytes(width));
         out.write(intToBytes(height));
+
         for (int y = 0; y < height; y++) {
-            bl = map[0][y];
-            rl = 0;
+            block = map[0][y];
+            run = 0;
             for (int[] ints : map) {
-                if (ints[y] != bl) {
-                    out.write(intToBytes(rl));
-                    out.write(intToBytes(bl));
-                    rl = 0;
-                    bl = ints[y];
+                if (ints[y] != block) {
+                    out.write(intToBytes(run));
+                    out.write(intToBytes(block));
+                    run = 0;
+                    block = ints[y];
                 }
-                rl++;
+                run++;
             }
-            out.write(intToBytes(rl));
-            out.write(intToBytes(bl));
+            out.write(intToBytes(run));
+            out.write(intToBytes(block));
         }
+
         out.flush();
         out.close();
     }
 
-
     private static int[][] loadMap(FileHandle file) throws Exception {
         int[][] map;
-        int ver, width, height;
-        int rl, bl;
+        int version, width, height;
+        int run, block;
+
         DataInputStream in = new DataInputStream(file.read());
-        ver = in.readInt();
-        if (VERSION == ver) {
+
+        version = in.readInt();
+
+        if (SAVE_VERSION == version) {
             width = in.readInt();
             height = in.readInt();
             map = new int[width][height];
             for (int y = 0; y < height; y++) {
-                for (int x = 0; x < width; x += rl) {
-                    rl = in.readInt();
-                    bl = in.readInt();
-                    for (int i = x; i < x + rl; i++) {
-                        map[i][y] = bl;
+                for (int x = 0; x < width; x += run) {
+                    run = in.readInt();
+                    block = in.readInt();
+                    for (int i = x; i < x + run; i++) {
+                        map[i][y] = block;
                     }
                 }
             }
-            in.close();
         } else {
             throw new Exception("version mismatch");
         }
+
+        in.close();
         return map;
     }
 
-    public static GameProc load() {
-//        FileHandle file = Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/game.sav");
-//        GameProc gameProc = null;
-//        try {
-//            ObjectInputStream in = new ObjectInputStream(file.read());
-//            int ver = in.readInt();
-//            if (VERSION == ver) {
-//                gameProc = (GameProc) in.readObject();
-//            } else {
-//                throw new Exception("version mismatch");
-//            }
-//            in.close();
-//            gameProc.world = new GameWorld(
-//                    loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav")),
-//                    loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav"))
-//            );
-//            gameProc.physics = new GamePhysics();
-//            gameProc.input = new GameInput();
-//        } catch (Exception e) {
-//            Gdx.app.error("GameSaver", e.getMessage(), e);
-//            Gdx.app.exit();
-//        }
-//        return gameProc;
+    @CheckForNull
+    public static Data load(MainConfig mainConfig) {
+        String folder = mainConfig.getGameFolder();
+        FileHandle file = Gdx.files.absolute(folder + "/saves/game.sav");
+
+        try {
+            ObjectInputStream in = new ObjectInputStream(file.read());
+            int version = in.readInt();
+            DropController dropController;
+            MobsController mobsController;
+
+            if (SAVE_VERSION == version) {
+                dropController = (DropController) in.readObject();
+                mobsController = (MobsController) in.readObject();
+            } else {
+                throw new Exception("version mismatch");
+            }
+
+            in.close();
+
+            int[][] foreMap = loadMap(Gdx.files.absolute(mainConfig.getGameFolder() + "/saves/foremap.sav"));
+            int[][] backMap = loadMap(Gdx.files.absolute(mainConfig.getGameFolder() + "/saves/backmap.sav"));
+
+            if (dropController == null || mobsController == null) {
+                throw new Exception("couldn't load");
+            }
+
+            return new Data(mobsController, dropController, foreMap, backMap);
+        } catch (Exception e) {
+            Gdx.app.error("GameSaver", e.getMessage());
+        }
+
         return null;
     }
 
-    public static void save(GameProc gp) {
-//        FileHandle file = Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/");
-//        file.mkdirs();
-//        file = Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/game.sav");
-//        try {
-//            ObjectOutputStream out = new ObjectOutputStream(file.write(false));
-//            out.writeInt(VERSION);
-//            out.writeObject(gp);
-//            out.close();
-//            saveMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav"), gp.world.getFullForeMap());
-//            saveMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav"), gp.world.getFullBackMap());
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//        }
-    }
+    public static void save(MainConfig mainConfig,
+                            DropController dropController,
+                            MobsController mobsController,
+                            GameWorld gameWorld) {
+
+        String folder = mainConfig.getGameFolder();
+        FileHandle file = Gdx.files.absolute(folder + "/saves/");
+        file.mkdirs();
+        file = Gdx.files.absolute(folder + "/saves/game.sav");
 
-    public static boolean exists() {
-//        return (Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/game.sav").exists() &&
-//                Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav").exists() &&
-//                Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav").exists());
-        return false;
+        try {
+            ObjectOutputStream out = new ObjectOutputStream(file.write(false));
+            out.writeInt(SAVE_VERSION);
+            out.writeObject(dropController);
+            out.writeObject(mobsController);
+            out.close();
+            saveMap(Gdx.files.absolute(folder + "/saves/foremap.sav"), gameWorld.getFullForeMap());
+            saveMap(Gdx.files.absolute(folder + "/saves/backmap.sav"), gameWorld.getFullBackMap());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
+    public static boolean exists(MainConfig mainConfig) {
+        String folder = mainConfig.getGameFolder();
+        return (Gdx.files.absolute(folder + "/saves/game.sav").exists() &&
+                Gdx.files.absolute(folder + "/saves/foremap.sav").exists() &&
+                Gdx.files.absolute(folder + "/saves/backmap.sav").exists());
+    }
 }
index 00cfd3e6502b57c0be039514f0f25870f639d2f6..370d8bd79066baf1db5c385f4d89556b53c6f740 100644 (file)
@@ -4,28 +4,52 @@ import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.Screen;
 import ru.deadsoftware.cavedroid.MainConfig;
 
+import javax.annotation.CheckForNull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
 @Singleton
 public class GameScreen implements Screen {
 
-    private static final String TAG = "GameScreen";
-
     private final MainConfig mMainConfig;
 
+    @CheckForNull
     private GameProc mGameProc;
+    @CheckForNull
+    private GameInputProcessor mGameInputProcessor;
 
     @Inject
     public GameScreen(MainConfig mainConfig) {
         mMainConfig = mainConfig;
-        newGame();
     }
 
     public void newGame() {
+        if (mGameProc != null) {
+            mGameProc.dispose();
+        }
+
         GameComponent gameComponent = DaggerGameComponent.builder()
                 .mainComponent(mMainConfig.getMainComponent()).build();
+
         mGameProc = gameComponent.getGameProc();
+        mGameInputProcessor = gameComponent.getGameInputProcessor();
+
+        Gdx.input.setInputProcessor(gameComponent.getGameInputProcessor());
+    }
+
+    public void loadGame() {
+        if (mGameProc != null) {
+            mGameProc.dispose();
+        }
+
+        GameModule.load(mMainConfig);
+
+        GameComponent gameComponent = DaggerGameComponent.builder()
+                .mainComponent(mMainConfig.getMainComponent()).build();
+
+        mGameProc = gameComponent.getGameProc();
+        mGameInputProcessor = gameComponent.getGameInputProcessor();
+
         Gdx.input.setInputProcessor(gameComponent.getGameInputProcessor());
     }
 
@@ -36,7 +60,7 @@ public class GameScreen implements Screen {
 
     @Override
     public void show() {
-
+        Gdx.input.setInputProcessor(mGameInputProcessor);
     }
 
     @Override
index 5aecce295466dda979db1ed307f27f0cbead3706..cbf970ced1a84251183cca22cbd9877844ae374a 100644 (file)
@@ -1,15 +1,17 @@
 package ru.deadsoftware.cavedroid.game;
 
+import com.badlogic.gdx.utils.Disposable;
 import ru.deadsoftware.cavedroid.game.mobs.FallingGravel;
 import ru.deadsoftware.cavedroid.game.mobs.FallingSand;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 import ru.deadsoftware.cavedroid.game.objects.Block;
 import ru.deadsoftware.cavedroid.game.objects.DropController;
 
+import javax.annotation.CheckForNull;
 import javax.inject.Inject;
 
 @GameScope
-public class GameWorld {
+public class GameWorld implements Disposable {
 
     private static final int DEFAULT_WIDTH = 1024;
     private static final int DEFAULT_HEIGHT = 256;
@@ -29,28 +31,33 @@ public class GameWorld {
     private int mUpdateY;
 
     @Inject
-    GameWorld(DropController dropController,
-              MobsController mobsController) {
+    public GameWorld(DropController dropController,
+                     MobsController mobsController,
+                     @CheckForNull int[][] foreMap,
+                     @CheckForNull int[][] backMap) {
         mDropController = dropController;
         mMobsController = mobsController;
 
-        mWidth = DEFAULT_WIDTH;
-        mHeight = DEFAULT_HEIGHT;
-        WorldGen.genWorld(mWidth, mHeight);
-        mForeMap = WorldGen.getForeMap();
-        mBackMap = WorldGen.getBackMap();
-        WorldGen.clear();
+        boolean isNewGame = foreMap == null || backMap == null;
+
+        if (isNewGame) {
+            mWidth = DEFAULT_WIDTH;
+            mHeight = DEFAULT_HEIGHT;
+            WorldGen.genWorld(mWidth, mHeight);
+            mForeMap = WorldGen.getForeMap();
+            mBackMap = WorldGen.getBackMap();
+            WorldGen.clear();
+            mMobsController.getPlayer().respawn(this);
+        } else {
+            mForeMap = foreMap;
+            mBackMap = backMap;
+            mWidth = mForeMap.length;
+            mHeight = mForeMap[0].length;
+        }
 
         mGameFluidsThread = new GameFluidsThread(this, mMobsController, Thread.currentThread());
     }
 
-//    GameWorld(int[][] foreMap, int[][] backMap) {
-//        this.foreMap = foreMap.clone();
-//        this.backMap = backMap.clone();
-//        WIDTH = foreMap.length;
-//        HEIGHT = foreMap[0].length;
-//    }
-
     public int getWidth() {
         return mWidth;
     }
@@ -200,7 +207,7 @@ public class GameWorld {
                 setForeMap(x, y, 0);
                 mMobsController.addMob(FallingSand.class, x * 16, y * 16);
                 updateBlock(x, y - 1);
-            }
+            }   
         }
 
         if (getForeMap(x, y) == 11) {
@@ -245,4 +252,8 @@ public class GameWorld {
         mGameFluidsThread.start();
     }
 
+    @Override
+    public void dispose() {
+        mGameFluidsThread.interrupt();
+    }
 }
\ No newline at end of file
index 4c9b9b23f68a1bfb823e44a1baffb087084a4b1b..cc02aea03f2dff4af2151175d451cb3c751c7f23 100644 (file)
@@ -3,13 +3,19 @@ package ru.deadsoftware.cavedroid.game;
 import com.badlogic.gdx.math.RandomXS128;
 import com.badlogic.gdx.utils.TimeUtils;
 
+import javax.annotation.CheckForNull;
+
 class WorldGen {
 
+    @CheckForNull
     private static RandomXS128 rand;
     private static long seed;
 
+    @CheckForNull
     private static int[][] foreMap, backMap;
+    @CheckForNull
     private static int[] hMap;
+    @CheckForNull
     private static int[] bMap; //biomes, 0-plains, 1-desert
 
     public static long getSeed() {
@@ -57,12 +63,14 @@ class WorldGen {
     }
 
     private static void genCactus(int x, int y) {
+        assert foreMap != null;
         foreMap[x][y] = 59;
         foreMap[x][y - 1] = 59;
         foreMap[x][y - 2] = 59;
     }
 
     private static void genOak(int x, int y) {
+        assert foreMap != null && backMap != null;
         backMap[x][y] = 15;
         backMap[x][y - 1] = 15;
         backMap[x][y - 2] = 15;
@@ -183,16 +191,16 @@ class WorldGen {
     }
 
     static int[][] getForeMap() {
+        assert foreMap != null;
         return foreMap;
     }
 
     static int[][] getBackMap() {
+        assert backMap != null;
         return backMap;
     }
 
     static void clear() {
-        foreMap = null;
-        backMap = null;
         hMap = null;
         bMap = null;
     }
index 91dfae55e90823ce7fdc91aa6f919835edc6e58c..0f765925bc1679bed83830f29011a5f0bd88def8 100644 (file)
@@ -35,11 +35,11 @@ public abstract class Mob extends Rectangle implements Serializable {
     private boolean mFlyMode;
 
     /**
-     * @param x      in pixels
-     * @param y      in pixels
-     * @param width  in pixels
-     * @param height in pixels
-     * @param mDirection    Direction in which mob is looking
+     * @param x          in pixels
+     * @param y          in pixels
+     * @param width      in pixels
+     * @param height     in pixels
+     * @param mDirection Direction in which mob is looking
      */
     protected Mob(float x, float y, float width, float height, Direction mDirection, Type type) {
         super(x, y, width, height);
index 915ce25603a42f8dcdf76e201899b345a7aa3b4c..cda54ee9c04678109cc15f9586f81d9e00b91301 100644 (file)
@@ -4,11 +4,12 @@ import com.badlogic.gdx.Gdx;
 import ru.deadsoftware.cavedroid.game.GameScope;
 
 import javax.inject.Inject;
+import java.io.Serializable;
 import java.util.Iterator;
 import java.util.LinkedList;
 
 @GameScope
-public class MobsController {
+public class MobsController implements Serializable {
 
     public interface Callback {
         void run(Mob mob);
index c71a37ed04cab439136c9850da947fb7166ad40f..0e4c6592abe3badac802872be953ab84c68b2324 100644 (file)
@@ -3,10 +3,12 @@ package ru.deadsoftware.cavedroid.game.objects;
 import ru.deadsoftware.cavedroid.game.GameScope;
 
 import javax.inject.Inject;
+import java.io.Serializable;
+import java.util.Iterator;
 import java.util.LinkedList;
 
 @GameScope
-public class DropController {
+public class DropController implements Serializable {
 
     public interface Callback {
         void run(Drop drop);
@@ -30,4 +32,8 @@ public class DropController {
         mDrops.forEach(callback::run);
     }
 
+    public Iterator<Drop> getIterator() {
+        return mDrops.iterator();
+    }
+
 }
diff --git a/core/src/ru/deadsoftware/cavedroid/menu/MenuComponent.java b/core/src/ru/deadsoftware/cavedroid/menu/MenuComponent.java
new file mode 100644 (file)
index 0000000..5674368
--- /dev/null
@@ -0,0 +1,10 @@
+package ru.deadsoftware.cavedroid.menu;
+
+import dagger.Component;
+import ru.deadsoftware.cavedroid.MainComponent;
+
+@MenuScope
+@Component(dependencies = MainComponent.class)
+public interface MenuComponent {
+    MenuProc getMenuProc();
+}
index 8bc9dd6615f37fec87e79aa0acda38bdd4bb1ac4..f96d4d42756545c2d13cfc20de9a74655f986c15 100644 (file)
@@ -3,30 +3,69 @@ package ru.deadsoftware.cavedroid.menu;
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.utils.ObjectMap;
 import ru.deadsoftware.cavedroid.CaveGame;
-import ru.deadsoftware.cavedroid.game.GameScreen;
+import ru.deadsoftware.cavedroid.MainConfig;
 import ru.deadsoftware.cavedroid.menu.objects.Button;
 import ru.deadsoftware.cavedroid.menu.submenus.Menu;
 import ru.deadsoftware.cavedroid.menu.submenus.MenuMain;
 import ru.deadsoftware.cavedroid.menu.submenus.MenuNewGame;
 import ru.deadsoftware.cavedroid.misc.Renderer;
-import ru.deadsoftware.cavedroid.misc.states.AppState;
-import ru.deadsoftware.cavedroid.misc.states.GameState;
-import ru.deadsoftware.cavedroid.misc.states.MenuState;
+
+import javax.inject.Inject;
 
 import static ru.deadsoftware.cavedroid.misc.Assets.*;
 
+@MenuScope
 public class MenuProc extends Renderer {
 
-    private MenuMain mainMenu;
-    private MenuNewGame newGameMenu;
+    public class Input {
+        private void startNewGame(int gameMode) {
+            mMainConfig.getCaveGame().newGame();
+        }
+
+        public void newGameClicked() {
+            mCurrentMenu = mMenuNewGame;
+        }
 
-    private Menu currentMenu;
+        public void loadGameClicked() {
+            mMainConfig.getCaveGame().loadGame();
+        }
+
+        public void quitClicked() {
+            Gdx.app.exit();
+        }
 
-    public MenuProc(int width) {
-        super(width, width * Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
-        mainMenu = new MenuMain(getWidth(), getHeight(), this::drawButton);
-        newGameMenu = new MenuNewGame(getWidth(), getHeight(), this::drawButton);
-        currentMenu = mainMenu;
+        public void survivalClicked() {
+            startNewGame(0);
+        }
+
+        public void creativeClicked() {
+            startNewGame(1);
+        }
+
+        public void backClicked() {
+            mCurrentMenu = mMenuMain;
+        }
+    }
+
+    private final MainConfig mMainConfig;
+
+    private final MenuMain mMenuMain;
+    private final MenuNewGame mMenuNewGame;
+
+    private Menu mCurrentMenu;
+
+    @Inject
+    public MenuProc(MainConfig mainConfig) {
+        super(mainConfig.getWidth(), mainConfig.getHeight());
+
+        mMainConfig = mainConfig;
+
+        Input menuInput = new Input();
+
+        mMenuMain = new MenuMain(getWidth(), getHeight(), this::drawButton, mainConfig, menuInput);
+        mMenuNewGame = new MenuNewGame(getWidth(), getHeight(), this::drawButton, mainConfig, menuInput);
+
+        mCurrentMenu = mMenuMain;
     }
 
     private void drawButton(Button button) {
@@ -37,32 +76,11 @@ public class MenuProc extends Renderer {
                 (button.getY() + button.getHeight() / 2) - (float) getStringHeight(button.getLabel()) / 2);
     }
 
-    private void update() {
-//        switch (CaveGame.MENU_STATE) {
-//            case MAIN:
-//                currentMenu = mainMenu;
-//                break;
-//            case NEW_GAME:
-//                currentMenu = newGameMenu;
-//                break;
-//            case LOADING:
-//                drawString("Generating World...");
-//                CaveGame.APP_STATE = AppState.GAME;
-//                CaveGame.GAME_STATE = GameState.PLAY;
-//                break;
-//            case SAVING:
-//                drawString("Saving Game...");
-//                CaveGame.APP_STATE = AppState.MENU;
-//                CaveGame.MENU_STATE = MenuState.MAIN;
-//                break;
-//        }
-    }
-
     @Override
     public boolean touchUp(int screenX, int screenY, int pointer, int mb) {
         screenX *= getWidth() / Gdx.graphics.getWidth();
         screenY *= getHeight() / Gdx.graphics.getHeight();
-        for (ObjectMap.Entry<String, Button> entry : currentMenu.getButtons()) {
+        for (ObjectMap.Entry<String, Button> entry : mCurrentMenu.getButtons()) {
             Button button = entry.value;
             if (button.getRect().contains(screenX, screenY)) {
                 if (button.getType() > 0) {
@@ -76,11 +94,14 @@ public class MenuProc extends Renderer {
 
     @Override
     public void render(float delta) {
-        update();
         spriter.begin();
-        currentMenu.draw(spriter);
+        mCurrentMenu.draw(spriter);
         drawString("CaveDroid " + CaveGame.VERSION, 0,
                 getHeight() - getStringHeight("CaveDroid " + CaveGame.VERSION) * 1.5f);
         spriter.end();
     }
+
+    public void reset() {
+        mCurrentMenu = mMenuMain;
+    }
 }
diff --git a/core/src/ru/deadsoftware/cavedroid/menu/MenuScope.java b/core/src/ru/deadsoftware/cavedroid/menu/MenuScope.java
new file mode 100644 (file)
index 0000000..3198af6
--- /dev/null
@@ -0,0 +1,10 @@
+package ru.deadsoftware.cavedroid.menu;
+
+import javax.inject.Scope;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Scope
+@Retention(RetentionPolicy.RUNTIME)
+public @interface MenuScope {
+}
diff --git a/core/src/ru/deadsoftware/cavedroid/menu/MenuScreen.java b/core/src/ru/deadsoftware/cavedroid/menu/MenuScreen.java
new file mode 100644 (file)
index 0000000..4b9c5e3
--- /dev/null
@@ -0,0 +1,57 @@
+package ru.deadsoftware.cavedroid.menu;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Screen;
+import ru.deadsoftware.cavedroid.MainConfig;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+@Singleton
+public class MenuScreen implements Screen {
+
+    private final MenuProc mMenuProc;
+
+    @Inject
+    public MenuScreen(MainConfig mainConfig) {
+        MenuComponent menuComponent = DaggerMenuComponent.builder()
+                .mainComponent(mainConfig.getMainComponent()).build();
+        mMenuProc = menuComponent.getMenuProc();
+    }
+
+    @Override
+    public void show() {
+        mMenuProc.reset();
+        Gdx.input.setInputProcessor(mMenuProc);
+    }
+
+    @Override
+    public void render(float delta) {
+        mMenuProc.render(delta);
+    }
+
+    @Override
+    public void resize(int width, int height) {
+
+    }
+
+    @Override
+    public void pause() {
+
+    }
+
+    @Override
+    public void resume() {
+
+    }
+
+    @Override
+    public void hide() {
+
+    }
+
+    @Override
+    public void dispose() {
+
+    }
+}
index 2a89e04608f3064a170bdb69c363a99deb84d23d..9f8df4c25d96d498c6019c1e123ef99a61e05c6e 100644 (file)
@@ -6,8 +6,8 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.graphics.g2d.TextureRegion;
 import com.badlogic.gdx.utils.ArrayMap;
 import com.badlogic.gdx.utils.JsonValue;
-import ru.deadsoftware.cavedroid.CaveGame;
-import ru.deadsoftware.cavedroid.game.GameScreen;
+import ru.deadsoftware.cavedroid.MainConfig;
+import ru.deadsoftware.cavedroid.menu.MenuProc;
 import ru.deadsoftware.cavedroid.menu.objects.Button;
 import ru.deadsoftware.cavedroid.menu.objects.ButtonEventListener;
 import ru.deadsoftware.cavedroid.menu.objects.ButtonRenderer;
@@ -17,10 +17,13 @@ import java.util.HashMap;
 
 public abstract class Menu {
 
-    private ButtonRenderer buttonRenderer;
+    protected final MainConfig mMainConfig;
+    protected final MenuProc.Input mMenuInput;
 
-    private float width;
-    private float height;
+    private final ButtonRenderer mButtonRenderer;
+
+    private final float mWidth;
+    private final float mHeight;
 
     /**
      * {@link ArrayMap} of {@link Button Buttons} of this menu screen
@@ -32,10 +35,12 @@ public abstract class Menu {
      * @param height         Viewport height
      * @param buttonRenderer {@link ButtonRenderer} that will draw the buttons of this menu
      */
-    Menu(float width, float height, ButtonRenderer buttonRenderer) {
-        this.width = width;
-        this.height = height;
-        this.buttonRenderer = buttonRenderer;
+    Menu(float width, float height, ButtonRenderer buttonRenderer, MainConfig mainConfig, MenuProc.Input menuInput) {
+        mWidth = width;
+        mHeight = height;
+        mButtonRenderer = buttonRenderer;
+        mMainConfig = mainConfig;
+        mMenuInput = menuInput;
         initButtons();
     }
 
@@ -61,11 +66,11 @@ public abstract class Menu {
         }
         HashMap<String, ButtonEventListener> eventListeners = getButtonEventListeners();
         JsonValue json = Assets.jsonReader.parse(jsonFile);
-        int y = (int) height / 4;
+        int y = (int) mHeight / 4;
         for (JsonValue key = json.child(); key != null; key = key.next(), y += Button.HEIGHT + 10) {
             buttons.put(key.name(),
                     new Button(Assets.getStringFromJson(key, "label", ""),
-                            (int) width / 2 - Button.WIDTH / 2,
+                            (int) mWidth / 2 - Button.WIDTH / 2,
                             Assets.getIntFromJson(key, "y", y),
                             Assets.getIntFromJson(key, "type", Button.NORMAL),
                             eventListeners.containsKey(key.name()) ? eventListeners.get(key.name()) : () -> {
@@ -82,15 +87,15 @@ public abstract class Menu {
         TextureRegion background = Assets.textureRegions.get("background");
         TextureRegion gamelogo = Assets.textureRegions.get("gamelogo");
 
-        for (int x = 0; x <= width / 16; x++) {
-            for (int y = 0; y <= height / 16; y++) {
+        for (int x = 0; x <= mWidth / 16; x++) {
+            for (int y = 0; y <= mHeight / 16; y++) {
                 spriter.draw(background, x * 16, y * 16);
             }
         }
-        spriter.draw(gamelogo, width / 2 - (float) gamelogo.getRegionWidth() / 2, 8);
+        spriter.draw(gamelogo, mWidth / 2 - (float) gamelogo.getRegionWidth() / 2, 8);
 
-        float inputX = Gdx.input.getX() * width / Gdx.graphics.getWidth();
-        float inputY = Gdx.input.getY() * height / Gdx.graphics.getHeight();
+        float inputX = Gdx.input.getX() * mWidth / Gdx.graphics.getWidth();
+        float inputY = Gdx.input.getY() * mHeight / Gdx.graphics.getHeight();
         for (Button button : buttons.values()) {
             if (button.getType() > 0) {
                 if (button.getRect().contains(inputX, inputY) && (/*!CaveGame.TOUCH || */Gdx.input.isTouched())) {
@@ -99,7 +104,7 @@ public abstract class Menu {
                     button.setType(1);
                 }
             }
-            button.draw(buttonRenderer);
+            button.draw(mButtonRenderer);
         }
     }
 
diff --git a/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuInput.java b/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuInput.java
deleted file mode 100644 (file)
index eccf9af..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-package ru.deadsoftware.cavedroid.menu.submenus;
-
-import com.badlogic.gdx.Gdx;
-import ru.deadsoftware.cavedroid.CaveGame;
-import ru.deadsoftware.cavedroid.game.GameSaver;
-import ru.deadsoftware.cavedroid.misc.states.AppState;
-import ru.deadsoftware.cavedroid.misc.states.MenuState;
-
-class MenuInput {
-
-    private static void startNewGame(int gameMode) {
-//        GP = new GameProc();
-//        GP.player.respawn();
-//        GameSaver.save(GP);
-//        CaveGame.APP_STATE = AppState.LOAD;
-    }
-
-    static void newGameClicked() {
-//        CaveGame.MENU_STATE = MenuState.NEW_GAME;
-    }
-
-    static void loadGameClicked() {
-//        CaveGame.APP_STATE = AppState.LOAD;
-//        GP = GameSaver.load();
-    }
-
-    static void quitClicked() {
-        Gdx.app.exit();
-    }
-
-    static void survivalClicked() {
-        startNewGame(0);
-    }
-
-    static void creativeClicked() {
-        startNewGame(1);
-    }
-
-    static void backClicked() {
-//        CaveGame.MENU_STATE = MenuState.MAIN;
-    }
-
-}
index 10db012c8efe278812fd3765f8e9be47acc0a7fe..d2dedd23c351f3fc8e91626375e55a0f3b3fd90d 100644 (file)
@@ -1,7 +1,9 @@
 package ru.deadsoftware.cavedroid.menu.submenus;
 
 import com.badlogic.gdx.Gdx;
+import ru.deadsoftware.cavedroid.MainConfig;
 import ru.deadsoftware.cavedroid.game.GameSaver;
+import ru.deadsoftware.cavedroid.menu.MenuProc;
 import ru.deadsoftware.cavedroid.menu.objects.Button;
 import ru.deadsoftware.cavedroid.menu.objects.ButtonEventListener;
 import ru.deadsoftware.cavedroid.menu.objects.ButtonRenderer;
@@ -10,23 +12,23 @@ import java.util.HashMap;
 
 public class MenuMain extends Menu {
 
-    public MenuMain(float width, float height, ButtonRenderer buttonRenderer) {
-        super(width, height, buttonRenderer);
+    public MenuMain(float width, float height, ButtonRenderer buttonRenderer, MainConfig mainConfig, MenuProc.Input menuInput) {
+        super(width, height, buttonRenderer, mainConfig, menuInput);
     }
 
     @Override
     protected HashMap<String, ButtonEventListener> getButtonEventListeners() {
         HashMap<String, ButtonEventListener> map = new HashMap<>();
-        map.put("new_game", MenuInput::newGameClicked);
-        map.put("load_game", MenuInput::loadGameClicked);
-        map.put("quit", MenuInput::quitClicked);
+        map.put("new_game", mMenuInput::newGameClicked);
+        map.put("load_game", mMenuInput::loadGameClicked);
+        map.put("quit", mMenuInput::quitClicked);
         return map;
     }
 
     @Override
     protected void initButtons() {
         loadButtonsFromJson(Gdx.files.internal("json/menu_main_buttons.json"));
-        if (GameSaver.exists()) {
+        if (GameSaver.exists(mMainConfig)) {
             getButtons().get("load_game").setType(Button.NORMAL);
         }
     }
index 6e6b66656519dff6449b1aaac54ec616c4349d38..2c3b38bee9b041a5ae16fd4e2e5a4d1d707aacad 100644 (file)
@@ -1,6 +1,8 @@
 package ru.deadsoftware.cavedroid.menu.submenus;
 
 import com.badlogic.gdx.Gdx;
+import ru.deadsoftware.cavedroid.MainConfig;
+import ru.deadsoftware.cavedroid.menu.MenuProc;
 import ru.deadsoftware.cavedroid.menu.objects.ButtonEventListener;
 import ru.deadsoftware.cavedroid.menu.objects.ButtonRenderer;
 
@@ -8,16 +10,16 @@ import java.util.HashMap;
 
 public class MenuNewGame extends Menu {
 
-    public MenuNewGame(float width, float height, ButtonRenderer buttonRenderer) {
-        super(width, height, buttonRenderer);
+    public MenuNewGame(float width, float height, ButtonRenderer buttonRenderer, MainConfig mainConfig, MenuProc.Input menuInput) {
+        super(width, height, buttonRenderer, mainConfig, menuInput);
     }
 
     @Override
     protected HashMap<String, ButtonEventListener> getButtonEventListeners() {
         HashMap<String, ButtonEventListener> map = new HashMap<>();
-        map.put("survival", MenuInput::survivalClicked);
-        map.put("creative", MenuInput::creativeClicked);
-        map.put("back", MenuInput::backClicked);
+        map.put("survival", mMenuInput::survivalClicked);
+        map.put("creative", mMenuInput::creativeClicked);
+        map.put("back", mMenuInput::backClicked);
         return map;
     }
 
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/states/AppState.java b/core/src/ru/deadsoftware/cavedroid/misc/states/AppState.java
deleted file mode 100644 (file)
index e706403..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-package ru.deadsoftware.cavedroid.misc.states;
-
-public enum AppState {
-    MENU,
-    GAME,
-    SAVE,
-    LOAD
-}
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/states/GameState.java b/core/src/ru/deadsoftware/cavedroid/misc/states/GameState.java
deleted file mode 100644 (file)
index f2ceb44..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package ru.deadsoftware.cavedroid.misc.states;
-
-public enum GameState {
-    PLAY,
-    CREATIVE_INV,
-    PAUSE
-}
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/states/MenuState.java b/core/src/ru/deadsoftware/cavedroid/misc/states/MenuState.java
deleted file mode 100644 (file)
index 69c39c4..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-package ru.deadsoftware.cavedroid.misc.states;
-
-public enum MenuState {
-    MAIN,
-    NEW_GAME,
-    LOADING,
-    SAVING
-}
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/states/package-info.java b/core/src/ru/deadsoftware/cavedroid/misc/states/package-info.java
deleted file mode 100644 (file)
index 23fc406..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-@NonnullByDefault
-package ru.deadsoftware.cavedroid.misc.states;
-
-import ru.deadsoftware.cavedroid.misc.annotations.NonnullByDefault;
\ No newline at end of file