X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;ds=sidebyside;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fmisc%2FAssets.java;h=93a5f86ea4a9509bfcd40f09f240db06a05ccb64;hb=0ed259db50b9cab761cd5dca5cb229e69886854b;hp=e2abcdfd61ceb82dfe547dfeffe9a23243f396d0;hpb=ef32f2e88b9c0daa411d0c304ce62b1235541fb1;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/misc/Assets.java b/core/src/ru/deadsoftware/cavedroid/misc/Assets.java index e2abcdf..93a5f86 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/Assets.java +++ b/core/src/ru/deadsoftware/cavedroid/misc/Assets.java @@ -18,15 +18,14 @@ public class Assets { public static final JsonReader jsonReader = new JsonReader(); private static final GlyphLayout glyphLayout = new GlyphLayout(); - - static BitmapFont minecraftFont; + static final BitmapFont minecraftFont = new BitmapFont(Gdx.files.internal("font.fnt"), true); 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 final HashMap textureRegions = new HashMap<>(); public static final ArrayMap guiMap = new ArrayMap<>(); + public static final Sprite sandSprite = flippedSprite(new Texture((Gdx.files.internal("textures/blocks/sand.png")))); + public static final Sprite gravelSprite = flippedSprite(new Texture((Gdx.files.internal("textures/blocks/gravel.png")))); private static TextureRegion flippedRegion(Texture texture, int x, int y, int width, int height) { return new TextureRegion(texture, x, y + height, width, -height); @@ -74,11 +73,6 @@ public class Assets { 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 json/texture_regions.json, cuts them to TextureRegions * and puts to {@link #textureRegions} HashMap @@ -91,10 +85,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)); } } @@ -102,11 +96,9 @@ public class Assets { } public static void load() { - minecraftFont = new BitmapFont(Gdx.files.internal("font.fnt"), true); minecraftFont.getData().setScale(.375f); loadPlayer(); loadPig(); - loadFallingBlocks(); loadJSON(); } @@ -128,4 +120,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; + } + }