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 ++++++++++++++++++++++------ src/main/Level.java | 35 +++++++++++++++-------------------- src/main/LevelController.java | 14 ++++---------- 3 files changed, 41 insertions(+), 36 deletions(-) (limited to 'src/main') 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(); + } } } 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 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 -- cgit v1.2.3 From 4e43d6f020d908ccd9b8a6b77803cac943da00ed Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 2 Jun 2023 00:48:13 -0400 Subject: Finish levelUtility and project cleanup --- src/main/Difficulty.java | 110 +++++++++++++++++++++++---------------- src/main/Level.java | 95 ++++++++++++++++++++++++++------- src/main/LevelController.java | 32 ++++++++++++ src/main/SettingsController.java | 36 ++++++------- 4 files changed, 189 insertions(+), 84 deletions(-) (limited to 'src/main') diff --git a/src/main/Difficulty.java b/src/main/Difficulty.java index c5dfca3..18dabb3 100644 --- a/src/main/Difficulty.java +++ b/src/main/Difficulty.java @@ -1,16 +1,13 @@ package main; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.time.LocalDate; - import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; - import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -21,15 +18,20 @@ public class Difficulty private ObservableList leaderboard = FXCollections.observableArrayList(); public File notes; public int bpm; - public File song; public int numBeats; - private File leaderboardFile; - public Difficulty(File file) + /** + * Creates a new Difficulty and gives it a file path + * @param newDir: The file path of the Difficulty + */ + public Difficulty(File newDir) { - thisDir = file; + thisDir = newDir; } + /** + * Checks for files in the difficulty folder and runs cooresponding actions + */ public void readData() { for(File cur: thisDir.listFiles()) //iterates through all files/folders in src/assets/levels/LEVEL/DIFFICULTY @@ -40,20 +42,18 @@ public class Difficulty } if (cur.getName().equals("leaderboard.json")) { - parseLeaderboard(cur); + parseLeaderboard(); } if (cur.getName().equals("notes.txt")) { notes = cur; } - if (cur.getName().equals("song.wav")) - { - song = cur; - } } } - + /** + * Reads in json metadata and assigns values to variables + */ public void parseMetadata() { File file = new File(thisDir, "metadata.json"); @@ -65,20 +65,44 @@ public class Difficulty JSONObject diffStuff = (JSONObject)(obj); //converts read object to a JSONObject title = (String) diffStuff.get("title"); - bpm = (int)(diffStuff.get("bpm")); - numBeats = (int)(diffStuff.get("numBeats")); - + bpm = Integer.parseInt(diffStuff.get("bpm")+""); + numBeats = Integer.parseInt(diffStuff.get("numBeats")+""); } catch (Exception e) { - System.out.println("Error in json file "+file); - //e.printStackTrace(); + e.printStackTrace(); } } - public void parseLeaderboard(File file) + /** + * Writes metadata to json file + */ + public void writeMetadata() { - leaderboardFile = file; + 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(); + } + } + + /** + * Reads in json leaderboard and assigns populates list with leaderboardEntries + */ + public void parseLeaderboard() + { + File file = new File(thisDir, "leaderboard.json"); JSONParser jsonParser = new JSONParser(); //parser to read the file try(FileReader reader = new FileReader(file)) @@ -99,17 +123,20 @@ public class Difficulty } catch (Exception e) { - System.out.println("Error in json file "+leaderboardFile); - //e.printStackTrace(); + e.printStackTrace(); } } - public void addToLeaderboard(String name, int score) + /** + * Writes leaderboard to json file + */ + public void writeLeaderboard() { - leaderboard.add(new LeaderboardEntry(name, score, ""+LocalDate.now())); //do not delete this tho its not a placeholder - - try (FileWriter fileWriter = new FileWriter(leaderboardFile)) + FileWriter fileWriter; + try { + File file = new File(thisDir, "leaderboard.json"); + fileWriter = new FileWriter(file); //write the settings JSONObject instance to the file JSONArray jsonArray = new JSONArray(); for (LeaderboardEntry cur: leaderboard) @@ -129,6 +156,17 @@ public class Difficulty } } + /** + * Adds new leaderboardEntry to list and updates json file + * @param name: the players name + * @param score the players score + */ + public void addToLeaderboard(String name, int score) + { + leaderboard.add(new LeaderboardEntry(name, score, ""+LocalDate.now())); //do not delete this tho its not a placeholder + writeLeaderboard(); + } + public ObservableList getLeaderboard() { return leaderboard; @@ -138,24 +176,4 @@ public class Difficulty { return title; } - - 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 56433f3..591bd9a 100644 --- a/src/main/Level.java +++ b/src/main/Level.java @@ -2,18 +2,17 @@ package main; import java.io.File; import java.util.ArrayList; +import java.util.Comparator; import javafx.scene.image.Image; import javafx.scene.paint.Color; import java.io.FileWriter; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; 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 { @@ -26,12 +25,20 @@ public class Level public String desc = "No description"; public Image background; //optional public Color[] colors = {Color.RED,Color.BLUE,Color.GREEN,Color.PURPLE,Color.YELLOW};//optional, have default colors + public File song; - public Level(File dir) + /** + * Creates a new level and gives it a file path + * @param newDir: The path of the Level + */ + public Level(File newDir) { - thisDir = dir; + thisDir = newDir; } + /** + * Checks for files in the level folder and runs cooresponding actions + */ public void readData() { diffList = new ArrayList(); @@ -43,24 +50,28 @@ public class Level diff.readData(); diffList.add(diff); } - - if (cur.getName().equals("preview.png")) - { - preview = new Image(cur.toURI().toString()); - } - if (cur.getName().equals("metadata.json")) { parseMetadata(); } - + if (cur.getName().equals("preview.png")) + { + preview = new Image(cur.toURI().toString()); + } if (cur.getName().equals("background.png")) { background = new Image(cur.toURI().toString()); } + if (cur.getName().equals("song.wav")) + { + song = cur; + } } } + /** + * Reads in json metadata and assigns values to variables + */ public void parseMetadata() { JSONParser jsonParser = new JSONParser(); //parser to read the file @@ -96,6 +107,9 @@ public class Level } } + /** + * Writes metadata to json file + */ public void writeMetadata() { FileWriter fileWriter; @@ -119,27 +133,70 @@ public class Level } } - public ArrayList getDiffList() - { - return diffList; - } - + /** + * Adds a difficulty by creating a directory and required files + * @param text: the name of the directory and default title + */ public void addDiff(String text) { File diffDir = new File(thisDir, text); diffDir.mkdirs(); File metadataDir = new File(diffDir, "metadata.json"); + File leaderboardDir = new File(diffDir, "leaderboard.json"); + File notesDir = new File(diffDir, "notes.txt"); try { metadataDir.createNewFile(); + leaderboardDir.createNewFile(); + notesDir.createNewFile(); } catch (IOException e) { e.printStackTrace(); } Difficulty temp = new Difficulty(diffDir); temp.title = text; temp.writeMetadata(); + temp.writeLeaderboard(); + readData(); + } + + /** + * Removes the difficaulty from the filesystem then reloads the level + * @param diff: the difficulty to be removed + */ + public void removeDiff(Difficulty diff) + { + File hold = diff.thisDir; + diffList.remove(diff); + + try { + Files.walk(hold.toPath()) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Copies a file into the level directory + * @param newFile: the file to be copied + * @param name: the new file name + */ + public void addFile(File newFile, String name) + { + try { + Files.copy(newFile.toPath(), new File(thisDir, name).toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + e.printStackTrace(); + } readData(); } + public ArrayList getDiffList() + { + return diffList; + } + public String getTitle() { return title; diff --git a/src/main/LevelController.java b/src/main/LevelController.java index 9a94838..78d638a 100644 --- a/src/main/LevelController.java +++ b/src/main/LevelController.java @@ -2,6 +2,9 @@ package main; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Comparator; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -11,11 +14,17 @@ public class LevelController File thisDir = new File("levels"); public static ObservableList levelList; + /** + * Creates a levelController, which holds all the levels + */ public LevelController() { readData(); } + /** + * Reads contents of folder and creates cooresponding levels + */ public void readData() { levelList = FXCollections.observableArrayList(); @@ -27,6 +36,10 @@ public class LevelController } } + /** + * Adds a level to the list by creating a directory and required files + * @param text: the name of the directory and default title + */ public void addLevel(String text) { File levelDir = new File(thisDir,text); @@ -45,4 +58,23 @@ public class LevelController temp.writeMetadata(); readData(); } + + /** + * Removes level from the filesystem then reloads this levelController + * @param level: the level to be removed + */ + public void removeLevel(Level level) + { + File hold = level.thisDir; + levelList.remove(level); + + try { + Files.walk(hold.toPath()) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } catch (IOException e) { + e.printStackTrace(); + } + } } \ No newline at end of file diff --git a/src/main/SettingsController.java b/src/main/SettingsController.java index f3bd671..4bd2b24 100644 --- a/src/main/SettingsController.java +++ b/src/main/SettingsController.java @@ -15,26 +15,9 @@ public class SettingsController { public SimpleIntegerProperty effectsVol = new SimpleIntegerProperty(0); public SimpleIntegerProperty musicVol = new SimpleIntegerProperty(0); - private boolean fullscreen; private JSONObject settings; - public void saveAndWrite(int newEffVol, int newMusVol) - { - settings.put("musicVol", newMusVol); - settings.put("effectsVol", newEffVol); - try (FileWriter file = new FileWriter("settings.json")) - { - //write the settings JSONObject instance to the file - file.write(settings.toJSONString()); - file.flush(); - - } - catch (IOException e) { - e.printStackTrace(); - } - } - - public void readFile() throws ParseException + public void read() throws ParseException { JSONParser jsonParser = new JSONParser(); //parser to read the file @@ -57,5 +40,20 @@ public class SettingsController } } - + + public void write(int newEffVol, int newMusVol) + { + settings.put("musicVol", newMusVol); + settings.put("effectsVol", newEffVol); + try (FileWriter file = new FileWriter("settings.json")) + { + //write the settings JSONObject instance to the file + file.write(settings.toJSONString()); + file.flush(); + + } + catch (IOException e) { + e.printStackTrace(); + } + } } -- cgit v1.2.3 From 0b7f45fcb05814870733613dcff233451948c967 Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 2 Jun 2023 01:31:49 -0400 Subject: start note editor, new test level --- src/main/Difficulty.java | 4 +++- src/main/Level.java | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/Difficulty.java b/src/main/Difficulty.java index 18dabb3..c7a289a 100644 --- a/src/main/Difficulty.java +++ b/src/main/Difficulty.java @@ -19,14 +19,16 @@ public class Difficulty public File notes; public int bpm; public int numBeats; + public Level level; /** * Creates a new Difficulty and gives it a file path * @param newDir: The file path of the Difficulty */ - public Difficulty(File newDir) + public Difficulty(File newDir, Level level) { thisDir = newDir; + this.level = level; } /** diff --git a/src/main/Level.java b/src/main/Level.java index 591bd9a..cb16489 100644 --- a/src/main/Level.java +++ b/src/main/Level.java @@ -46,7 +46,7 @@ public class Level { if (cur.isDirectory()) //all subfolders within a level folder are difficulties { - Difficulty diff = new Difficulty(cur); + Difficulty diff = new Difficulty(cur,this); diff.readData(); diffList.add(diff); } @@ -151,7 +151,7 @@ public class Level } catch (IOException e) { e.printStackTrace(); } - Difficulty temp = new Difficulty(diffDir); + Difficulty temp = new Difficulty(diffDir,this); temp.title = text; temp.writeMetadata(); temp.writeLeaderboard(); -- cgit v1.2.3 From 571bab88c599571ee5bd9c6f5f8af2f3016fb19d Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 2 Jun 2023 01:36:34 -0400 Subject: bpm is now a double --- src/main/Difficulty.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/Difficulty.java b/src/main/Difficulty.java index c7a289a..0691675 100644 --- a/src/main/Difficulty.java +++ b/src/main/Difficulty.java @@ -17,7 +17,7 @@ public class Difficulty public String title = "Unnamed"; private ObservableList leaderboard = FXCollections.observableArrayList(); public File notes; - public int bpm; + public Double bpm; public int numBeats; public Level level; @@ -67,7 +67,7 @@ public class Difficulty JSONObject diffStuff = (JSONObject)(obj); //converts read object to a JSONObject title = (String) diffStuff.get("title"); - bpm = Integer.parseInt(diffStuff.get("bpm")+""); + bpm = Double.parseDouble(diffStuff.get("bpm")+""); numBeats = Integer.parseInt(diffStuff.get("numBeats")+""); } catch (Exception e) -- cgit v1.2.3 From a0739dc019417f17e77f6c959ebc0989c873514c Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 2 Jun 2023 02:31:20 -0400 Subject: kinda working note writer --- src/main/Difficulty.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/Difficulty.java b/src/main/Difficulty.java index 0691675..abb12f4 100644 --- a/src/main/Difficulty.java +++ b/src/main/Difficulty.java @@ -17,7 +17,7 @@ public class Difficulty public String title = "Unnamed"; private ObservableList leaderboard = FXCollections.observableArrayList(); public File notes; - public Double bpm; + public Double bpm = 0.0; public int numBeats; public Level level; -- cgit v1.2.3