diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameItems.java b/core/src/ru/deadsoftware/cavedroid/game/GameItems.java
index 5ae4f19a92e70b96ede2cfcecf01c40fac27d8e5..a5d6c23f716681c78acf0d34f923d6fedbbaf3b0 100644 (file)
import ru.deadsoftware.cavedroid.misc.utils.AssetLoader;
import ru.deadsoftware.cavedroid.misc.utils.SpriteOrigin;
import ru.deadsoftware.cavedroid.misc.utils.AssetLoader;
import ru.deadsoftware.cavedroid.misc.utils.SpriteOrigin;
-import java.util.HashMap;
+import java.util.*;
public class GameItems {
public class GameItems {
public static void load(AssetLoader assetLoader) {
JsonValue json = Assets.jsonReader.parse(assetLoader.getAssetHandle("json/game_items.json"));
public static void load(AssetLoader assetLoader) {
JsonValue json = Assets.jsonReader.parse(assetLoader.getAssetHandle("json/game_items.json"));
+
+ TreeSet<Block> blocksSet = new TreeSet<>(Comparator.comparingInt(Block::getId));
+ TreeSet<Item> itemsSet = new TreeSet<>(Comparator.comparingInt(Item::getId));
+
+
+ int count = 0;
for (JsonValue block = json.get("blocks").child(); block != null; block = block.next()) {
try {
String key = block.name();
for (JsonValue block = json.get("blocks").child(); block != null; block = block.next()) {
try {
String key = block.name();
new Texture(assetLoader.getAssetHandle("textures/blocks/" + tex + ".png"));
boolean animated = Assets.getBooleanFromJson(block, "animated", false);
int frames = Assets.getIntFromJson(block, "frames", 0);
new Texture(assetLoader.getAssetHandle("textures/blocks/" + tex + ".png"));
boolean animated = Assets.getBooleanFromJson(block, "animated", false);
int frames = Assets.getIntFromJson(block, "frames", 0);
- int id = blocks.size;
+ int id = Assets.getIntFromJson(block, "id", count);
blocksIds.put(key, id);
blocksIds.put(key, id);
+ if (count >= id) {
+ count++;
+ }
+
Block newBlock = new Block(
id,
Block newBlock = new Block(
id,
+ key,
left,
top,
right,
left,
top,
right,
clipWidth,
clipHeight
);
clipWidth,
clipHeight
);
- blocks.put(key, newBlock);
+ blocksSet.add(newBlock);
} catch (GdxRuntimeException e) {
Gdx.app.error(TAG, e.getMessage());
}
}
} catch (GdxRuntimeException e) {
Gdx.app.error(TAG, e.getMessage());
}
}
+
+ count = 0;
for (JsonValue item = json.get("items").child(); item != null; item = item.next()) {
try {
String key = item.name();
for (JsonValue item = json.get("items").child(); item != null; item = item.next()) {
try {
String key = item.name();
originY = MathUtils.clamp(originY, 0f, 1f);
SpriteOrigin origin = new SpriteOrigin(originX, originY);
originY = MathUtils.clamp(originY, 0f, 1f);
SpriteOrigin origin = new SpriteOrigin(originX, originY);
- int id = items.size;
+ int id = Assets.getIntFromJson(item, "id", count);
+
+ if (count >= id) {
+ count++;
+ }
+
itemsIds.put(key, id);
itemsIds.put(key, id);
- items.put(key, new Item(id, name, type, sprite, origin));
+ itemsSet.add(new Item(id, key, name, type, sprite, origin));
} catch (GdxRuntimeException e) {
Gdx.app.error(TAG, e.getMessage());
}
}
} catch (GdxRuntimeException e) {
Gdx.app.error(TAG, e.getMessage());
}
}
+
+ blocksSet.forEach((block -> blocks.put(block.getKey(), block)));
+ itemsSet.forEach((item -> items.put(item.getKey(), item)));
}
}
\ No newline at end of file
}
}
\ No newline at end of file