aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/neodymium/config
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2022-06-30 16:15:25 +0200
committermakamys <makamys@outlook.com>2022-06-30 16:58:14 +0200
commit33162cb3ecbd8ad26cd6b363854d92c63a5e5f91 (patch)
tree8af69de2dcd6c7e2d44dc3f39eae12320c0366c2 /src/main/java/makamys/neodymium/config
parente599b420e4ac09a68c19c2e083facdd44ca9b3ae (diff)
downloadNeodymium-33162cb3ecbd8ad26cd6b363854d92c63a5e5f91.tar.gz
Neodymium-33162cb3ecbd8ad26cd6b363854d92c63a5e5f91.tar.bz2
Neodymium-33162cb3ecbd8ad26cd6b363854d92c63a5e5f91.zip
Make names in config GUI more human readable
Diffstat (limited to 'src/main/java/makamys/neodymium/config')
-rw-r--r--src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java b/src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java
new file mode 100644
index 0000000..761f114
--- /dev/null
+++ b/src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java
@@ -0,0 +1,39 @@
+package makamys.neodymium.config;
+
+import net.minecraftforge.common.config.ConfigElement;
+import net.minecraftforge.common.config.Property;
+
+public class HumanReadableConfigElement extends ConfigElement {
+
+ public HumanReadableConfigElement(Property prop) {
+ super(prop);
+ }
+
+ @Override
+ public String getName() {
+ return decamelize(super.getName());
+ }
+
+ private static String decamelize(String s) {
+ boolean[] spaceField = new boolean[s.length()];
+
+ for(int i = 0; i < s.length(); i++) {
+ if(i > 0 && i < s.length() && !Character.isUpperCase(s.charAt(i - 1)) && Character.isUpperCase(s.charAt(i))) {
+ spaceField[i] = true;
+ } else if(i > 2 && Character.isUpperCase(s.charAt(i - 2)) && Character.isUpperCase(s.charAt(i - 1)) && !Character.isUpperCase(s.charAt(i))) {
+ spaceField[i - 1] = true;
+ }
+ }
+
+ String out = "";
+ for(int i = 0; i < s.length(); i++) {
+ if(spaceField[i]) {
+ out += " ";
+ }
+ out += i == 0 ? Character.toUpperCase(s.charAt(i)) : s.charAt(i);
+ }
+
+ return out;
+ }
+
+}