Skip to content

Commit b5f9370

Browse files
committed
working
1 parent 8d0c377 commit b5f9370

9 files changed

Lines changed: 43 additions & 39 deletions

File tree

src/main/java/dsns/betterhud/Config.java

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import dsns.betterhud.util.Setting;
66
import java.nio.file.Files;
77
import java.nio.file.Path;
8-
import java.util.ArrayList;
98
import java.util.HashMap;
109
import java.util.Map;
1110
import 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
}

src/main/java/dsns/betterhud/mods/Biome.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212

1313
public class Biome implements BaseMod {
1414

15+
private static final ModSettings SETTINGS = new ModSettings("top-right");
16+
1517
@Override
1618
public String getModID() {
1719
return "Biome";
1820
}
1921

2022
@Override
2123
public ModSettings getModSettings() {
22-
return new ModSettings("top-right");
24+
return SETTINGS;
2325
}
2426

2527
@Override

src/main/java/dsns/betterhud/mods/Coordinates.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ public CoordinatesSettings(String position) {
1919

2020
public class Coordinates implements BaseMod {
2121

22+
private static final CoordinatesSettings SETTINGS = new CoordinatesSettings(
23+
"top-right"
24+
);
25+
2226
@Override
2327
public String getModID() {
2428
return "Coordinates";
2529
}
2630

2731
@Override
2832
public ModSettings getModSettings() {
29-
return new CoordinatesSettings("top-right");
33+
return SETTINGS;
3034
}
3135

3236
@Override

src/main/java/dsns/betterhud/mods/FPS.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88

99
public class FPS implements BaseMod {
1010

11+
private static final ModSettings SETTINGS = new ModSettings("top-left");
12+
1113
@Override
1214
public String getModID() {
1315
return "FPS";
1416
}
1517

1618
@Override
1719
public ModSettings getModSettings() {
18-
return new ModSettings("top-left");
20+
return SETTINGS;
1921
}
2022

2123
@Override

src/main/java/dsns/betterhud/mods/Facing.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88

99
public class Facing implements BaseMod {
1010

11+
private static final CoordinatesSettings SETTINGS = new CoordinatesSettings(
12+
"top-right"
13+
);
14+
1115
@Override
1216
public String getModID() {
1317
return "Facing";
1418
}
1519

1620
@Override
1721
public ModSettings getModSettings() {
18-
return new ModSettings("top-right");
22+
return SETTINGS;
1923
}
2024

2125
@Override

src/main/java/dsns/betterhud/mods/Momentum.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99

1010
public class Momentum implements BaseMod {
1111

12+
private static final ModSettings SETTINGS = new ModSettings("top-left");
13+
1214
@Override
1315
public String getModID() {
1416
return "Momentum";
1517
}
1618

1719
@Override
1820
public ModSettings getModSettings() {
19-
return new ModSettings("top-right");
21+
return SETTINGS;
2022
}
2123

2224
@Override

src/main/java/dsns/betterhud/mods/Ping.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88

99
public class Ping implements BaseMod {
1010

11+
private static final ModSettings SETTINGS = new ModSettings("top-left");
12+
1113
@Override
1214
public String getModID() {
1315
return "Ping";
1416
}
1517

1618
@Override
1719
public ModSettings getModSettings() {
18-
return new ModSettings("top-left");
20+
return SETTINGS;
1921
}
2022

2123
@Override

src/main/java/dsns/betterhud/mods/Time.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99

1010
public class Time implements BaseMod {
1111

12+
private static final ModSettings SETTINGS = new ModSettings("bottom-right");
13+
1214
@Override
1315
public String getModID() {
1416
return "Time";
1517
}
1618

1719
@Override
1820
public ModSettings getModSettings() {
19-
return new ModSettings("bottom-right");
21+
return SETTINGS;
2022
}
2123

2224
@Override

src/main/java/dsns/betterhud/util/ModSettings.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
public class ModSettings {
66

7-
private LinkedHashMap<String, Setting> settings = new LinkedHashMap<String, Setting>();
7+
private LinkedHashMap<String, Setting> settings = new LinkedHashMap<
8+
String,
9+
Setting
10+
>();
811

912
public ModSettings() {
10-
settings.put("enabled", Setting.createBooleanSetting(true));
13+
settings.put("Enabled", Setting.createBooleanSetting(true));
1114

1215
settings.put(
1316
"Orientation",
@@ -26,7 +29,10 @@ public ModSettings() {
2629
settings.put("Custom X", Setting.createIntegerSetting(0, 0, 100));
2730
settings.put("Custom Y", Setting.createIntegerSetting(0, 0, 100));
2831
settings.put("Text Color", Setting.createColorSetting(0xffffffff));
29-
settings.put("Background Color", Setting.createColorSetting(0x88000000));
32+
settings.put(
33+
"Background Color",
34+
Setting.createColorSetting(0x88000000)
35+
);
3036
}
3137

3238
public ModSettings(String orientation) {

0 commit comments

Comments
 (0)