diff options
Diffstat (limited to 'core/src/ch/asynk/zproject/GdxBoardTest.java')
-rw-r--r-- | core/src/ch/asynk/zproject/GdxBoardTest.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/core/src/ch/asynk/zproject/GdxBoardTest.java b/core/src/ch/asynk/zproject/GdxBoardTest.java new file mode 100644 index 0000000..43ff6aa --- /dev/null +++ b/core/src/ch/asynk/zproject/GdxBoardTest.java @@ -0,0 +1,83 @@ +package ch.asynk.gdx.board; + +import com.badlogic.gdx.Game; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Screen; + +public class GdxBoardTest extends Game +{ + public static final String DOM = "GdxBoardTest"; + + private enum State + { + NONE, + LOADING, + GAME, + } + private State state; + + public final Assets assets = new Assets(); + + @Override public void create() + { + this.state = State.NONE; + Gdx.app.setLogLevel(Gdx.app.LOG_DEBUG); + debug(String.format("create() [%d;%d] %f", Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Gdx.graphics.getDensity())); + switchToLoading(); + } + + @Override public void dispose() + { + switchToNone(); + assets.dispose(); + } + + public static void error(String msg) + { + Gdx.app.error(DOM, msg); + } + + public static void debug(String msg) + { + Gdx.app.debug(DOM, msg); + } + + public static void debug(String from, String msg) + { + Gdx.app.debug(DOM, String.format("%s : %s", from, msg)); + } + + private void switchTo(Screen nextScreen, State nextState) + { + if (state == nextState) { + error("switch from and to " + state); + return; + } + switch(state) { + case LOADING: assets.unloadLoading(); break; + case GAME: assets.unloadGame(); break; + } + if (state != State.NONE) { + getScreen().dispose(); + } + setScreen(nextScreen); + this.state = nextState; + } + + public void switchToNone() + { + switchTo(null, State.NONE); + } + + public void switchToLoading() + { + assets.loadLoading(); + assets.finishLoading(); + switchTo(new LoadingScreen(this, () -> assets.loadGame(), () -> switchToGame()), State.LOADING); + } + + public void switchToGame() + { + switchTo(new GameScreen(this), State.GAME); + } +} |