X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;ds=sidebyside;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fmisc%2FAssets.java;h=d86d3f8a17942e2a1d0301e0c7f2ec8399aee166;hb=115eb3d1e276d862941598ef3280f73e4d14b854;hp=778a44d78fcae10d20957c173edd5946a28d8a6a;hpb=44bd000cd15bf9713453a279840e133416fea998;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/misc/Assets.java b/core/src/ru/deadsoftware/cavedroid/misc/Assets.java index 778a44d..d86d3f8 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/Assets.java +++ b/core/src/ru/deadsoftware/cavedroid/misc/Assets.java @@ -15,18 +15,18 @@ import java.util.HashMap; public class Assets { - public static JsonReader jsonReader = new JsonReader(); + public static final JsonReader jsonReader = new JsonReader(); - private static GlyphLayout glyphLayout = new GlyphLayout(); + private static final GlyphLayout glyphLayout = new GlyphLayout(); static BitmapFont minecraftFont; - public static Sprite[][] playerSprite = new Sprite[2][4]; - public static Sprite[][] pigSprite = new Sprite[2][2]; + public static final Sprite[][] playerSprite = new Sprite[2][4]; + public static final Sprite[][] pigSprite = new Sprite[2][2]; public static Sprite fallingSandSprite; public static Sprite fallingGravelSprite; - public static HashMap textureRegions = new HashMap<>(); - public static ArrayMap guiMap = new ArrayMap<>(); + public static final HashMap textureRegions = new HashMap<>(); + public static final ArrayMap 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); @@ -91,10 +91,10 @@ public class Assets { 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)); } } @@ -128,4 +128,16 @@ public class Assets { 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; + } + }