Skip to content

Commit

Permalink
LibGDX:
Browse files Browse the repository at this point in the history
* Modding debugging
  • Loading branch information
Mikhael-Danilov committed Dec 19, 2024
1 parent bcfd4d0 commit 30ac63f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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<String> 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) {
Expand All @@ -62,6 +77,7 @@ public class FileSystem {
return fileHandle;
}
}
PUtil.slog("file", "Internal file not found: " + fileName);
return fileHandle;
}

Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,10 @@ private static List<String> _listResources(String path, FilenameFilter filter) {

Set<String> 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]));
}

Expand All @@ -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();
Expand Down

0 comments on commit 30ac63f

Please sign in to comment.