From 30ac63f3a37abe69582d1af842b5625b5854fe3a Mon Sep 17 00:00:00 2001 From: Mikhael Date: Fri, 20 Dec 2024 01:59:07 +0300 Subject: [PATCH] LibGDX: * Modding debugging --- .../nyrds/platform/storage/FileSystem.java | 48 +++++++++++-------- .../java/com/nyrds/util/ModdingMode.java | 17 +------ 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/platform/storage/FileSystem.java b/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/platform/storage/FileSystem.java index f91b45826d..2445a1efa4 100644 --- a/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/platform/storage/FileSystem.java +++ b/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/platform/storage/FileSystem.java @@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; -import com.nyrds.pixeldungeon.ml.actions.Push; import com.nyrds.platform.util.PUtil; import com.nyrds.util.ModError; import com.nyrds.util.ModdingMode; @@ -19,6 +18,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.HashSet; +import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -27,25 +28,39 @@ public class FileSystem { - static public @NotNull FileHandle getInternalStorageFileHandle(String fileName) { + static public FileHandle getInternalStorageFileHandle(String fileName) { FileHandle fileHandle = null; - for(String path : new String[] { - "mods/"+ModdingMode.activeMod()+"/", + for(String path : getAllResPaths()) { + fileHandle = Gdx.files.internal(path+fileName); + if(fileHandle.exists()) { + return fileHandle; + } + } + PUtil.slog("file", "File not found: " + fileName); + return fileHandle; + } + + private static String[] getAllResPaths() { + return new String[]{ + "mods/" + ModdingMode.activeMod() + "/", "mods/Remixed/", "../assets/", "../d_assets/", "../l10ns/", "./", - }) { - fileHandle = Gdx.files.internal(path+fileName); - //PUtil.slog("storage", "Trying " + path + fileName); - if(fileHandle.exists()) { + }; + } - return fileHandle; + static public String[] listResources(String resName) { + Set resList = new HashSet<>(); + for (String path : getAllResPaths()) { + FileHandle fileHandle = Gdx.files.internal(path + resName); + FileHandle[] fileHandles = fileHandle.list(file -> true); + for (FileHandle file : fileHandles) { + resList.add(file.name()); } } - - return fileHandle; + return resList.toArray(new String[0]); } static public @NotNull FileHandle getInternalStorageFileHandleBase(String fileName) { @@ -62,6 +77,7 @@ public class FileSystem { return fileHandle; } } + PUtil.slog("file", "Internal file not found: " + fileName); return fileHandle; } @@ -74,10 +90,6 @@ public class FileSystem { return getInternalStorageFileHandleBase(fileName).file(); } - static public String[] listInternalStorage() { - return getInternalStorageFile(".").list(); - } - @NotNull static public File[] listExternalStorage() { File storageDir = Gdx.files.internal("mods/").file(); @@ -172,7 +184,7 @@ private static void addFolderToZip(File rootFolder, File srcFolder, int depth, } if(depth > 0 && file.isDirectory()) { - zip.putNextEntry(new ZipEntry(getRelativePath(file,rootFolder))); + zip.putNextEntry(new ZipEntry(getRelativePath(file, rootFolder))); addFolderToZip(rootFolder, srcFolder, depth-1, zip, filter); zip.closeEntry(); } @@ -216,8 +228,4 @@ public static void ensureDir(String dir) { throw new ModError("Can't create directory:"+dir); } } - - public static boolean deleteFile(String file) { - return new File(file).delete(); - } } diff --git a/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/util/ModdingMode.java b/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/util/ModdingMode.java index 694a2be7cd..17f5aa4cbf 100644 --- a/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/util/ModdingMode.java +++ b/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/util/ModdingMode.java @@ -207,18 +207,10 @@ private static List _listResources(String path, FilenameFilter filter) { Set resList = new HashSet<>(); - String[] fullList = FileSystem.getInternalStorageFile(path).list(); + String[] fullList = FileSystem.listResources(path); collectResources(path, filter, resList, fullList); - if (inMod()) { - String resourcesPath = mActiveMod + "/" + path; - if (isResourceExistInMod(path)) { - String[] modList = FileSystem.getExternalStorageFile(resourcesPath).list(); - collectResources(path, filter, resList, modList); - } - } - return Arrays.asList(resList.toArray(new String[0])); } @@ -243,13 +235,6 @@ public static boolean isResourceExist(String resName) { } } - public static File getFile(String resName) { - if (!mActiveMod.equals(REMIXED)) { - return FileSystem.getExternalStorageFile(mActiveMod + "/" + resName); - } - return null; - } - public static String getResource(String resName) { StringBuilder resource = new StringBuilder();