summaryrefslogtreecommitdiff
path: root/core/src/kz/ilotterytea/maxon/assets
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-06-09 15:17:36 +0500
committerilotterytea <iltsu@alright.party>2024-06-09 19:27:35 +0500
commit5a95a3213dc311ed27f9f0ee749c9ac5bb501ade (patch)
tree418460318aa4501ba158ca98bc37fc9ea9f41ab1 /core/src/kz/ilotterytea/maxon/assets
parenta3bb4022b1693e865f13b6cf294762aaaa8987a7 (diff)
feat: automatically load assets from txt file
Diffstat (limited to 'core/src/kz/ilotterytea/maxon/assets')
-rw-r--r--core/src/kz/ilotterytea/maxon/assets/AssetUtils.java69
1 files changed, 69 insertions, 0 deletions
diff --git a/core/src/kz/ilotterytea/maxon/assets/AssetUtils.java b/core/src/kz/ilotterytea/maxon/assets/AssetUtils.java
new file mode 100644
index 0000000..ae3598e
--- /dev/null
+++ b/core/src/kz/ilotterytea/maxon/assets/AssetUtils.java
@@ -0,0 +1,69 @@
+package kz.ilotterytea.maxon.assets;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.assets.AssetManager;
+import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
+import com.badlogic.gdx.audio.Music;
+import com.badlogic.gdx.files.FileHandle;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+import com.badlogic.gdx.scenes.scene2d.ui.Skin;
+import kz.ilotterytea.maxon.assets.loaders.Text;
+import kz.ilotterytea.maxon.assets.loaders.TextLoader;
+import net.mgsx.gltf.loaders.glb.GLBAssetLoader;
+import net.mgsx.gltf.scene3d.scene.SceneAsset;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class AssetUtils {
+ public static void setup(AssetManager assetManager) {
+ assetManager.setLoader(SceneAsset.class, ".glb", new GLBAssetLoader());
+ assetManager.setLoader(Text.class, new TextLoader(new InternalFileHandleResolver()));
+ }
+
+ public static void queue(AssetManager assetManager) {
+ FileHandle assetsFile = Gdx.files.internal("assets.txt");
+ String contents = assetsFile.readString();
+ List<String> filePaths = contents.lines().collect(Collectors.toList());
+
+ for (String filePath : filePaths) {
+ System.out.println(filePath);
+ String[] splitFilePath = filePath.split("/");
+ String[] splitFileName = splitFilePath[splitFilePath.length - 1].split("\\.");
+ String extension = splitFileName[splitFileName.length - 1];
+
+ Class<?> type = null;
+
+ switch (extension) {
+ case "png":
+ type = Texture.class;
+ break;
+ case "atlas":
+ type = TextureAtlas.class;
+ break;
+ case "skin":
+ type = Skin.class;
+ break;
+ case "json":
+ case "txt":
+ type = Text.class;
+ break;
+ case "glb":
+ type = SceneAsset.class;
+ break;
+ case "ogg":
+ type = Music.class;
+ break;
+ default:
+ break;
+ }
+
+ if (type == null) {
+ continue;
+ }
+
+ assetManager.load(filePath, type);
+ }
+ }
+} \ No newline at end of file