Compare commits
6 Commits
main
...
assest_man
| Author | SHA1 | Date | |
|---|---|---|---|
| 474b40018c | |||
| 5f121ad315 | |||
| 93953cc0b3 | |||
| ae1eba3ff6 | |||
| 213dcf3a6a | |||
| 3d4071e267 |
@@ -1,42 +1,36 @@
|
|||||||
package com.ghost.technic;
|
package com.ghost.technic;
|
||||||
|
|
||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.Game;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Screen;
|
import com.badlogic.gdx.Screen;
|
||||||
import com.badlogic.gdx.assets.AssetManager;
|
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Window;
|
import com.ghost.technic.asset.AssetService;
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
import com.ghost.technic.screen.BattlefieldScreen;
|
||||||
import com.badlogic.gdx.utils.ScreenUtils;
|
|
||||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
|
||||||
import com.ghost.technic.server.Player;
|
import com.ghost.technic.server.Player;
|
||||||
import com.ghost.technic.server.game.GameActionService;
|
import com.ghost.technic.server.game.GameActionService;
|
||||||
import com.ghost.technic.server.game.GameState;
|
import com.ghost.technic.server.game.GameState;
|
||||||
import com.ghost.technic.server.game.event.EventBus;
|
import com.ghost.technic.server.game.event.EventBus;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/** {@link com.badlogic.gdx.ApplicationListener} implementation shared by all platforms. */
|
/** {@link com.badlogic.gdx.ApplicationListener} implementation shared by all platforms. */
|
||||||
public class TechnicClient extends ApplicationAdapter {
|
public class TechnicClient extends Game {
|
||||||
|
|
||||||
private Skin skin;
|
private Skin skin;
|
||||||
private Screen currentScreen;
|
private AssetService assetService;
|
||||||
private AssetManager assetManager;
|
|
||||||
private GameState gameState;
|
private GameState gameState;
|
||||||
private GameActionService gameActionService;
|
private GameActionService gameActionService;
|
||||||
|
|
||||||
|
private final Map<Class<? extends Screen>, Screen> screenCache = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
|
|
||||||
skin = new Skin(Gdx.files.internal("ui/uiskin.json"));
|
skin = new Skin(Gdx.files.internal("ui/uiskin.json"));
|
||||||
assetManager = new AssetManager();
|
assetService = new AssetService(new InternalFileHandleResolver());
|
||||||
assetManager.load("cards/cards.atlas", TextureAtlas.class);
|
|
||||||
assetManager.finishLoading();
|
|
||||||
Gdx.app.log("TechnicClient | INFO", "Finished loading assets!");
|
|
||||||
|
|
||||||
gameState = new GameState(new EventBus());
|
gameState = new GameState(new EventBus());
|
||||||
gameActionService = new GameActionService(gameState);
|
gameActionService = new GameActionService(gameState);
|
||||||
@@ -46,28 +40,31 @@ public class TechnicClient extends ApplicationAdapter {
|
|||||||
gameState.setPlayers(playerOne, playerTwo);
|
gameState.setPlayers(playerOne, playerTwo);
|
||||||
gameState.setup();
|
gameState.setup();
|
||||||
|
|
||||||
currentScreen = new BattlefieldScreen(skin); // store reference
|
// screen
|
||||||
currentScreen.show();
|
addScreen(new BattlefieldScreen(skin));
|
||||||
|
setScreen(BattlefieldScreen.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void addScreen(Screen screen) {
|
||||||
public void render() {
|
screenCache.put(screen.getClass(), screen);
|
||||||
if (currentScreen != null) {
|
|
||||||
currentScreen.render(Gdx.graphics.getDeltaTime());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setScreen(Class<? extends Screen> screenClass) {
|
||||||
public void resize(int width, int height) {
|
var screen = screenCache.get(screenClass);
|
||||||
if (currentScreen != null) {
|
if (screen == null) {
|
||||||
currentScreen.resize(width, height);
|
throw new GdxRuntimeException("Screen " + screenClass.getSimpleName() + " not found in cache");
|
||||||
}
|
}
|
||||||
|
super.setScreen(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeScreen(Screen screen) {
|
||||||
|
screenCache.remove(screen.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
if (currentScreen != null) {
|
for (Screen screen : screenCache.values()) {
|
||||||
currentScreen.dispose();
|
screen.dispose();
|
||||||
}
|
}
|
||||||
skin.dispose();
|
skin.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
7
core/src/main/java/com/ghost/technic/asset/Asset.java
Normal file
7
core/src/main/java/com/ghost/technic/asset/Asset.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package com.ghost.technic.asset;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.assets.AssetDescriptor;
|
||||||
|
|
||||||
|
public interface Asset<T> {
|
||||||
|
AssetDescriptor<T> getDescriptor();
|
||||||
|
}
|
||||||
51
core/src/main/java/com/ghost/technic/asset/AssetService.java
Normal file
51
core/src/main/java/com/ghost/technic/asset/AssetService.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package com.ghost.technic.asset;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.assets.AssetManager;
|
||||||
|
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
|
||||||
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
|
|
||||||
|
public class AssetService implements Disposable {
|
||||||
|
private final AssetManager assetManager;
|
||||||
|
|
||||||
|
public AssetService(FileHandleResolver fileHandleResolver) {
|
||||||
|
this.assetManager = new AssetManager(fileHandleResolver);
|
||||||
|
|
||||||
|
// old technic code
|
||||||
|
// this.assetManager.load("cards/cards.atlas", TextureAtlas.class);
|
||||||
|
// this.assetManager.finishLoading();
|
||||||
|
// Gdx.app.log("Technic | INFO", "Finished loading assets!");
|
||||||
|
// this.cardSkin.addRegions(assetManager.get("cards/cards.atlas", TextureAtlas.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T load(Asset<T> asset) {
|
||||||
|
this.assetManager.load(asset.getDescriptor());
|
||||||
|
this.assetManager.finishLoading();
|
||||||
|
return this.assetManager.get(asset.getDescriptor());
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void unload(Asset<T> asset) {
|
||||||
|
this.assetManager.unload(asset.getDescriptor().fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void queue(Asset<T> asset) {
|
||||||
|
this.assetManager.load(asset.getDescriptor());
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T get(Asset<T> asset) {
|
||||||
|
return this.assetManager.get(asset.getDescriptor());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean update() {
|
||||||
|
return this.assetManager.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void debugDiagnostics() {
|
||||||
|
Gdx.app.debug("AssetService", this.assetManager.getDiagnostics());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
this.assetManager.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.ghost.technic;
|
package com.ghost.technic.screen;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Screen;
|
import com.badlogic.gdx.Screen;
|
||||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||||
import com.badlogic.gdx.utils.ScreenUtils;
|
import com.badlogic.gdx.utils.ScreenUtils;
|
||||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||||
|
import com.ghost.technic.BattlefieldView;
|
||||||
|
|
||||||
public class BattlefieldScreen implements Screen {
|
public class BattlefieldScreen implements Screen {
|
||||||
|
|
||||||
Reference in New Issue
Block a user