mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-17 01:15:52 +01:00
Add Data TSJ loading, replace and update Banners
This commit is contained in:
@@ -5,6 +5,8 @@ import emu.grasscutter.server.http.handlers.GachaHandler;
|
||||
import emu.grasscutter.tools.Tools;
|
||||
import emu.grasscutter.utils.FileUtils;
|
||||
import emu.grasscutter.utils.JsonUtils;
|
||||
import emu.grasscutter.utils.TsvUtils;
|
||||
import lombok.val;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@@ -88,6 +90,17 @@ public class DataLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> List<T> loadTableToList(String resourcePath, Class<T> classType) throws IOException {
|
||||
val path = FileUtils.getDataPathTsjJsonTsv(resourcePath);
|
||||
Grasscutter.getLogger().info("Loading data table from: "+path);
|
||||
return switch (FileUtils.getFileExtension(path)) {
|
||||
case "json" -> JsonUtils.loadToList(path, classType);
|
||||
case "tsj" -> TsvUtils.loadTsjToListSetField(path, classType);
|
||||
case "tsv" -> TsvUtils.loadTsvToListSetField(path, classType);
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
public static void checkAllFiles() {
|
||||
try {
|
||||
List<Path> filenames = FileUtils.getPathsFromResource("/defaults/data/");
|
||||
|
||||
@@ -152,8 +152,8 @@ public class ResourceLoader {
|
||||
protected static <T> void loadFromResource(Class<T> c, Path filename, Int2ObjectMap map) throws Exception {
|
||||
val results = switch (FileUtils.getFileExtension(filename)) {
|
||||
case "json" -> JsonUtils.loadToList(filename, c);
|
||||
case "tsj" -> TsvUtils.loadTsjToListSetField(c, filename);
|
||||
case "tsv" -> TsvUtils.loadTsvToListSetField(c, filename);
|
||||
case "tsj" -> TsvUtils.loadTsjToListSetField(filename, c);
|
||||
case "tsv" -> TsvUtils.loadTsvToListSetField(filename, c);
|
||||
default -> null;
|
||||
};
|
||||
if (results == null) return;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class GachaBanner {
|
||||
private int[] rateUpItems4 = {};
|
||||
private int[] rateUpItems5 = {};
|
||||
@Getter private int[] fallbackItems3 = {11301, 11302, 11306, 12301, 12302, 12305, 13303, 14301, 14302, 14304, 15301, 15302, 15304};
|
||||
@Getter private int[] fallbackItems4Pool1 = {1014, 1020, 1023, 1024, 1025, 1027, 1031, 1032, 1034, 1036, 1039, 1043, 1044, 1045, 1048, 1053, 1055, 1056, 1064};
|
||||
@Getter private int[] fallbackItems4Pool1 = {1014, 1020, 1023, 1024, 1025, 1027, 1031, 1032, 1034, 1036, 1039, 1043, 1044, 1045, 1048, 1053, 1055, 1056, 1059, 1064, 1065, 1067, 1068, 1072};
|
||||
@Getter private int[] fallbackItems4Pool2 = {11401, 11402, 11403, 11405, 12401, 12402, 12403, 12405, 13401, 13407, 14401, 14402, 14403, 14409, 15401, 15402, 15403, 15405};
|
||||
@Getter private int[] fallbackItems5Pool1 = {1003, 1016, 1042, 1035, 1041};
|
||||
@Getter private int[] fallbackItems5Pool2 = {11501, 11502, 12501, 12502, 13502, 13505, 14501, 14502, 15501, 15502};
|
||||
|
||||
@@ -70,7 +70,7 @@ public class GachaSystem extends BaseGameSystem {
|
||||
public synchronized void load() {
|
||||
getGachaBanners().clear();
|
||||
try {
|
||||
List<GachaBanner> banners = DataLoader.loadList("Banners.json", GachaBanner.class);
|
||||
List<GachaBanner> banners = DataLoader.loadTableToList("Banners", GachaBanner.class);
|
||||
if (banners.size() > 0) {
|
||||
for (GachaBanner banner : banners) {
|
||||
banner.onLoad();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user