From 48bfed142f7175809a43037fb695b6fcdc4146b1 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 1 Jun 2023 11:38:04 -0400 Subject: finish gui level editor --- src/main/Difficulty.java | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/main/Difficulty.java') diff --git a/src/main/Difficulty.java b/src/main/Difficulty.java index 2c74956..c5dfca3 100644 --- a/src/main/Difficulty.java +++ b/src/main/Difficulty.java @@ -17,7 +17,7 @@ import javafx.collections.ObservableList; public class Difficulty { public File thisDir; - public String title; + public String title = "Unnamed"; private ObservableList leaderboard = FXCollections.observableArrayList(); public File notes; public int bpm; @@ -28,7 +28,6 @@ public class Difficulty public Difficulty(File file) { thisDir = file; - readData(); } public void readData() @@ -37,7 +36,7 @@ public class Difficulty { if (cur.getName().equals("metadata.json")) { - parseMetadata(cur); + parseMetadata(); } if (cur.getName().equals("leaderboard.json")) { @@ -55,8 +54,9 @@ public class Difficulty } - public void parseMetadata(File file) + public void parseMetadata() { + File file = new File(thisDir, "metadata.json"); JSONParser jsonParser = new JSONParser(); //parser to read the file try(FileReader reader = new FileReader(file)) @@ -139,7 +139,23 @@ public class Difficulty return title; } - public void writeMetadata() { - + public void writeMetadata() + { + FileWriter fileWriter; + try + { + File file = new File(thisDir, "metadata.json"); + fileWriter = new FileWriter(file); + JSONObject obj = new JSONObject(); + obj.put("title", title); + obj.put("bpm", bpm); + obj.put("numBeats", numBeats); + obj.writeJSONString(fileWriter); + fileWriter.flush(); + } + catch (IOException e) + { + e.printStackTrace(); + } } } -- cgit v1.2.3