feat: asset manager

This commit is contained in:
2025-04-06 12:58:47 +02:00
parent 6eae7e386f
commit 58cc9f3f17
3 changed files with 54 additions and 7 deletions

View File

@@ -0,0 +1,38 @@
package chess.view;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class AssetManager {
private static final String gradleBase = "app/src/main/resources/";
public static InputStream getResource(String name) {
// we first search it in files
InputStream inputStream = getFileInputStream(name);
if (inputStream != null)
return inputStream;
inputStream = getFileInputStream(gradleBase + name);
if (inputStream != null)
return inputStream;
// then in the jar
return ClassLoader.getSystemResourceAsStream(name);
}
private static InputStream getFileInputStream(String path) {
File f = new File(path);
if (f.exists()) {
FileInputStream fis;
try {
fis = new FileInputStream(f);
return fis;
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}