attempt to fix debug env res path not found in Idea2019.1
@@ -13,7 +13,7 @@ public final class EngineAssetSource extends FileSystemAssetSource {
try {
Path path = Paths.get(EngineAssetSource.class.getProtectionDomain().getCodeSource().getLocation().toURI());
if (Files.isDirectory(path)) {
- return new EngineAssetSource(FileSystems.getDefault(), path.getParent().resolve("resources").resolve("assets").toString());
+ return new EngineAssetSource(FileSystems.getDefault(), resolveIdeResourcePath(path).toString());
} else {
FileSystem fileSystem = FileSystems.newFileSystem(path, EngineAssetSource.class.getClassLoader());
return new EngineAssetSource(fileSystem, "assets");
@@ -23,6 +23,21 @@ public final class EngineAssetSource extends FileSystemAssetSource {
}
}
+ private static Path resolveIdeResourcePath(Path path) {
+ Path tmp = path;
+ Path gradleSrc = Path.of("");
+ while(tmp.getParent() != null){
+ tmp = tmp.getParent();
+ if(Objects.equals(tmp.getFileName().toString(), "java")){
+ gradleSrc = tmp.relativize(path);
+ }
+ if(Files.exists(tmp.resolveSibling("resources"))){
+ return tmp.resolveSibling("resources").resolve(gradleSrc).resolve("assets");
+ }
+ }
+ return path.getParent().resolve("resources").resolve(gradleSrc).resolve("assets"); //return default value
+ }
+
private EngineAssetSource(FileSystem fileSystem, String root) {
super(fileSystem, root);
}
