From a24ba17b8b818b7d5624e459e1481ed6a80dd20f Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Mon, 5 Aug 2024 12:49:38 +0200 Subject: [PATCH] Added new class AssetsTxt II --- .../java/com/openeggbert/main/AssetsTxt.java | 19 +++++++++++++++---- .../com/openeggbert/main/OpenEggbertGame.java | 19 ++++++++++--------- .../openeggbert/utils/OpenEggbertUtils.java | 5 +++++ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/com/openeggbert/main/AssetsTxt.java b/core/src/main/java/com/openeggbert/main/AssetsTxt.java index 7bddbd0..1c921c7 100644 --- a/core/src/main/java/com/openeggbert/main/AssetsTxt.java +++ b/core/src/main/java/com/openeggbert/main/AssetsTxt.java @@ -19,6 +19,8 @@ /////////////////////////////////////////////////////////////////////////////////////////////// package com.openeggbert.main; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.files.FileHandle; import com.openeggbert.entity.common.OpenEggbertException; import com.openeggbert.utils.OpenEggbertUtils; import java.util.ArrayList; @@ -82,7 +84,7 @@ public class AssetsTxt { } public List listRoot(boolean directoryType, boolean fileType) { - return list(".", directoryType, fileType); + return AssetsTxt.this.list(".", directoryType, fileType); } public List listRoot() { @@ -90,18 +92,19 @@ public class AssetsTxt { } public List list(String pathToDirectory) { - return list(pathToDirectory, true, true); + return AssetsTxt.this.list(pathToDirectory, true, true); } public List listDirectories(String pathToDirectory) { - return list(pathToDirectory, true, false); + return AssetsTxt.this.list(pathToDirectory, true, false); } public List listFiles(String pathToDirectory) { - return list(pathToDirectory, false, true); + return AssetsTxt.this.list(pathToDirectory, false, true); } public List list(String pathToDirectory, boolean directoryType, boolean fileType) { + System.out.println("Calling: AssetsTxt.list( " + pathToDirectory + " ...)"); if (!directoryType && !fileType) { throw new OpenEggbertException("Invalid arguments, both arguments are false: directoryType, fileType"); } @@ -148,6 +151,14 @@ public class AssetsTxt { return result; } + + public List list(FileHandle fileHandle) { + String pathToDirectory = fileHandle.path();//((fileHandle.path().isEmpty() ? "" : (fileHandle.path() + "/"))) + fileHandle.name(); + return AssetsTxt.this.list(pathToDirectory) + .stream() + .map(p-> Gdx.files.classpath((pathToDirectory.equals(".") ? "" : (pathToDirectory + "/")) + p)) + .collect(Collectors.toList()); + } private static String convertListStringToStringPath(List list) { return list.stream().collect(Collectors.joining("/")); diff --git a/core/src/main/java/com/openeggbert/main/OpenEggbertGame.java b/core/src/main/java/com/openeggbert/main/OpenEggbertGame.java index 9ba115a..abb8b76 100644 --- a/core/src/main/java/com/openeggbert/main/OpenEggbertGame.java +++ b/core/src/main/java/com/openeggbert/main/OpenEggbertGame.java @@ -36,6 +36,7 @@ import com.openeggbert.entity.common.GameSpace; import com.openeggbert.mods.Mod; import com.openeggbert.screens.GameSpaceListScreen; import com.openeggbert.screens.InitScreen; +import com.openeggbert.utils.OpenEggbertUtils; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -61,7 +62,7 @@ public class OpenEggbertGame extends Game { private int widthInPixels = 640; private Camera camera; private Viewport viewport; - private AssetsTxt assetsTxt; + private AssetsTxt assets; public OpenEggbertGame() { this(null, null); @@ -85,25 +86,23 @@ public class OpenEggbertGame extends Game { //.setToOrtho(false,640,480); - assetsTxt = new AssetsTxt(Gdx.files.internal("assets.txt").readString()); + assets = new AssetsTxt(Gdx.files.internal("assets.txt").readString()); System.out.println("Searching mods"); for(FileHandle f:Gdx.files.internal(".").list()) { System.out.println("assets contains also: " + f.name()); } FileHandle embeddedModsDirectory = Gdx.files.internal("embedded_mods"); + System.out.println("embeddedModsDirectory.exists=" + embeddedModsDirectory.exists()); System.out.println("embeddedModsDirectory.list().length=" + embeddedModsDirectory.list().length); - for (FileHandle embeddedModGroup : embeddedModsDirectory.list()) { - if (!embeddedModGroup.isDirectory()) { - System.out.println("embedded_mods directory is missing"); - continue; - } + for (FileHandle embeddedModGroup : assets.list(embeddedModsDirectory)) { + if(embeddedModGroup.name().equals("README.md"))continue; System.out.println("Found group " + embeddedModGroup.name()); - for (FileHandle embeddedMod : embeddedModGroup.list()) { + for (FileHandle embeddedMod : assets.list(embeddedModGroup)) { System.out.println("Found mod " + embeddedMod.name()); FileHandle modXml = null; - for(FileHandle file: embeddedMod.list()) { + for(FileHandle file: assets.list(embeddedMod)) { if(file.name().equals("mod.xml")) { modXml = file; } @@ -113,6 +112,8 @@ public class OpenEggbertGame extends Game { continue; } System.out.println("Found mod: " + embeddedMod.name()); + System.out.println("embeddedMod.exists?=: " + embeddedMod.exists()); + Mod mod = new Mod(modXml.readString()); embeddedMods.add(mod); System.out.println("embeddedMods.size(): " + embeddedMods.size()); diff --git a/core/src/main/java/com/openeggbert/utils/OpenEggbertUtils.java b/core/src/main/java/com/openeggbert/utils/OpenEggbertUtils.java index 3d4a349..4e539f1 100644 --- a/core/src/main/java/com/openeggbert/utils/OpenEggbertUtils.java +++ b/core/src/main/java/com/openeggbert/utils/OpenEggbertUtils.java @@ -20,6 +20,8 @@ package com.openeggbert.utils; import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -33,5 +35,8 @@ public class OpenEggbertUtils { public static Stream lines(String string) { return Arrays.asList(string.split("\\r?\\n")).stream(); } + public static List streamToList(Stream stream) { + return stream.collect(Collectors.toList()); + } }