Added new class AssetsTxt II
This commit is contained in:
parent
b35987c7c2
commit
a24ba17b8b
@ -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<String> listRoot(boolean directoryType, boolean fileType) {
|
||||
return list(".", directoryType, fileType);
|
||||
return AssetsTxt.this.list(".", directoryType, fileType);
|
||||
}
|
||||
|
||||
public List<String> listRoot() {
|
||||
@ -90,18 +92,19 @@ public class AssetsTxt {
|
||||
}
|
||||
|
||||
public List<String> list(String pathToDirectory) {
|
||||
return list(pathToDirectory, true, true);
|
||||
return AssetsTxt.this.list(pathToDirectory, true, true);
|
||||
}
|
||||
|
||||
public List<String> listDirectories(String pathToDirectory) {
|
||||
return list(pathToDirectory, true, false);
|
||||
return AssetsTxt.this.list(pathToDirectory, true, false);
|
||||
}
|
||||
|
||||
public List<String> listFiles(String pathToDirectory) {
|
||||
return list(pathToDirectory, false, true);
|
||||
return AssetsTxt.this.list(pathToDirectory, false, true);
|
||||
}
|
||||
|
||||
public List<String> 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<FileHandle> 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<String> list) {
|
||||
return list.stream().collect(Collectors.joining("/"));
|
||||
|
@ -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());
|
||||
|
@ -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<String> lines(String string) {
|
||||
return Arrays.asList(string.split("\\r?\\n")).stream();
|
||||
}
|
||||
public static <T> List<T> streamToList(Stream<T> stream) {
|
||||
return stream.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user