fixed config load bug
This commit is contained in:
@@ -5,23 +5,15 @@ import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.saturnclient.modules.mods.*;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.SaturnClientConfig;
|
||||
import org.saturnclient.saturnclient.menus.HudEditor;
|
||||
|
||||
public class ModManager {
|
||||
public static List<Module> MODS = new ArrayList<>();
|
||||
|
||||
public static <T extends Module> void impl(Class<T> mod) {
|
||||
try {
|
||||
MODS.add((Module) mod.getDeclaredConstructor().newInstance());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static Module[] MODS = {
|
||||
new Crosshair()
|
||||
};
|
||||
|
||||
public static void init() {
|
||||
ClientTickEvents.START_CLIENT_TICK.register(client -> {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.ModManager;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.saturnclient.config.NamedProperty;
|
||||
import org.saturnclient.saturnclient.config.Property;
|
||||
@@ -13,10 +12,6 @@ public class Crosshair extends Module {
|
||||
super("Crosshair", "crosshair", enabled, range_indicator);
|
||||
}
|
||||
|
||||
static {
|
||||
ModManager.impl(Crosshair.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.prop.value;
|
||||
|
||||
@@ -34,13 +34,14 @@ public class SaturnClient implements ModInitializer {
|
||||
LOGGER.info("Initializing " + MOD_ID);
|
||||
client = MinecraftClient.getInstance();
|
||||
ModManager.init();
|
||||
SaturnClientConfig.init();
|
||||
ThemeManager.load();
|
||||
ConfigManager.load();
|
||||
|
||||
ClientLifecycleEvents.CLIENT_STOPPING.register(_o -> {ConfigManager.save(); ThemeManager.save();});
|
||||
ScreenEvents.BEFORE_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
|
||||
if (SaturnClientConfig.saturnTitleScreen.value && screen instanceof TitleScreen
|
||||
&& !(screen instanceof SaturnMenu)) {
|
||||
&& !(screen instanceof SaturnMenu)) {
|
||||
client.setScreen(new SaturnTitleScreen());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -12,27 +12,23 @@ import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.ColorHelper;
|
||||
|
||||
public class SaturnClientConfig {
|
||||
public static ConfigManager config = new ConfigManager("Saturn Client");
|
||||
public static ConfigManager config;
|
||||
|
||||
public static Property<Integer> color = config.property(
|
||||
"Primary color",
|
||||
public static Property<Integer> color =
|
||||
new Property<>(
|
||||
ColorHelper.getArgb(255, 251, 60, 79),
|
||||
Property.PropertyType.HEX));
|
||||
Property.PropertyType.HEX);
|
||||
|
||||
public static Property<Integer> normal = config.property(
|
||||
"Default color",
|
||||
public static Property<Integer> normal =
|
||||
new Property<>(
|
||||
ColorHelper.getArgb(255, 182, 182, 182),
|
||||
Property.PropertyType.HEX));
|
||||
Property.PropertyType.HEX);
|
||||
|
||||
public static Property<Boolean> realisticLogo = config.property(
|
||||
"Realistic logo",
|
||||
new Property<>(false));
|
||||
public static Property<Boolean> realisticLogo =
|
||||
new Property<>(false);
|
||||
|
||||
public static Property<Boolean> saturnTitleScreen = config.property(
|
||||
"Saturn client title screen",
|
||||
new Property<>(true));
|
||||
public static Property<Boolean> saturnTitleScreen =
|
||||
new Property<>(true);
|
||||
|
||||
public static int WHITE = ColorHelper.getArgb(255, 255, 255, 255);
|
||||
public static TextRenderer textRenderer = null;
|
||||
@@ -56,4 +52,13 @@ public class SaturnClientConfig {
|
||||
public static String getSaturnIndicator() {
|
||||
return realisticLogo.value ? "" : "";
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
config = new ConfigManager("Saturn Client");
|
||||
|
||||
config.property("Primary color", color);
|
||||
config.property("Default color", normal);
|
||||
config.property("Realistic logo", realisticLogo);
|
||||
config.property("Saturn client title screen", saturnTitleScreen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public class ConfigManager {
|
||||
public ConfigManager(String namespace) {
|
||||
currentMap = new LinkedHashMap<>();
|
||||
properties.put(namespace, currentMap);
|
||||
System.out.println("Created namespace: " + namespace);
|
||||
}
|
||||
|
||||
public ConfigManager(ConfigManager config, String namespace) {
|
||||
@@ -35,10 +36,12 @@ public class ConfigManager {
|
||||
config.property(namespace, namespaceProperty);
|
||||
// Update the parent's state
|
||||
config.currentMap.put(namespace, namespaceProperty);
|
||||
System.out.println("Created sub-namespace: " + namespace);
|
||||
}
|
||||
|
||||
// Generic method to store any type of property
|
||||
public <T> Property<T> property(String name, Property<T> value) {
|
||||
System.out.println("Adding property: " + name);
|
||||
currentMap.put(name, value);
|
||||
return value;
|
||||
}
|
||||
@@ -55,6 +58,7 @@ public class ConfigManager {
|
||||
new String(Files.readAllBytes(configFile.toPath()))).getAsJsonObject();
|
||||
|
||||
for (String namespace : properties.keySet()) {
|
||||
SaturnClient.LOGGER.info("Loading namespace: " + namespace);
|
||||
JsonElement configElement = jsonObject.get(namespace);
|
||||
|
||||
if (configElement == null)
|
||||
@@ -76,6 +80,8 @@ public class ConfigManager {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void loadProperties(JsonObject config, Map<String, Property<?>> propertyMap) {
|
||||
SaturnClient.LOGGER.info("Loading properties: " + propertyMap);
|
||||
|
||||
for (String propertyName : propertyMap.keySet()) {
|
||||
JsonElement c = config.get(propertyName);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user