Skip to content

Commit cf58538

Browse files
committed
final v2.0.0
1 parent 48298a0 commit cf58538

3 files changed

Lines changed: 36 additions & 65 deletions

File tree

src/main/java/dsns/betterhud/BetterHUDGUI.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@ public void onStartTick(MinecraftClient client) {
3838
for (BaseMod mod : BetterHUD.mods) {
3939
ModSettings modSettings = mod.getModSettings();
4040
if (!modSettings.getSetting("Enabled").getBooleanValue()) continue;
41-
System.out.println(
42-
modSettings.getSetting("Enabled").getBooleanValue()
43-
);
4441

4542
CustomText modText = mod.onStartTick(client);
46-
System.out.println(modText);
4743
if (modText == null) continue;
4844

4945
String orientation = modSettings

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

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,31 @@ public static void configure() {
3232
}
3333
}
3434

35+
private static String titleCaseToCamelCase(String title) {
36+
if (title == null || title.trim().isEmpty()) {
37+
return title;
38+
}
39+
40+
String[] words = title.trim().split("\\s+");
41+
if (words.length == 0) {
42+
return "";
43+
}
44+
45+
StringBuilder result = new StringBuilder(words[0].toLowerCase());
46+
47+
for (int i = 1; i < words.length; i++) {
48+
String word = words[i];
49+
if (!word.isEmpty()) {
50+
String camelWord =
51+
word.substring(0, 1).toUpperCase() +
52+
word.substring(1).toLowerCase();
53+
result.append(camelWord);
54+
}
55+
}
56+
57+
return result.toString();
58+
}
59+
3560
public static void serialize() {
3661
Properties prop = new Properties();
3762
HashMap<String, String> serialized = new HashMap<String, String>();
@@ -73,7 +98,6 @@ public static void deserialize() {
7398
map.put(name, prop.getProperty(name));
7499
}
75100

76-
int updatedCount = 0;
77101
for (Map.Entry<String, ModSettings> modEntry : settings.entrySet()) {
78102
String modID = modEntry.getKey();
79103
ModSettings modSetting = modEntry.getValue();
@@ -82,10 +106,15 @@ public static void deserialize() {
82106
.getSettings()
83107
.entrySet()) {
84108
String fullKey = modID + "." + entry.getKey();
109+
String oldConfigKey =
110+
modID + "." + titleCaseToCamelCase(entry.getKey());
111+
85112
String val = map.get(fullKey);
113+
String oldVal = map.get(oldConfigKey);
86114
if (val != null) {
87115
entry.getValue().setValue(val);
88-
updatedCount++;
116+
} else if (oldVal != null) {
117+
entry.getValue().setValue(oldVal);
89118
}
90119
}
91120
}
@@ -101,13 +130,8 @@ public static void deserialize() {
101130
.getSetting("Background Color");
102131
if (bgSetting != null) {
103132
bgSetting.setValue(globalBg);
104-
updatedCount++;
105133
}
106134
}
107-
System.out.println(
108-
// Remove this debug line in release
109-
"Migrated global backgroundColor to all mods: " + globalBg
110-
);
111135
}
112136

113137
String globalText = map.get("textColor");
@@ -121,18 +145,10 @@ public static void deserialize() {
121145
.getSetting("Text Color");
122146
if (textSetting != null) {
123147
textSetting.setValue(globalText);
124-
updatedCount++;
125148
}
126149
}
127-
System.out.println(
128-
// Remove this debug line in release
129-
"Migrated global textColor to all mods: " + globalText
130-
);
131150
}
132151

133-
// Ignore other old globals (e.g., horizontalMargin) unless you map them to specific settings
134-
135-
System.out.println("Deserialized " + updatedCount + " settings."); // Remove this debug line in release
136-
serialize(); // Re-save with migrated values
152+
serialize();
137153
}
138154
}

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

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,10 @@
33
import dsns.betterhud.util.BaseMod;
44
import dsns.betterhud.util.CustomText;
55
import dsns.betterhud.util.ModSettings;
6-
import dsns.betterhud.util.Setting;
7-
import java.util.ArrayList;
8-
import java.util.LinkedHashMap;
9-
import java.util.List;
10-
import java.util.Map;
116
import net.minecraft.client.MinecraftClient;
127
import net.minecraft.entity.player.PlayerEntity;
138
import net.minecraft.util.math.MathHelper;
149

15-
class MomentumSettings extends ModSettings {
16-
17-
public MomentumSettings(String position) {
18-
super(position);
19-
LinkedHashMap<String, Setting> settings = super.getSettings();
20-
21-
List<Map.Entry<String, Setting>> entries = new ArrayList<>(
22-
settings.entrySet()
23-
);
24-
settings.clear();
25-
26-
int insertIndex = 2;
27-
28-
for (int i = 0; i < Math.min(insertIndex, entries.size()); i++) {
29-
Map.Entry<String, Setting> entry = entries.get(i);
30-
settings.put(entry.getKey(), entry.getValue());
31-
}
32-
33-
settings.put("Decimal", Setting.createBooleanSetting(false));
34-
35-
for (int i = insertIndex; i < entries.size(); i++) {
36-
Map.Entry<String, Setting> entry = entries.get(i);
37-
settings.put(entry.getKey(), entry.getValue());
38-
}
39-
}
40-
}
41-
4210
public class Momentum implements BaseMod {
4311

4412
private static final ModSettings SETTINGS = new ModSettings("top-left");
@@ -67,18 +35,9 @@ public CustomText onStartTick(MinecraftClient client) {
6735
) /
6836
0.05F;
6937

70-
if (SETTINGS.getSetting("Decimal").getBooleanValue()) {
71-
return new CustomText(
72-
String.format("%.2f m/s", currentSpeed),
73-
getModSettings()
74-
);
75-
} else {
76-
int roundedSpeed = (int) currentSpeed;
77-
78-
return new CustomText(
79-
String.format(roundedSpeed + " m/s"),
80-
getModSettings()
81-
);
82-
}
38+
return new CustomText(
39+
String.format("%.2f m/s", currentSpeed),
40+
getModSettings()
41+
);
8342
}
8443
}

0 commit comments

Comments
 (0)