Update Asset.java, AssetService.java, and TechnicClient.java - Wrapped AssetManager with AssetService
This commit is contained in:
@@ -3,10 +3,10 @@ package com.ghost.technic;
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
import com.ghost.technic.asset.AssetService;
|
||||
import com.ghost.technic.screen.BattlefieldScreen;
|
||||
import com.ghost.technic.server.Player;
|
||||
import com.ghost.technic.server.game.GameActionService;
|
||||
@@ -20,7 +20,7 @@ import java.util.Map;
|
||||
public class TechnicClient extends Game {
|
||||
|
||||
private Skin skin;
|
||||
private AssetManager assetManager;
|
||||
private AssetService assetService;
|
||||
private GameState gameState;
|
||||
private GameActionService gameActionService;
|
||||
|
||||
@@ -30,10 +30,7 @@ public class TechnicClient extends Game {
|
||||
public void create() {
|
||||
|
||||
skin = new Skin(Gdx.files.internal("ui/uiskin.json"));
|
||||
assetManager = new AssetManager();
|
||||
assetManager.load("cards/cards.atlas", TextureAtlas.class);
|
||||
assetManager.finishLoading();
|
||||
Gdx.app.log("TechnicClient | INFO", "Finished loading assets!");
|
||||
assetService = new AssetService(new InternalFileHandleResolver());
|
||||
|
||||
gameState = new GameState(new EventBus());
|
||||
gameActionService = new GameActionService(gameState);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user