From e62da29a4960c4692c9f2b06580349342ac981fa Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Sat, 21 Feb 2026 23:11:22 +0100 Subject: [PATCH] Sub namespace loading --- .../saturnclient/config/ConfigManager.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/saturnclient/saturnclient/config/ConfigManager.java b/src/main/java/org/saturnclient/saturnclient/config/ConfigManager.java index 87aab0e..bc628b1 100644 --- a/src/main/java/org/saturnclient/saturnclient/config/ConfigManager.java +++ b/src/main/java/org/saturnclient/saturnclient/config/ConfigManager.java @@ -11,8 +11,7 @@ import java.util.Map; public class ConfigManager { - private static final File configFile = - new File(SaturnClient.client.runDirectory, "saturn.json"); + private static final File configFile = new File(SaturnClient.client.runDirectory, "saturn.json"); // SINGLE ROOT TREE private static final Map> ROOT = new LinkedHashMap<>(); @@ -21,11 +20,14 @@ public class ConfigManager { private final Map> currentMap; + private final String[] path; + /** * Creates a root namespace */ public ConfigManager(String namespace) { this.currentMap = new LinkedHashMap<>(); + this.path = new String[] { namespace }; // Path is just ["namespace"] ROOT.put(namespace, Property.namespace(currentMap)); } @@ -34,6 +36,12 @@ public class ConfigManager { */ public ConfigManager(ConfigManager parent, String namespace) { this.currentMap = new LinkedHashMap<>(); + + // Build new path: parent path + current namespace + this.path = new String[parent.path.length + 1]; + System.arraycopy(parent.path, 0, this.path, 0, parent.path.length); + this.path[this.path.length - 1] = namespace; + parent.property(namespace, Property.namespace(currentMap)); } @@ -121,16 +129,30 @@ public class ConfigManager { } /** - * Load only a single property immediately after creation + * Load only a single property immediately after creation, + * traversing the JSON tree based on this manager's path. */ private void loadSingleProperty(String name, Property prop) { JsonObject source = cachedJson != null ? cachedJson : loadAndCache(); if (source == null) return; - JsonElement element = source.get(name); - if (element != null) + // Traverse the tree to the correct namespace + JsonObject currentScope = source; + for (String segment : path) { + JsonElement next = currentScope.get(segment); + if (next != null && next.isJsonObject()) { + currentScope = next.getAsJsonObject(); + } else { + return; // Path doesn't exist in config yet + } + } + + // Now look for the property inside the correctly nested object + JsonElement element = currentScope.get(name); + if (element != null) { prop.loadFromJson(element); + } } /**