Add Data TSJ loading, replace and update Banners

This commit is contained in:
AnimeGitB
2022-11-24 23:09:55 +10:30
parent 35962542af
commit 1c4d263dd2
8 changed files with 43 additions and 96 deletions

View File

@@ -88,6 +88,19 @@ public final class FileUtils {
: Path.of(scripts);
};
private static final String[] TSJ_JSON_TSV = {"tsj", "json", "tsv"};
private static final Path[] DATA_PATHS = {DATA_USER_PATH, DATA_DEFAULT_PATH};
public static Path getDataPathTsjJsonTsv(String filename) {
val name = getFilenameWithoutExtension(filename);
for (val data_path : DATA_PATHS) {
for (val ext : TSJ_JSON_TSV) {
val path = data_path.resolve(name + "." + ext);
if (Files.exists(path)) return path;
}
}
return DATA_USER_PATH.resolve(name + ".tsj"); // Maybe they want to write to a new file
}
public static Path getDataPath(String path) {
Path userPath = DATA_USER_PATH.resolve(path);
if (Files.exists(userPath)) return userPath;
@@ -121,13 +134,11 @@ public final class FileUtils {
// If none exist, return the TSJ path, in case it wants to create a file
public static Path getTsjJsonTsv(Path root, String filename) {
val name = getFilenameWithoutExtension(filename);
val tsj = root.resolve(name + ".tsj");
if (Files.exists(tsj)) return tsj;
val json = root.resolve(name + ".json");
if (Files.exists(json)) return json;
val tsv = root.resolve(name + ".tsv");
if (Files.exists(tsv)) return tsv;
return tsj;
for (val ext : TSJ_JSON_TSV) {
val path = root.resolve(name + "." + ext);
if (Files.exists(path)) return path;
}
return root.resolve(name + ".tsj");
}
public static Path getScriptPath(String path) {

View File

@@ -402,7 +402,7 @@ public class TsvUtils {
// Arrays are represented as arrayName.0, arrayName.1, etc. columns.
// Maps/POJOs are represented as objName.fieldOneName, objName.fieldTwoName, etc. columns.
// This is currently about 25x as slow as TSJ and Gson parsers, likely due to the tree spam.
public static <T> List<T> loadTsvToListSetField(Class<T> classType, Path filename) {
public static <T> List<T> loadTsvToListSetField(Path filename, Class<T> classType) {
try (val fileReader = Files.newBufferedReader(filename, StandardCharsets.UTF_8)) {
// val fieldMap = getClassFieldMap(classType);
// val constructor = classType.getDeclaredConstructor();
@@ -453,7 +453,7 @@ public class TsvUtils {
// This uses a hybrid format where columns can hold JSON-encoded values.
// I'll term it TSJ (tab-separated JSON) for now, it has convenient properties.
public static <T> List<T> loadTsjToListSetField(Class<T> classType, Path filename) {
public static <T> List<T> loadTsjToListSetField(Path filename, Class<T> classType) {
try (val fileReader = Files.newBufferedReader(filename, StandardCharsets.UTF_8)) {
val fieldMap = getClassFieldMap(classType);
val constructor = classType.getDeclaredConstructor();