aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2023-06-01 00:53:04 -0400
committersowgro <tpoke.ferrari@gmail.com>2023-06-01 00:53:04 -0400
commit6c216a309838bf1cbeb19070ce180c0170ccd3c9 (patch)
tree461f877b9417621cb0a19b1bbc735c8455a570ba /src/main
parent99584f39f8e8f3b69255135665040c2a947d4021 (diff)
downloadNPEhero-6c216a309838bf1cbeb19070ce180c0170ccd3c9.tar.gz
NPEhero-6c216a309838bf1cbeb19070ce180c0170ccd3c9.tar.bz2
NPEhero-6c216a309838bf1cbeb19070ce180c0170ccd3c9.zip
early code for level editor gui
Diffstat (limited to 'src/main')
-rw-r--r--src/main/Difficulty.java43
-rw-r--r--src/main/Level.java145
-rw-r--r--src/main/LevelController.java90
3 files changed, 183 insertions, 95 deletions
diff --git a/src/main/Difficulty.java b/src/main/Difficulty.java
index 8420886..2c74956 100644
--- a/src/main/Difficulty.java
+++ b/src/main/Difficulty.java
@@ -16,6 +16,7 @@ import javafx.collections.ObservableList;
public class Difficulty
{
+ public File thisDir;
public String title;
private ObservableList<LeaderboardEntry> leaderboard = FXCollections.observableArrayList();
public File notes;
@@ -24,8 +25,37 @@ public class Difficulty
public int numBeats;
private File leaderboardFile;
+ public Difficulty(File file)
+ {
+ thisDir = file;
+ readData();
+ }
+
+ public void readData()
+ {
+ for(File cur: thisDir.listFiles()) //iterates through all files/folders in src/assets/levels/LEVEL/DIFFICULTY
+ {
+ if (cur.getName().equals("metadata.json"))
+ {
+ parseMetadata(cur);
+ }
+ if (cur.getName().equals("leaderboard.json"))
+ {
+ parseLeaderboard(cur);
+ }
+ if (cur.getName().equals("notes.txt"))
+ {
+ notes = cur;
+ }
+ if (cur.getName().equals("song.wav"))
+ {
+ song = cur;
+ }
+ }
+ }
+
- public void parseMetadata(File file) throws FileNotFoundException, IOException
+ public void parseMetadata(File file)
{
JSONParser jsonParser = new JSONParser(); //parser to read the file
@@ -46,7 +76,7 @@ public class Difficulty
}
}
- public void parseLeaderboard(File file) throws FileNotFoundException, IOException
+ public void parseLeaderboard(File file)
{
leaderboardFile = file;
JSONParser jsonParser = new JSONParser(); //parser to read the file
@@ -103,4 +133,13 @@ public class Difficulty
{
return leaderboard;
}
+
+ public String toString()
+ {
+ return title;
+ }
+
+ public void writeMetadata() {
+
+ }
}
diff --git a/src/main/Level.java b/src/main/Level.java
index 66fe243..95d6b5d 100644
--- a/src/main/Level.java
+++ b/src/main/Level.java
@@ -12,47 +12,62 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
+import gui.Driver;
+
public class Level
{
- public Image preview; //optional
+ public File thisDir;
private String title;
private String artist;
- public String desc;
- public ArrayList<Difficulty> diffList = new ArrayList<Difficulty>();
+ private ArrayList<Difficulty> diffList;
+ public Image preview; //optional
+ public String desc;
public Image background; //optional
public Color[] colors;//optional, have default colors
- public Color c1;
- public Color c2;
- public Color c3;
- public Color c4;
- public Color c5;
-
- private JSONObject levelStuff;
- public void setColors(Color... newColors)
+ public Level(File dir)
{
- colors = newColors;
+ thisDir = dir;
+ readData();
}
- public String getTitle()
+ public void readData()
{
- return title;
- }
+ diffList = new ArrayList<Difficulty>();
+ for(File cur: thisDir.listFiles()) //iterates through all files/folders in src/assets/levels/LEVEL
+ {
+ if (cur.isDirectory()) //all subfolders within a level folder are difficulties
+ {
+ Difficulty diff = new Difficulty(cur);
+ diffList.add(diff);
+ }
- public String getArtist()
- {
- return artist;
+ if (cur.getName().equals("preview.png"))
+ {
+ preview = new Image(cur.toURI().toString());
+ }
+
+ if (cur.getName().equals("metadata.json"))
+ {
+ parseMetadata();
+ }
+
+ if (cur.getName().equals("background.png"))
+ {
+ background = new Image(cur.toURI().toString());
+ }
+ }
}
- public void parseMetadata(File file)
+ public void parseMetadata()
{
JSONParser jsonParser = new JSONParser(); //parser to read the file
- try(FileReader reader = new FileReader(file))
+ try(FileReader reader = new FileReader(new File(thisDir, "metadata.json")))
{
Object obj = jsonParser.parse(reader);
-
+ JSONObject levelStuff = new JSONObject();
levelStuff = (JSONObject)(obj); //converts read object to a JSONObject
title = (String)(levelStuff.get("title"));
@@ -63,34 +78,88 @@ public class Level
{
colors = new Color[5];
- c1 = Color.web((String)(levelStuff.get("color1"))); //read in all the custom colors
- c2 = Color.web((String)(levelStuff.get("color2")));
- c3 = Color.web((String)(levelStuff.get("color3")));
- c4 = Color.web((String)(levelStuff.get("color4")));
- c5 = Color.web((String)(levelStuff.get("color5")));
-
- colors[0] = c1;
- colors[1] = c2;
- colors[2] = c3;
- colors[3] = c4;
- colors[4] = c5;
+ colors[0] = Color.web((String)(levelStuff.get("color1"))); //read in all the custom colors
+ colors[1] = Color.web((String)(levelStuff.get("color2")));
+ colors[2] = Color.web((String)(levelStuff.get("color3")));
+ colors[3] = Color.web((String)(levelStuff.get("color4")));
+ colors[4] = Color.web((String)(levelStuff.get("color5")));
}
else
{
colors = new Color[]{Color.RED,Color.BLUE,Color.GREEN,Color.PURPLE,Color.YELLOW};
}
}
- catch (FileNotFoundException e)
+ catch (Exception e)
{
e.printStackTrace();
}
- catch (IOException e)
- {
- e.printStackTrace();
- }
- catch (ParseException e)
+ }
+
+ public void writeMetadata()
+ {
+ FileWriter fileWriter;
+ try
{
+ fileWriter = new FileWriter(new File(thisDir, "metadata.json"));
+ JSONObject obj = new JSONObject();
+ 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.writeJSONString(fileWriter);
+ }
+ catch (IOException e) {
e.printStackTrace();
}
}
+
+ public ArrayList<Difficulty> getDiffList()
+ {
+ return diffList;
+ }
+
+ public void addDiff(String text)
+ {
+ File diffDir = new File(thisDir, text);
+ diffDir.mkdirs();
+ File metadataDir = new File(diffDir, "metadata.json");
+ try {
+ metadataDir.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ readData();
+ }
+
+ public void removeDiff(Difficulty diff)
+ {
+ //soon
+ }
+
+ public void renameDiff(Difficulty diff, String newName)
+ {
+ //soon
+ }
+
+ public String getTitle()
+ {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getArtist()
+ {
+ return artist;
+ }
+
+ public void setArtist(String artist) {
+ this.artist = artist;
+ }
}
diff --git a/src/main/LevelController.java b/src/main/LevelController.java
index 3abf810..eff512d 100644
--- a/src/main/LevelController.java
+++ b/src/main/LevelController.java
@@ -5,70 +5,50 @@ import java.io.IOException;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
-import javafx.scene.image.Image;
public class LevelController
{
- public static ObservableList<Level> levelList = FXCollections.observableArrayList();
+ File thisDir = new File("levels");
+ public static ObservableList<Level> levelList;
public LevelController()
{
- for (File curFileInLevels: new File("levels").listFiles()) //iterates through all files/folders in src/assets/levels
+ readData();
+ }
+
+ public void readData()
+ {
+ levelList = FXCollections.observableArrayList();
+ for (File cur: thisDir.listFiles()) //iterates through all files/folders in levels
{
- Level level = new Level();
- for(File curFileInCurLevel: curFileInLevels.listFiles()) //iterates through all files/folders in src/assets/levels/LEVEL
- {
- if (curFileInCurLevel.isDirectory()) //all subfolders within a level folder are difficulties
- {
- Difficulty diff = new Difficulty();
- for(File curFileInCurDiff: curFileInCurLevel.listFiles()) //iterates through all files/folders in src/assets/levels/LEVEL/DIFFICULTY
- {
- if (curFileInCurDiff.getName().equals("metadata.json"))
- {
- try {
- diff.parseMetadata(curFileInCurDiff);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (curFileInCurDiff.getName().equals("leaderboard.json"))
- {
- try {
- diff.parseLeaderboard(curFileInCurDiff);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (curFileInCurDiff.getName().equals("notes.txt"))
- {
- diff.notes = curFileInCurDiff;
- }
- if (curFileInCurDiff.getName().equals("song.wav"))
- {
- diff.song = curFileInCurDiff;
- }
- }
- level.diffList.add(diff);
- }
+ Level level = new Level(cur);
+ levelList.add(level);
+ }
+ }
- if (curFileInCurLevel.getName().equals("preview.png"))
- {
- level.preview = new Image(curFileInCurLevel.toURI().toString());
- }
+ public void addLevel(String text)
+ {
+ File levelDir = new File(thisDir,text);
+ levelDir.mkdirs();
+ File metadataDir = new File(levelDir, "metadata.json");
+ try
+ {
+ metadataDir.createNewFile();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ readData();
+ }
- if (curFileInCurLevel.getName().equals("metadata.json"))
- {
- level.parseMetadata(curFileInCurLevel);
- }
+ public void removeLevel(Level level)
+ {
+ //soon
+ }
- if (curFileInCurLevel.getName().equals("background.png"))
- {
- level.background = new Image(curFileInCurLevel.toURI().toString());
- }
- }
- levelList.add(level);
- }
+ public void renameLevel(Level level, String newName)
+ {
+ //soon
}
} \ No newline at end of file