diff --git a/core/src/ru/deadsoftware/cavedroid/misc/Assets.java b/core/src/ru/deadsoftware/cavedroid/misc/Assets.java
index 778a44d78fcae10d20957c173edd5946a28d8a6a..1e531415c63baaefd9a04111ec9e663f5cda544a 100644 (file)
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
-import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.ArrayMap;
import com.badlogic.gdx.utils.JsonReader;
import com.badlogic.gdx.utils.JsonValue;
+import ru.deadsoftware.cavedroid.game.objects.TouchButton;
import java.util.HashMap;
public class Assets {
- public static JsonReader jsonReader = new JsonReader();
-
- private static GlyphLayout glyphLayout = new GlyphLayout();
-
+ public static final JsonReader jsonReader = new JsonReader();
+ public static final Sprite[][] playerSprite = new Sprite[2][4];
+ public static final Sprite[][] pigSprite = new Sprite[2][2];
+ public static final HashMap<String, TextureRegion> textureRegions = new HashMap<>();
+ public static final ArrayMap<String, TouchButton> guiMap = new ArrayMap<>();
+ private static final GlyphLayout glyphLayout = new GlyphLayout();
+ public static Sprite sandSprite;
+ public static Sprite gravelSprite;
static BitmapFont minecraftFont;
- public static Sprite[][] playerSprite = new Sprite[2][4];
- public static Sprite[][] pigSprite = new Sprite[2][2];
- public static Sprite fallingSandSprite;
- public static Sprite fallingGravelSprite;
- public static HashMap<String, TextureRegion> textureRegions = new HashMap<>();
- public static ArrayMap<String, Rectangle> guiMap = new ArrayMap<>();
-
private static TextureRegion flippedRegion(Texture texture, int x, int y, int width, int height) {
return new TextureRegion(texture, x, y + height, width, -height);
}
pigSprite[1][1] = flippedSprite(new TextureRegion(pigTex, 16, 26, 12, 12));
}
- private static void loadFallingBlocks() {
- fallingSandSprite = flippedSprite(new Texture((Gdx.files.internal("textures/blocks/sand.png"))));
- fallingGravelSprite = flippedSprite(new Texture((Gdx.files.internal("textures/blocks/gravel.png"))));
- }
-
/**
* Loads texture names and sizes from <b>json/texture_regions.json</b>, cuts them to TextureRegions
* and puts to {@link #textureRegions} HashMap
for (JsonValue file = json.child(); file != null; file = file.next()) {
Texture texture = new Texture(Gdx.files.internal(file.name() + ".png"));
if (file.size == 0) {
- textureRegions.put(file.name(), flippedRegion(texture, 0, 0, texture.getWidth(), texture.getHeight()));
+ textureRegions.put(file.name(),
+ flippedRegion(texture, 0, 0, texture.getWidth(), texture.getHeight()));
} else {
for (JsonValue key = file.child(); key != null; key = key.next()) {
- int x = key.has("x") ? key.getInt("x") : 0;
- int y = key.has("y") ? key.getInt("y") : 0;
- int w = key.has("w") ? key.getInt("w") : texture.getWidth();
- int h = key.has("h") ? key.getInt("h") : texture.getHeight();
+ int x = getIntFromJson(key, "x", 0);
+ int y = getIntFromJson(key, "y", 0);
+ int w = getIntFromJson(key, "w", texture.getWidth());
+ int h = getIntFromJson(key, "h", texture.getHeight());
textureRegions.put(key.name(), flippedRegion(texture, x, y, w, h));
}
}
}
public static void load() {
- minecraftFont = new BitmapFont(Gdx.files.internal("font.fnt"), true);
- minecraftFont.getData().setScale(.375f);
loadPlayer();
loadPig();
- loadFallingBlocks();
loadJSON();
+ minecraftFont = new BitmapFont(Gdx.files.internal("font.fnt"), true);
+ minecraftFont.getData().setScale(.375f);
+ sandSprite = flippedSprite(new Texture((Gdx.files.internal("textures/blocks/sand.png"))));
+ gravelSprite = flippedSprite(new Texture((Gdx.files.internal("textures/blocks/gravel.png"))));
}
/**
return (int) glyphLayout.height;
}
+ public static int getIntFromJson(JsonValue json, String name, int defaultValue) {
+ return json.has(name) ? json.getInt(name) : defaultValue;
+ }
+
+ public static String getStringFromJson(JsonValue json, String name, String defaultValue) {
+ return json.has(name) ? json.getString(name) : defaultValue;
+ }
+
+ public static boolean getBooleanFromJson(JsonValue json, String name, boolean defaultValue) {
+ return json.has(name) ? json.getBoolean(name) : defaultValue;
+ }
+
}