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/Level.java | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'src/main/Level.java') 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; -- 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/Level.java | 95 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 19 deletions(-) (limited to 'src/main/Level.java') 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; -- 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/Level.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/Level.java') 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