@@ -19,23 +19,47 @@ public class Config {
1919
2020 private static HashMap <String , ModSettings > settings = new HashMap <>();
2121
22- public static void configure (ArrayList <BaseMod > mods ) {
23- if (settings .size () == 0 ) {
24- for (BaseMod mod : mods ) {
25- settings .put (mod .getModID (), mod .getModSettings ());
26- }
27- }
28-
22+ public static void configure () {
2923 if (Files .exists (configPath )) {
30- deserialize (mods );
24+ deserialize ();
3125 } else {
3226 serialize ();
3327 }
3428 }
3529
3630 public static void serialize () {
31+ HashMap <String , ModSettings > settings = new HashMap <>();
32+
33+ if (settings .size () == 0 ) {
34+ for (BaseMod mod : BetterHUD .mods ) {
35+ settings .put (mod .getModID (), mod .getModSettings ());
36+ }
37+ }
38+
3739 Properties prop = new Properties ();
38- prop .putAll (settings );
40+
41+ HashMap <String , String > serialized = new HashMap <String , String >();
42+
43+ for (Map .Entry <String , ModSettings > entry : settings .entrySet ()) {
44+ ModSettings modSettings = entry .getValue ();
45+
46+ for (Map .Entry <String , Setting > settingEntry : modSettings
47+ .getSettings ()
48+ .entrySet ()) {
49+ System .out .println (settingEntry );
50+ System .out .println (settingEntry .getValue ());
51+ System .out .println (settingEntry .getValue ().getStringValue ());
52+
53+ serialized .put (
54+ entry .getKey () + "." + settingEntry .getKey (),
55+ settingEntry .getValue ().getStringValue ()
56+ );
57+ }
58+ }
59+
60+ System .out .println ("Serialized settings: " + serialized );
61+
62+ prop .putAll (serialized );
3963
4064 try {
4165 prop .store (Files .newOutputStream (configPath ), null );
@@ -44,29 +68,91 @@ public static void serialize() {
4468 }
4569 }
4670
47- public static void deserialize (ArrayList < BaseMod > mods ) {
71+ public static void deserialize () {
4872 Properties prop = new Properties ();
4973 try {
5074 prop .load (Files .newInputStream (configPath ));
75+ System .out .println (
76+ "Loaded config with " + prop .size () + " properties."
77+ );
5178 } catch (Exception e ) {
79+ System .err .println ("Failed to load config: " + e .getMessage ());
5280 e .printStackTrace ();
81+ return ;
5382 }
5483
5584 Map <String , String > map = new HashMap <String , String >();
56-
5785 for (final String name : prop .stringPropertyNames ()) {
5886 map .put (name , prop .getProperty (name ));
5987 }
6088
61- // set each setting
62- for (ModSettings modSetting : settings .values ()) {
89+ // Load per-mod prefixed settings
90+ int updatedCount = 0 ;
91+ for (Map .Entry <String , ModSettings > modEntry : settings .entrySet ()) {
92+ String modID = modEntry .getKey ();
93+ ModSettings modSetting = modEntry .getValue ();
94+
6395 for (Map .Entry <String , Setting > entry : modSetting
6496 .getSettings ()
6597 .entrySet ()) {
66- entry .getValue ().setValue (map .get (entry .getKey ()));
98+ String fullKey = modID + "." + entry .getKey ();
99+ String val = map .get (fullKey );
100+ if (val != null ) {
101+ entry .getValue ().setValue (val );
102+ updatedCount ++;
103+ System .out .println (
104+ "Deserialized: " + fullKey + " = " + val
105+ ); // Debug (remove after)
106+ } else {
107+ System .out .println (
108+ "No value found for " + fullKey + "; keeping default."
109+ ); // Debug (remove after)
110+ }
67111 }
68112 }
69113
70- serialize ();
114+ // Backwards compatibility: Migrate old global settings to all mods (one-time)
115+ String globalBg = map .get ("backgroundColor" );
116+ if (globalBg != null ) {
117+ for (Map .Entry <
118+ String ,
119+ ModSettings
120+ > modEntry : settings .entrySet ()) {
121+ Setting bgSetting = modEntry
122+ .getValue ()
123+ .getSetting ("Background Color" );
124+ if (bgSetting != null ) {
125+ bgSetting .setValue (globalBg );
126+ updatedCount ++;
127+ }
128+ }
129+ System .out .println (
130+ "Migrated global backgroundColor to all mods: " + globalBg
131+ );
132+ }
133+
134+ String globalText = map .get ("textColor" );
135+ if (globalText != null ) {
136+ for (Map .Entry <
137+ String ,
138+ ModSettings
139+ > modEntry : settings .entrySet ()) {
140+ Setting textSetting = modEntry
141+ .getValue ()
142+ .getSetting ("Text Color" );
143+ if (textSetting != null ) {
144+ textSetting .setValue (globalText );
145+ updatedCount ++;
146+ }
147+ }
148+ System .out .println (
149+ "Migrated global textColor to all mods: " + globalText
150+ );
151+ }
152+
153+ // Ignore other old globals (e.g., horizontalMargin) unless you map them to specific settings
154+
155+ System .out .println ("Deserialized " + updatedCount + " settings." );
156+ serialize (); // Re-save with migrated values
71157 }
72158}
0 commit comments