Fix serialization registering not working in prod
This commit is contained in:
@@ -48,6 +48,7 @@ public class VoxyConfigScreenFactory implements ModMenuApi {
|
|||||||
ConfigCategory category = builder.getOrCreateCategory(Text.translatable("voxy.config.general"));
|
ConfigCategory category = builder.getOrCreateCategory(Text.translatable("voxy.config.general"));
|
||||||
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
|
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
|
||||||
|
|
||||||
|
/*
|
||||||
category.addEntry(entryBuilder.startSubCategory(Text.translatable("aaa"), List.of(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.enabled"), config.enabled)
|
category.addEntry(entryBuilder.startSubCategory(Text.translatable("aaa"), List.of(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.enabled"), config.enabled)
|
||||||
.setTooltip(Text.translatable("voxy.config.general.enabled.tooltip"))
|
.setTooltip(Text.translatable("voxy.config.general.enabled.tooltip"))
|
||||||
.setSaveConsumer(val -> config.enabled = val)
|
.setSaveConsumer(val -> config.enabled = val)
|
||||||
@@ -58,7 +59,7 @@ public class VoxyConfigScreenFactory implements ModMenuApi {
|
|||||||
.setDefaultValue(DEFAULT.geometryBufferSize)
|
.setDefaultValue(DEFAULT.geometryBufferSize)
|
||||||
.build())).build()
|
.build())).build()
|
||||||
)).build());
|
)).build());
|
||||||
|
*/
|
||||||
|
|
||||||
category.addEntry(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.enabled"), config.enabled)
|
category.addEntry(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.enabled"), config.enabled)
|
||||||
.setTooltip(Text.translatable("voxy.config.general.enabled.tooltip"))
|
.setTooltip(Text.translatable("voxy.config.general.enabled.tooltip"))
|
||||||
|
|||||||
@@ -42,24 +42,26 @@ public class ContextSelectionSystem {
|
|||||||
if (Files.exists(json)) {
|
if (Files.exists(json)) {
|
||||||
try {
|
try {
|
||||||
this.storageConfig = Serialization.GSON.fromJson(Files.readString(json), StorageConfig.class);
|
this.storageConfig = Serialization.GSON.fromJson(Files.readString(json), StorageConfig.class);
|
||||||
} catch (IOException e) {
|
return;
|
||||||
throw new RuntimeException(e);
|
} catch (Exception e) {
|
||||||
|
System.err.println("Failed to load the storage configuration file, resetting it to default");
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
//Load the default config
|
|
||||||
var baseDB = new RocksDBStorageBackend.Config();
|
|
||||||
|
|
||||||
var compressor = new ZSTDCompressor.Config();
|
|
||||||
compressor.compressionLevel = 7;
|
|
||||||
|
|
||||||
var compression = new CompressionStorageAdaptor.Config();
|
|
||||||
compression.delegate = baseDB;
|
|
||||||
compression.compressor = compressor;
|
|
||||||
|
|
||||||
this.storageConfig = compression;
|
|
||||||
|
|
||||||
this.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Load the default config
|
||||||
|
var baseDB = new RocksDBStorageBackend.Config();
|
||||||
|
|
||||||
|
var compressor = new ZSTDCompressor.Config();
|
||||||
|
compressor.compressionLevel = 7;
|
||||||
|
|
||||||
|
var compression = new CompressionStorageAdaptor.Config();
|
||||||
|
compression.delegate = baseDB;
|
||||||
|
compression.compressor = compressor;
|
||||||
|
|
||||||
|
this.storageConfig = compression;
|
||||||
|
|
||||||
|
this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageBackend createStorageBackend() {
|
public StorageBackend createStorageBackend() {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.google.gson.stream.JsonToken;
|
import com.google.gson.stream.JsonToken;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -13,9 +14,13 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
public class Serialization {
|
public class Serialization {
|
||||||
public static final Set<Class<?>> CONFIG_TYPES = new HashSet<>();
|
public static final Set<Class<?>> CONFIG_TYPES = new HashSet<>();
|
||||||
@@ -89,8 +94,14 @@ public class Serialization {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
Map<Class<?>, GsonConfigSerialization<?>> serializers = new HashMap<>();
|
Map<Class<?>, GsonConfigSerialization<?>> serializers = new HashMap<>();
|
||||||
|
|
||||||
|
Set<String> clazzs = new LinkedHashSet<>();
|
||||||
|
var path = FabricLoader.getInstance().getModContainer("voxy").get().getRootPaths().get(0);
|
||||||
|
clazzs.addAll(collectAllClasses(path, "me.cortex.voxy.common.storage"));
|
||||||
|
clazzs.addAll(collectAllClasses("me.cortex.voxy.common.storage"));
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
for (var clzName : collectAllClasses("me.cortex.voxy.common.storage")) {
|
for (var clzName : clazzs) {
|
||||||
if (clzName.equals(Serialization.class.getName())) {
|
if (clzName.equals(Serialization.class.getName())) {
|
||||||
continue;//Dont want to load ourselves
|
continue;//Dont want to load ourselves
|
||||||
}
|
}
|
||||||
@@ -144,6 +155,22 @@ public class Serialization {
|
|||||||
}
|
}
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
private static List<String> collectAllClasses(Path base, String pack) {
|
||||||
|
try {
|
||||||
|
return Files.list(base.resolve(pack.replaceAll("[.]", "/"))).flatMap(inner -> {
|
||||||
|
if (inner.getFileName().toString().endsWith(".class")) {
|
||||||
|
return Stream.of(pack + "." + inner.getFileName().toString().replace(".class", ""));
|
||||||
|
} else if (Files.isDirectory(inner)) {
|
||||||
|
return collectAllClasses(base, pack + "." + inner.getFileName()).stream();
|
||||||
|
} else {
|
||||||
|
return Stream.of();
|
||||||
|
}
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
} catch (
|
||||||
|
IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void init() {}
|
public static void init() {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user