mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
update remaining sprites to cache
This commit is contained in:
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import forge.Forge;
|
||||
import forge.adventure.util.Config;
|
||||
import forge.adventure.util.Paths;
|
||||
@@ -19,14 +20,15 @@ public class HeroListData {
|
||||
static private HeroListData instance;
|
||||
public HeroData[] heroes;
|
||||
public String avatar;
|
||||
private TextureAtlas avatarSprites;
|
||||
private TextureAtlas avatarAtlas;
|
||||
private final ObjectMap<String, Array<Sprite>> avatarSprites = new ObjectMap<>();
|
||||
|
||||
static private HeroListData read() {
|
||||
Json json = new Json();
|
||||
FileHandle handle = Config.instance().getFile(Paths.HEROES);
|
||||
if (handle.exists()) {
|
||||
instance = json.fromJson(HeroListData.class, handle);
|
||||
instance.avatarSprites = Config.instance().getAtlas(instance.avatar);
|
||||
instance.avatarAtlas = Config.instance().getAtlas(instance.avatar);
|
||||
|
||||
/*
|
||||
instance.avatarSprites.getTextures().first().setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
|
||||
@@ -47,15 +49,14 @@ public class HeroListData {
|
||||
}
|
||||
|
||||
public static TextureRegion getAvatar(int heroRace, boolean isFemale, int avatarIndex) {
|
||||
|
||||
if (instance == null)
|
||||
instance = read();
|
||||
HeroData data = instance.heroes[heroRace];
|
||||
Array<Sprite> sprites;
|
||||
if (isFemale)
|
||||
sprites = instance.avatarSprites.createSprites(data.femaleAvatar);
|
||||
else
|
||||
sprites = instance.avatarSprites.createSprites(data.maleAvatar);
|
||||
Array<Sprite> sprites = instance.avatarSprites.get(isFemale ? data.femaleAvatar : data.maleAvatar);
|
||||
if (sprites == null) {
|
||||
sprites = instance.avatarAtlas.createSprites(isFemale ? data.femaleAvatar : data.maleAvatar);
|
||||
instance.avatarSprites.put(isFemale ? data.femaleAvatar : data.maleAvatar, sprites);
|
||||
}
|
||||
avatarIndex %= sprites.size;
|
||||
if (avatarIndex < 0) {
|
||||
avatarIndex += sprites.size;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class PointOfInterest implements Serializable, SaveFileContent {
|
||||
}
|
||||
|
||||
oldMapId="";
|
||||
Array<Sprite> textureAtlas = Config.instance().getAtlas(this.data.spriteAtlas).createSprites(this.data.sprite);
|
||||
Array<Sprite> textureAtlas = Config.instance().getPOISprites(this.data);
|
||||
sprite = textureAtlas.get(spriteIndex%textureAtlas.size);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class PointOfInterest implements Serializable, SaveFileContent {
|
||||
public PointOfInterest() {
|
||||
}
|
||||
public PointOfInterest(PointOfInterestData d, Vector2 pos, Random rand) {
|
||||
Array<Sprite> textureAtlas = Config.instance().getAtlas(d.spriteAtlas).createSprites(d.sprite);
|
||||
Array<Sprite> textureAtlas = Config.instance().getPOISprites(d);
|
||||
if (textureAtlas.isEmpty()) {
|
||||
System.out.print("sprite " + d.sprite + " not found");
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public class PointOfInterest implements Serializable, SaveFileContent {
|
||||
}
|
||||
|
||||
public Vector2 getTilePosition(int tileSize) {
|
||||
return new Vector2((int) ((position.x + (sprite.getWidth() / 2)) / tileSize), (int) position.y / tileSize);
|
||||
return new Vector2(((position.x + (sprite.getWidth() / 2)) / tileSize), position.y / tileSize);
|
||||
}
|
||||
|
||||
public Rectangle getBoundingRectangle() {
|
||||
|
||||
@@ -10,10 +10,7 @@ import com.badlogic.gdx.utils.ObjectMap;
|
||||
import forge.CardStorageReader;
|
||||
import forge.Forge;
|
||||
import forge.ImageKeys;
|
||||
import forge.adventure.data.ConfigData;
|
||||
import forge.adventure.data.DifficultyData;
|
||||
import forge.adventure.data.RewardData;
|
||||
import forge.adventure.data.SettingData;
|
||||
import forge.adventure.data.*;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.CardRules;
|
||||
@@ -52,6 +49,7 @@ public class Config {
|
||||
private String Lang = "en-us";
|
||||
private final String plane;
|
||||
private ObjectMap<String, ObjectMap<String, Sprite>> atlasSprites = new ObjectMap<>();
|
||||
private ObjectMap<PointOfInterestData, Array<Sprite>> poiSprites = new ObjectMap<>();
|
||||
|
||||
static public Config instance() {
|
||||
if (currentConfig == null)
|
||||
@@ -267,6 +265,15 @@ public class Config {
|
||||
}
|
||||
return sprite;
|
||||
}
|
||||
|
||||
public Array<Sprite> getPOISprites(PointOfInterestData d) {
|
||||
Array<Sprite> sprites = poiSprites.get(d);
|
||||
if (sprites == null) {
|
||||
sprites = getAtlas(d.spriteAtlas).createSprites(d.sprite);
|
||||
poiSprites.put(d, sprites);
|
||||
}
|
||||
return sprites;
|
||||
}
|
||||
public SettingData getSettingData() {
|
||||
return settingsData;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package forge.adventure.world;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import forge.adventure.data.BiomeSpriteData;
|
||||
@@ -14,18 +13,14 @@ public class BiomeSprites {
|
||||
private final ObjectMap<String, Array<Sprite>> spriteBuffer = new ObjectMap<>();
|
||||
public String textureAtlas;
|
||||
public BiomeSpriteData[] sprites;
|
||||
private TextureAtlas textureAtlasBuffer;
|
||||
|
||||
public Sprite getSprite(String name, int seed) {
|
||||
if (textureAtlasBuffer == null) {
|
||||
textureAtlasBuffer = Config.instance().getAtlas(textureAtlas);
|
||||
}
|
||||
if (!spriteBuffer.containsKey(name)) {
|
||||
spriteBuffer.put(name, new Array<Sprite>());
|
||||
spriteBuffer.put(name, new Array<>());
|
||||
}
|
||||
Array<Sprite> sprites = spriteBuffer.get(name);
|
||||
if (sprites.isEmpty()) {
|
||||
sprites.addAll(textureAtlasBuffer.createSprites(name));
|
||||
sprites.addAll(Config.instance().getAtlas(textureAtlas).createSprites(name));
|
||||
}
|
||||
int index = seed % sprites.size;
|
||||
if (index >= sprites.size || index < 0) {
|
||||
|
||||
@@ -101,6 +101,7 @@ public class TransitionScreen extends FContainer {
|
||||
private class BGAnimation extends ForgeAnimation {
|
||||
float DURATION = isArenaScene ? 1.2f : 0.6f;
|
||||
private float progress = 0;
|
||||
TextureRegion enemyAvatar;
|
||||
|
||||
public void drawBackground(Graphics g) {
|
||||
float percentage = progress / DURATION;
|
||||
@@ -156,7 +157,7 @@ public class TransitionScreen extends FContainer {
|
||||
float scale = screenW / 4;
|
||||
float centerX = screenW / 2;
|
||||
float centerY = screenH / 2;
|
||||
TextureRegion enemyAvatar = Config.instance().getAtlas(enemyAtlasPath).createSprite("Avatar");
|
||||
enemyAvatar = Config.instance().getAtlas(enemyAtlasPath).createSprite("Avatar");
|
||||
if (enemyAvatar != null)
|
||||
enemyAvatar.flip(true, false);
|
||||
float fontScale = GuiBase.isAndroid() ? 14f : 10f;
|
||||
|
||||
Reference in New Issue
Block a user