55import dsns .betterhud .util .Setting ;
66import java .nio .file .Files ;
77import java .nio .file .Path ;
8- import java .util .ArrayList ;
98import java .util .HashMap ;
109import java .util .Map ;
1110import java .util .Properties ;
@@ -20,6 +19,12 @@ public class Config {
2019 private static HashMap <String , ModSettings > settings = new HashMap <>();
2120
2221 public static void configure () {
22+ if (settings .isEmpty ()) {
23+ for (BaseMod mod : BetterHUD .mods ) {
24+ settings .put (mod .getModID (), mod .getModSettings ());
25+ }
26+ }
27+
2328 if (Files .exists (configPath )) {
2429 deserialize ();
2530 } else {
@@ -28,16 +33,7 @@ public static void configure() {
2833 }
2934
3035 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-
3936 Properties prop = new Properties ();
40-
4137 HashMap <String , String > serialized = new HashMap <String , String >();
4238
4339 for (Map .Entry <String , ModSettings > entry : settings .entrySet ()) {
@@ -46,19 +42,13 @@ public static void serialize() {
4642 for (Map .Entry <String , Setting > settingEntry : modSettings
4743 .getSettings ()
4844 .entrySet ()) {
49- System .out .println (settingEntry );
50- System .out .println (settingEntry .getValue ());
51- System .out .println (settingEntry .getValue ().getStringValue ());
52-
5345 serialized .put (
5446 entry .getKey () + "." + settingEntry .getKey (),
5547 settingEntry .getValue ().getStringValue ()
5648 );
5749 }
5850 }
5951
60- System .out .println ("Serialized settings: " + serialized );
61-
6252 prop .putAll (serialized );
6353
6454 try {
@@ -72,9 +62,6 @@ public static void deserialize() {
7262 Properties prop = new Properties ();
7363 try {
7464 prop .load (Files .newInputStream (configPath ));
75- System .out .println (
76- "Loaded config with " + prop .size () + " properties."
77- );
7865 } catch (Exception e ) {
7966 System .err .println ("Failed to load config: " + e .getMessage ());
8067 e .printStackTrace ();
@@ -86,7 +73,6 @@ public static void deserialize() {
8673 map .put (name , prop .getProperty (name ));
8774 }
8875
89- // Load per-mod prefixed settings
9076 int updatedCount = 0 ;
9177 for (Map .Entry <String , ModSettings > modEntry : settings .entrySet ()) {
9278 String modID = modEntry .getKey ();
@@ -100,18 +86,10 @@ public static void deserialize() {
10086 if (val != null ) {
10187 entry .getValue ().setValue (val );
10288 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)
11089 }
11190 }
11291 }
11392
114- // Backwards compatibility: Migrate old global settings to all mods (one-time)
11593 String globalBg = map .get ("backgroundColor" );
11694 if (globalBg != null ) {
11795 for (Map .Entry <
@@ -127,6 +105,7 @@ public static void deserialize() {
127105 }
128106 }
129107 System .out .println (
108+ // Remove this debug line in release
130109 "Migrated global backgroundColor to all mods: " + globalBg
131110 );
132111 }
@@ -146,13 +125,14 @@ public static void deserialize() {
146125 }
147126 }
148127 System .out .println (
128+ // Remove this debug line in release
149129 "Migrated global textColor to all mods: " + globalText
150130 );
151131 }
152132
153133 // Ignore other old globals (e.g., horizontalMargin) unless you map them to specific settings
154134
155- System .out .println ("Deserialized " + updatedCount + " settings." );
135+ System .out .println ("Deserialized " + updatedCount + " settings." ); // Remove this debug line in release
156136 serialize (); // Re-save with migrated values
157137 }
158138}
0 commit comments