summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7bb5658)
raw | patch | inline | side by side (parent: 7bb5658)
author | fredboy <fredboy@protonmail.com> | |
Sun, 21 Apr 2024 13:33:53 +0000 (20:33 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Sun, 21 Apr 2024 13:33:53 +0000 (20:33 +0700) |
diff --git a/core/src/ru/deadsoftware/cavedroid/CaveGame.java b/core/src/ru/deadsoftware/cavedroid/CaveGame.java
index 5bd5c99ebd3b8b706d7ade5ae56f5ba0950df238..6e3e1891b6b0b14cb41e9ed82b6bb0d80cd95780 100644 (file)
@Override
public void create() {
- Gdx.app.log(TAG, mGameFolder);
Gdx.files.absolute(mGameFolder).mkdirs();
initConfig();
+
+ Gdx.app.debug(TAG, mGameFolder);
Assets.load(mAssetLoader);
setScreen(mMainComponent.getMenuScreen());
}
if (screen != null) {
screen.dispose();
}
+ Assets.dispose();
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/mapper/BlockMapper.kt b/core/src/ru/deadsoftware/cavedroid/game/model/mapper/BlockMapper.kt
index cae219f00c053b679141776e2ec8a67b40395bf1..bc2978320d8f2d062889f4c6390a139545f0e029 100644 (file)
isTransparent = dto.transparent,
requiresBlock = dto.blockRequired,
animationInfo = mapBlockAnimationInfo(dto),
- texture = loadTexture(dto.texture),
+ texture = getTexture(dto.texture),
spriteMargins = BlockMargins(
left = dto.spriteLeft,
top = dto.spriteTop,
)
}
- private fun loadTexture(textureName: String): Texture? {
+ private fun getTexture(textureName: String): Texture? {
if (textureName == GameItemsHolder.FALLBACK_BLOCK_KEY) {
return null
}
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/Assets.java b/core/src/ru/deadsoftware/cavedroid/misc/Assets.java
index cf87a0859cd666f3adda10c11ab57ec10c247ea1..a6318d71e75cb86c5788be83b1937a5f89c90cbf 100644 (file)
import ru.deadsoftware.cavedroid.misc.utils.AssetLoader;
import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
public class Assets {
public static final JsonReader jsonReader = new JsonReader();
+
+ private static final List<Texture> loadedTextures = new LinkedList<>();
+
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 Map<String, Texture> blockTextures = new HashMap<>();
public static Map<String, Texture> itemTextures = new HashMap<>();
+ public static void dispose() {
+ minecraftFont.dispose();
+ loadedTextures.forEach(Texture::dispose);
+ loadedTextures.clear();
+ }
+
+ private static Texture loadTexture(FileHandle fileHandle) {
+ Texture texture = new Texture(fileHandle);
+ loadedTextures.add(texture);
+ return texture;
+ }
+
private static TextureRegion flippedRegion(Texture texture, int x, int y, int width, int height) {
return new TextureRegion(texture, x, y + height, width, -height);
}
private static void loadMob(AssetLoader assetLoader, Sprite[][] sprite, String mob) {
for (int i = 0; i < sprite.length; i++) {
for (int j = 0; j < sprite[i].length; j++) {
- sprite[i][j] = flippedSprite(new Texture(
+ sprite[i][j] = flippedSprite(loadTexture(
assetLoader.getAssetHandle("mobs/" + mob + "/" + i + "_" + j + ".png")));
sprite[i][j].setOrigin(sprite[i][j].getWidth() / 2, 0);
}
private static void loadJSON(AssetLoader assetLoader) {
JsonValue json = jsonReader.parse(assetLoader.getAssetHandle("json/texture_regions.json"));
for (JsonValue file = json.child(); file != null; file = file.next()) {
- Texture texture = new Texture(assetLoader.getAssetHandle(file.name() + ".png"));
+ Texture texture = loadTexture(assetLoader.getAssetHandle(file.name() + ".png"));
if (file.size == 0) {
textureRegions.put(file.name(),
flippedRegion(texture, 0, 0, texture.getWidth(), texture.getHeight()));
private static void loadAllPngsFromDirInto(FileHandle dir, Map<String, Texture> loadInto) {
for (FileHandle handle : dir.list((d, name) -> name.endsWith(".png"))) {
- loadInto.put(handle.nameWithoutExtension(), new Texture(handle));
+ loadInto.put(handle.nameWithoutExtension(), loadTexture(handle));
}
}