forked from SkyeStarfall/BaseMod
-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathAtlasLoader.java
More file actions
43 lines (35 loc) · 1.36 KB
/
AtlasLoader.java
File metadata and controls
43 lines (35 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package basemod;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePrefixPatch;
import java.util.HashMap;
public class AtlasLoader {
private static HashMap<String, TextureAtlas> atlases = new HashMap<>();
public static TextureAtlas getAtlas(final String atlasString) {
if (atlases.get(atlasString) == null) {
try {
loadAtlas(atlasString);
} catch (GdxRuntimeException e) {
}
}
return atlases.get(atlasString);
}
private static void loadAtlas(final String atlasString) throws GdxRuntimeException {
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal(atlasString));
atlases.put(atlasString, atlas);
}
public static boolean testAtlas(String filePath) {
return Gdx.files.internal(filePath).exists();
}
@SpirePatch(clz = TextureAtlas.class, method = "dispose")
public static class DisposeListener {
@SpirePrefixPatch
public static void DisposeListenerPatch(final TextureAtlas __instance) {
atlases.entrySet().removeIf(entry -> {
return entry.getValue().equals(__instance);
});
}
}
}