diff --git a/.idea/misc.xml b/.idea/misc.xml
index f16dea7..5d98256 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -4,7 +4,7 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/eu/midnightdust/yaytris/ui/ScoreMenu.java b/src/main/java/eu/midnightdust/yaytris/ui/ScoreMenu.java
index 8e70399..cd6c804 100644
--- a/src/main/java/eu/midnightdust/yaytris/ui/ScoreMenu.java
+++ b/src/main/java/eu/midnightdust/yaytris/ui/ScoreMenu.java
@@ -43,7 +43,7 @@ public class ScoreMenu extends AbstractMenu {
}
public void updateScore(int score) {
- this.currentScoreLabel.setText("Score: %s".formatted(score));
+ this.currentScoreLabel.setText(String.format("Score: %s", score));
this.repaint();
}
@@ -51,7 +51,7 @@ public class ScoreMenu extends AbstractMenu {
LocalTime timeElapsed = LocalTime.ofNanoOfDay(LocalTime.now().toNanoOfDay() - startingTime.toNanoOfDay());
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern(timeElapsed.getHour() > 0 ? "HH:mm:ss" : "mm:ss");
- this.currentTimeLabel.setText("Zeit: %s".formatted(timeFormatter.format(timeElapsed)));
+ this.currentTimeLabel.setText(String.format("Zeit: %s", timeFormatter.format(timeElapsed)));
this.repaint();
}
diff --git a/src/main/java/eu/midnightdust/yaytris/util/NightJson.java b/src/main/java/eu/midnightdust/yaytris/util/NightJson.java
index fad0a94..3b90498 100644
--- a/src/main/java/eu/midnightdust/yaytris/util/NightJson.java
+++ b/src/main/java/eu/midnightdust/yaytris/util/NightJson.java
@@ -17,15 +17,8 @@ public class NightJson {
Class> jsonClass;
String fileLocation;
- public NightJson(Class> jsonClass) {
- this.jsonClass = jsonClass;
- }
public NightJson(Class> jsonClass, String fileLocation) {
- this(jsonClass);
- this.fileLocation = fileLocation;
- }
-
- public void setFileLocation(String fileLocation) {
+ this.jsonClass = jsonClass;
this.fileLocation = fileLocation;
}
@@ -40,10 +33,10 @@ public class NightJson {
Field field = it.next();
jsonFile.write("\t");
if (field.getType() == Comment.class) {
- jsonFile.write("// %s\n".formatted(((Comment) field.get(null)).commentString));
+ jsonFile.write(String.format("// %s\n", ((Comment) field.get(null)).commentString));
continue;
}
- jsonFile.write((field.getType() == String.class || field.getType().isEnum() ? "\"%s\": \"%s\"" : "\"%s\": %s").formatted(field.getName(), field.get(null)));
+ jsonFile.write(String.format(field.getType() == String.class || field.getType().isEnum() ? "\"%s\": \"%s\"" : "\"%s\": %s", field.getName(), field.get(null)));
jsonFile.write(it.hasNext() ? ",\n" : "\n");
}
jsonFile.write("}");
@@ -85,17 +78,7 @@ public class NightJson {
try { field = jsonClass.getField(key);
} catch (NoSuchFieldException e) {continue;}
- Object value = switch (field.getType().getName()) {
- case "byte" -> Byte.parseByte(currentString);
- case "int" -> Integer.parseInt(currentString);
- case "long" -> Long.parseLong(currentString);
- case "float" -> Float.parseFloat(currentString);
- case "double" -> Double.parseDouble(currentString);
- default -> currentString;
- };
- if (field.getType().isEnum()) value = Arrays.stream(field.getType().getEnumConstants())
- .filter(enumConstant -> Objects.equals(enumConstant.toString(), currentString)).findFirst().orElseThrow();
- field.set(field, value);
+ field.set(field, stringToObj(field, currentString));
}
jsonFile.close();
} catch (IOException | IllegalAccessException | NoSuchElementException e) {
@@ -104,6 +87,19 @@ public class NightJson {
}
}
+ private Object stringToObj(Field field, String currentString) {
+ switch (field.getType().getName()) {
+ case "byte": return Byte.parseByte(currentString);
+ case "int": return Integer.parseInt(currentString);
+ case "long": return Long.parseLong(currentString);
+ case "float": return Float.parseFloat(currentString);
+ case "double": return Double.parseDouble(currentString);
+ }
+ if (field.getType().isEnum()) return Arrays.stream(field.getType().getEnumConstants())
+ .filter(enumConstant -> Objects.equals(enumConstant.toString(), currentString)).findFirst().orElseThrow();
+ else return currentString;
+ }
+
public static class Comment {
final String commentString;
public Comment(String commentString) {