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