diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2023-06-01 11:38:04 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2023-06-01 11:38:04 -0400 |
commit | 48bfed142f7175809a43037fb695b6fcdc4146b1 (patch) | |
tree | e489132ad42bd7049b9854f6d6ed74673c796f43 /src/main | |
parent | 6c216a309838bf1cbeb19070ce180c0170ccd3c9 (diff) | |
download | NPEhero-48bfed142f7175809a43037fb695b6fcdc4146b1.tar.gz NPEhero-48bfed142f7175809a43037fb695b6fcdc4146b1.tar.bz2 NPEhero-48bfed142f7175809a43037fb695b6fcdc4146b1.zip |
finish gui level editor
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/Difficulty.java | 28 | ||||
-rw-r--r-- | src/main/Level.java | 35 | ||||
-rw-r--r-- | src/main/LevelController.java | 14 |
3 files changed, 41 insertions, 36 deletions
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<LeaderboardEntry> 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(); + } } } diff --git a/src/main/Level.java b/src/main/Level.java index 95d6b5d..56433f3 100644 --- a/src/main/Level.java +++ b/src/main/Level.java @@ -12,24 +12,24 @@ import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; +import devmenu.LevelList; import gui.Driver; public class Level { public File thisDir; - private String title; - private String artist; + private String title = "Unnamed"; + private String artist = "Unknown"; private ArrayList<Difficulty> diffList; public Image preview; //optional - public String desc; + public String desc = "No description"; public Image background; //optional - public Color[] colors;//optional, have default colors + public Color[] colors = {Color.RED,Color.BLUE,Color.GREEN,Color.PURPLE,Color.YELLOW};//optional, have default colors public Level(File dir) { thisDir = dir; - readData(); } public void readData() @@ -40,6 +40,7 @@ public class Level if (cur.isDirectory()) //all subfolders within a level folder are difficulties { Difficulty diff = new Difficulty(cur); + diff.readData(); diffList.add(diff); } @@ -105,12 +106,13 @@ public class Level obj.put("title", title); obj.put("artist", artist); obj.put("desc", desc); - obj.put("color1",colors[0]); - obj.put("color2",colors[1]); - obj.put("color3",colors[2]); - obj.put("color4",colors[3]); - obj.put("color5",colors[4]); + obj.put("color1",colors[0].toString()); + obj.put("color2",colors[1].toString()); + obj.put("color3",colors[2].toString()); + obj.put("color4",colors[3].toString()); + obj.put("color5",colors[4].toString()); obj.writeJSONString(fileWriter); + fileWriter.flush(); } catch (IOException e) { e.printStackTrace(); @@ -132,19 +134,12 @@ public class Level } catch (IOException e) { e.printStackTrace(); } + Difficulty temp = new Difficulty(diffDir); + temp.title = text; + temp.writeMetadata(); readData(); } - public void removeDiff(Difficulty diff) - { - //soon - } - - public void renameDiff(Difficulty diff, String newName) - { - //soon - } - public String getTitle() { return title; diff --git a/src/main/LevelController.java b/src/main/LevelController.java index eff512d..9a94838 100644 --- a/src/main/LevelController.java +++ b/src/main/LevelController.java @@ -22,6 +22,7 @@ public class LevelController for (File cur: thisDir.listFiles()) //iterates through all files/folders in levels { Level level = new Level(cur); + level.readData(); levelList.add(level); } } @@ -39,16 +40,9 @@ public class LevelController { e.printStackTrace(); } + Level temp = new Level(levelDir); + temp.setTitle(text); + temp.writeMetadata(); readData(); } - - public void removeLevel(Level level) - { - //soon - } - - public void renameLevel(Level level, String newName) - { - //soon - } }
\ No newline at end of file |