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