From 7eb1beae9fd79a07783bd850a5d739a9813797dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 13 Sep 2018 18:55:07 +0200 Subject: ZProject -> GdxBoardTest --- core/src/ch/asynk/zproject/Assets.java | 2 +- core/src/ch/asynk/zproject/GameBoard.java | 4 +- core/src/ch/asynk/zproject/GameHud.java | 2 +- core/src/ch/asynk/zproject/GameScreen.java | 22 +++---- core/src/ch/asynk/zproject/GdxBoardTest.java | 83 +++++++++++++++++++++++++++ core/src/ch/asynk/zproject/LoadingScreen.java | 26 ++++----- core/src/ch/asynk/zproject/ZProject.java | 83 --------------------------- 7 files changed, 111 insertions(+), 111 deletions(-) create mode 100644 core/src/ch/asynk/zproject/GdxBoardTest.java delete mode 100644 core/src/ch/asynk/zproject/ZProject.java diff --git a/core/src/ch/asynk/zproject/Assets.java b/core/src/ch/asynk/zproject/Assets.java index 2cff430..3673bf4 100644 --- a/core/src/ch/asynk/zproject/Assets.java +++ b/core/src/ch/asynk/zproject/Assets.java @@ -41,7 +41,7 @@ public class Assets extends ch.asynk.gdx.board.engine.Assets @Override public void dispose() { - ZProject.debug("diagnostics:\n" + getDiagnostics() ); + GdxBoardTest.debug("diagnostics:\n" + getDiagnostics() ); clear(); super.dispose(); } diff --git a/core/src/ch/asynk/zproject/GameBoard.java b/core/src/ch/asynk/zproject/GameBoard.java index 489e00d..b6f2331 100644 --- a/core/src/ch/asynk/zproject/GameBoard.java +++ b/core/src/ch/asynk/zproject/GameBoard.java @@ -38,9 +38,9 @@ public class GameBoard implements Disposable, Touchable @Override public boolean touch(float x, float y) { board.toBoard(x, y, v); - ZProject.debug("BoardGame", String.format("touchDown [%d;%d] => [%d;%d]", (int)x, (int)y, (int)v.x, (int)v.y)); + GdxBoardTest.debug("BoardGame", String.format("touchDown [%d;%d] => [%d;%d]", (int)x, (int)y, (int)v.x, (int)v.y)); board.centerOf((int)v.x, (int)v.y, v); - ZProject.debug("BoardGame", String.format(" => [%d;%d]", (int)v.x, (int)v.y)); + GdxBoardTest.debug("BoardGame", String.format(" => [%d;%d]", (int)v.x, (int)v.y)); return true; } diff --git a/core/src/ch/asynk/zproject/GameHud.java b/core/src/ch/asynk/zproject/GameHud.java index a28f4ea..62a1046 100644 --- a/core/src/ch/asynk/zproject/GameHud.java +++ b/core/src/ch/asynk/zproject/GameHud.java @@ -50,7 +50,7 @@ public class GameHud implements Disposable, Touchable @Override public boolean touch(float x, float y) { if (root.touch(x, y)) { - ZProject.debug("GameHud", String.format("touchDown : %f %f", x, y)); + GdxBoardTest.debug("GameHud", String.format("touchDown : %f %f", x, y)); if (root.touched() == this.next) onNext(); return true; diff --git a/core/src/ch/asynk/zproject/GameScreen.java b/core/src/ch/asynk/zproject/GameScreen.java index e3cc255..4be7fae 100644 --- a/core/src/ch/asynk/zproject/GameScreen.java +++ b/core/src/ch/asynk/zproject/GameScreen.java @@ -23,7 +23,7 @@ public class GameScreen implements Screen private static final boolean DEBUG = true; - private final ZProject zproject; + private final GdxBoardTest app; private final GameHud hud; private final GameBoard board; private final Camera camera; @@ -59,11 +59,11 @@ public class GameScreen implements Screen } private State state; - public GameScreen(final ZProject zproject) + public GameScreen(final GdxBoardTest app) { - this.zproject = zproject; - this.hud = new GameHud(zproject.assets, State.UI, () -> nextState()); - this.board = new GameBoard(zproject.assets); + this.app = app; + this.hud = new GameHud(app.assets, State.UI, () -> nextState()); + this.board = new GameBoard(app.assets); this.batch = new SpriteBatch(); this.camera = new Camera(10, board.getWidth(), board.getHeight(), 1.0f, 0.3f, false); Gdx.input.setInputProcessor(getMultiplexer(this)); @@ -122,14 +122,14 @@ public class GameScreen implements Screen @Override public void resize(int width, int height) { if (paused) return; - ZProject.debug("GameScreen", String.format("resize (%d,%d)",width, height)); + GdxBoardTest.debug("GameScreen", String.format("resize (%d,%d)",width, height)); camera.updateViewport(width, height); hud.resize(camera.getHud().width, camera.getHud().height); } @Override public void dispose() { - ZProject.debug("GameScreen", "dispose()"); + GdxBoardTest.debug("GameScreen", "dispose()"); batch.dispose(); if (debugShapes != null) debugShapes.dispose(); hud.dispose(); @@ -138,23 +138,23 @@ public class GameScreen implements Screen @Override public void show() { - ZProject.debug("GameScreen", "show()"); + GdxBoardTest.debug("GameScreen", "show()"); } @Override public void hide() { - ZProject.debug("GameScreen", "hide()"); + GdxBoardTest.debug("GameScreen", "hide()"); } @Override public void pause() { - ZProject.debug("pause() "); + GdxBoardTest.debug("pause() "); paused = true; } @Override public void resume() { - ZProject.debug("resume() "); + GdxBoardTest.debug("resume() "); paused = false; resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); } 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); + } +} diff --git a/core/src/ch/asynk/zproject/LoadingScreen.java b/core/src/ch/asynk/zproject/LoadingScreen.java index 6fe3996..00c41c9 100644 --- a/core/src/ch/asynk/zproject/LoadingScreen.java +++ b/core/src/ch/asynk/zproject/LoadingScreen.java @@ -11,7 +11,7 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; public class LoadingScreen implements Screen { - private final ZProject zproject; + private final GdxBoardTest app; private final SpriteBatch batch; private final Color c; private final OrthographicCamera camera; @@ -38,9 +38,9 @@ public class LoadingScreen implements Screen } private LoadAction onLoaded; - public LoadingScreen(final ZProject zproject, LoadAction startLoading, LoadAction onLoaded) + public LoadingScreen(final GdxBoardTest app, LoadAction startLoading, LoadAction onLoaded) { - this.zproject = zproject; + this.app = app; this.onLoaded = onLoaded; this.batch = new SpriteBatch(); this.c = batch.getColor(); @@ -50,7 +50,7 @@ public class LoadingScreen implements Screen this.camera.setToOrtho(false, w, h); this.camera.update(); this.paused = false; - atlas = zproject.assets.getAtlas(zproject.assets.LOADING); + atlas = app.assets.getAtlas(app.assets.LOADING); bar = atlas.findRegion("bar"); border = atlas.findRegion("border"); loading = atlas.findRegion("loading"); @@ -74,12 +74,12 @@ public class LoadingScreen implements Screen if (paused) return; if (!isLoaded) { - if (zproject.assets.update()) { - ZProject.debug("LoadingScreen", "assets loaded"); + if (app.assets.update()) { + GdxBoardTest.debug("LoadingScreen", "assets loaded"); isLoaded = true; percent = 1f; } else { - percent = zproject.assets.getProgress(); + percent = app.assets.getProgress(); } } @@ -129,7 +129,7 @@ public class LoadingScreen implements Screen @Override public void resize(int width, int height) { if (paused) return; - ZProject.debug("LoadingScreen", String.format("resize (%d,%d)",width, height)); + GdxBoardTest.debug("LoadingScreen", String.format("resize (%d,%d)",width, height)); this.camera.setToOrtho(false, width, height); this.camera.update(); computeCoords(width, height); @@ -137,29 +137,29 @@ public class LoadingScreen implements Screen @Override public void dispose() { - ZProject.debug("LoadingScreen", "dispose()"); + GdxBoardTest.debug("LoadingScreen", "dispose()"); batch.dispose(); } @Override public void show() { - ZProject.debug("LoadingScreen", "show()"); + GdxBoardTest.debug("LoadingScreen", "show()"); } @Override public void hide() { - ZProject.debug("LoadingScreen", "hide()"); + GdxBoardTest.debug("LoadingScreen", "hide()"); } @Override public void pause() { paused = true; - ZProject.debug("pause() "); + GdxBoardTest.debug("pause() "); } @Override public void resume() { - ZProject.debug("resume() "); + GdxBoardTest.debug("resume() "); resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); paused = false; } diff --git a/core/src/ch/asynk/zproject/ZProject.java b/core/src/ch/asynk/zproject/ZProject.java deleted file mode 100644 index 8f1ff0d..0000000 --- a/core/src/ch/asynk/zproject/ZProject.java +++ /dev/null @@ -1,83 +0,0 @@ -package ch.asynk.gdx.board; - -import com.badlogic.gdx.Game; -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.Screen; - -public class ZProject extends Game -{ - public static final String DOM = "ZProject"; - - 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); - } -} -- cgit v1.1-2-g2b99