aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/devmenu/LevelEditor.java26
-rw-r--r--src/devmenu/LevelList.java11
-rw-r--r--src/gui/LevelDetails.java2
-rw-r--r--src/gui/LevelSelector.java2
-rw-r--r--src/main/Difficulty.java65
-rw-r--r--src/main/Level.java109
-rw-r--r--src/main/LevelController.java17
7 files changed, 177 insertions, 55 deletions
diff --git a/src/devmenu/LevelEditor.java b/src/devmenu/LevelEditor.java
index a00ce57..9e65a0c 100644
--- a/src/devmenu/LevelEditor.java
+++ b/src/devmenu/LevelEditor.java
@@ -6,8 +6,12 @@ import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker;
+import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
+import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
+import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
@@ -71,10 +75,19 @@ public class LevelEditor
Text diffLabel = new Text("Difficulties");
- ObservableList<Difficulty> diffList2 = FXCollections.observableArrayList();
- diffList2.addAll(level.getDiffList());
- ListView<Difficulty> diffList = new ListView<Difficulty>();
- diffList.setItems(diffList2);
+ TableView<Difficulty> diffList = new TableView<Difficulty>();
+
+ TableColumn<Difficulty,String> diffCol = new TableColumn<Difficulty,String>("Difficulty");
+ TableColumn<Difficulty,Boolean> validCol = new TableColumn<Difficulty,Boolean>("Valid?");
+
+ diffList.getColumns().add(diffCol);
+ diffList.getColumns().add(validCol);
+
+ diffCol.setCellValueFactory(new PropertyValueFactory<Difficulty,String>("title"));
+ validCol.setCellValueFactory(new PropertyValueFactory<Difficulty,Boolean>("valid"));
+
+ diffList.setItems(level.getDiffList());
+
Button edit = new Button("Edit");
edit.setOnAction(e -> new DiffEditor(diffList.getSelectionModel().getSelectedItem()));
@@ -84,9 +97,8 @@ public class LevelEditor
Button refresh = new Button("Refresh");
refresh.setOnAction(e -> {
- diffList2.clear();
- diffList2.addAll(level.getDiffList());
- diffList.setItems(diffList2);
+ level.readData();
+ diffList.setItems(level.getDiffList());
});
HBox buttons = new HBox();
diff --git a/src/devmenu/LevelList.java b/src/devmenu/LevelList.java
index 7eaca84..7087472 100644
--- a/src/devmenu/LevelList.java
+++ b/src/devmenu/LevelList.java
@@ -29,14 +29,18 @@ public class LevelList
TableColumn<Level,String> titleCol = new TableColumn<Level,String>("Title");
TableColumn<Level,String> artistCol = new TableColumn<Level,String>("Artist");
+ TableColumn<Level,Boolean> validCol = new TableColumn<>("Valid?");
levels.getColumns().add(titleCol);
levels.getColumns().add(artistCol);
+ levels.getColumns().add(validCol);
titleCol.setCellValueFactory(new PropertyValueFactory<Level, String>("title"));
artistCol.setCellValueFactory(new PropertyValueFactory<Level, String>("artist"));
+ validCol.setCellValueFactory(new PropertyValueFactory<Level, Boolean>("valid"));
+
+ levels.setItems(LevelController.getLevelList());
- levels.setItems(LevelController.levelList);
Button edit = new Button("Edit");
edit.setOnAction(e -> new LevelEditor(levels.getSelectionModel().getSelectedItem()));
@@ -45,7 +49,10 @@ public class LevelList
remove.setOnAction(e -> gui.Driver.levelController.removeLevel(levels.getSelectionModel().getSelectedItem()));
Button refresh = new Button("Refresh");
- refresh.setOnAction(e -> levels.setItems(LevelController.levelList));
+ refresh.setOnAction(e -> {
+ Driver.levelController.readData();
+ levels.setItems(LevelController.getLevelList());
+ });
HBox buttons = new HBox();
buttons.getChildren().addAll(edit,remove,refresh);
diff --git a/src/gui/LevelDetails.java b/src/gui/LevelDetails.java
index 4a417ec..f9239e7 100644
--- a/src/gui/LevelDetails.java
+++ b/src/gui/LevelDetails.java
@@ -84,7 +84,7 @@ public class LevelDetails extends VBox
FlowPane diffSelector = new FlowPane();
diffSelector.setAlignment(Pos.CENTER);
ToggleGroup diffToggleGroup = new ToggleGroup(); //allows only one to be selected at a time
- for (Difficulty diff : level.getDiffList()) //adds a button for each diff
+ for (Difficulty diff : level.getValidDiffList()) //adds a button for each diff
{
RadioButton temp = new RadioButton();
temp.getStyleClass().remove("radio-button"); //makes the buttons not look like a radio button and instead a normal button
diff --git a/src/gui/LevelSelector.java b/src/gui/LevelSelector.java
index 1d71a3f..2a95b6c 100644
--- a/src/gui/LevelSelector.java
+++ b/src/gui/LevelSelector.java
@@ -34,7 +34,7 @@ public class LevelSelector extends Pane
titleCol.setCellValueFactory(new PropertyValueFactory<Level, String>("title"));
artistCol.setCellValueFactory(new PropertyValueFactory<Level, String>("artist"));
- levels.setItems(LevelController.levelList);
+ levels.setItems(LevelController.getValidLevelList());
levels.prefWidthProperty().bind(super.prefWidthProperty().multiply(0.25));
levels.prefHeightProperty().bind(super.prefHeightProperty().multiply(0.75));
diff --git a/src/main/Difficulty.java b/src/main/Difficulty.java
index abb12f4..7174c33 100644
--- a/src/main/Difficulty.java
+++ b/src/main/Difficulty.java
@@ -11,7 +11,7 @@ import org.json.simple.parser.JSONParser;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
-public class Difficulty
+public class Difficulty
{
public File thisDir;
public String title = "Unnamed";
@@ -20,6 +20,7 @@ public class Difficulty
public Double bpm = 0.0;
public int numBeats;
public Level level;
+ public boolean isValid = false;
/**
* Creates a new Difficulty and gives it a file path
@@ -31,33 +32,54 @@ public class Difficulty
this.level = level;
}
- /**
- * 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
+ boolean isValid1 = true;
+ if (new File(thisDir, "metadata.json").exists())
{
- if (cur.getName().equals("metadata.json"))
- {
- parseMetadata();
- }
- if (cur.getName().equals("leaderboard.json"))
+ if (!parseMetadata())
{
- parseLeaderboard();
+ isValid1 = false;
}
- if (cur.getName().equals("notes.txt"))
+ }
+ else
+ {
+ System.err.println(thisDir+" is missing metadata.json");
+ isValid1 = false;
+ }
+
+ if (new File(thisDir, "leaderboard.json").exists())
+ {
+ if (!parseLeaderboard())
{
- notes = cur;
+ isValid1 = false;
}
}
+ else
+ {
+ System.err.println(thisDir+" is missing leaderboard.json");
+ isValid1 = false;
+ }
+
+ if (new File(thisDir, "notes.txt").exists())
+ {
+ notes = new File(thisDir, "notes.txt");
+ }
+ else
+ {
+ System.err.println(thisDir+" is missing notes.txt");
+ isValid1 = false;
+ }
+
+ isValid = isValid1;
}
/**
* Reads in json metadata and assigns values to variables
*/
- public void parseMetadata()
+ public boolean parseMetadata()
{
+ boolean isValid = true;
File file = new File(thisDir, "metadata.json");
JSONParser jsonParser = new JSONParser(); //parser to read the file
@@ -73,7 +95,9 @@ public class Difficulty
catch (Exception e)
{
e.printStackTrace();
+ isValid = false;
}
+ return isValid;
}
/**
@@ -102,8 +126,9 @@ public class Difficulty
/**
* Reads in json leaderboard and assigns populates list with leaderboardEntries
*/
- public void parseLeaderboard()
+ public boolean parseLeaderboard()
{
+ boolean isValid = true;
File file = new File(thisDir, "leaderboard.json");
JSONParser jsonParser = new JSONParser(); //parser to read the file
@@ -125,8 +150,10 @@ public class Difficulty
}
catch (Exception e)
{
+ isValid = false;
e.printStackTrace();
}
+ return isValid;
}
/**
@@ -178,4 +205,12 @@ public class Difficulty
{
return title;
}
+
+ public boolean isValid() {
+ return isValid;
+ }
+
+ public String getTitle() {
+ return title;
+ }
}
diff --git a/src/main/Level.java b/src/main/Level.java
index cb16489..a173191 100644
--- a/src/main/Level.java
+++ b/src/main/Level.java
@@ -1,8 +1,10 @@
package main;
import java.io.File;
-import java.util.ArrayList;
import java.util.Comparator;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import java.io.FileWriter;
@@ -19,7 +21,9 @@ public class Level
public File thisDir;
private String title = "Unnamed";
private String artist = "Unknown";
- private ArrayList<Difficulty> diffList;
+ private ObservableList<Difficulty> diffList;
+ private ObservableList<Difficulty> validDiffList;
+ private boolean isValid;
public Image preview; //optional
public String desc = "No description";
@@ -36,44 +40,85 @@ public class Level
thisDir = newDir;
}
- /**
- * Checks for files in the level folder and runs cooresponding actions
- */
public void readData()
{
- diffList = new ArrayList<Difficulty>();
+ boolean isValid1 = true;
+ if (new File(thisDir, "metadata.json").exists())
+ {
+ if (!parseMetadata())
+ {
+ System.err.println(new File(thisDir, "metadata.json")+" contains error(s)");
+ isValid1 = false;
+ }
+ }
+ else
+ {
+ System.err.println(thisDir+" is missing metadata.json");
+ isValid1 = false;
+ }
+
+ if (new File(thisDir, "song.wav").exists())
+ {
+ song = new File(thisDir,"song.wav");
+ }
+ else
+ {
+ System.err.println(thisDir+" is missing song.wav");
+ isValid1 = false;
+ }
+
+ if (new File(thisDir, "background.png").exists())
+ {
+ background = new Image(new File(thisDir,"background.png").toURI().toString());
+ }
+ else
+ {
+ System.out.println(thisDir+" is missing background.png, though it is not required");
+ }
+
+ if (! new File(thisDir, "preview.png").exists())
+ {
+ preview = new Image(new File(thisDir,"preview.png").toURI().toString());
+ }
+ else
+ {
+ System.out.println(thisDir+" is missing preview.png, though it is not required");
+ }
+
+ diffList = FXCollections.observableArrayList();
+ validDiffList = FXCollections.observableArrayList();
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,this);
diff.readData();
- diffList.add(diff);
- }
- 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;
+ if (diff.isValid)
+ {
+ diffList.add(diff);
+ validDiffList.add(diff);
+ }
+ else
+ {
+ diffList.add(diff);
+ }
}
}
+ if (validDiffList.size() == 0)
+ {
+ System.err.println(thisDir+" contains no valid difficulties");
+ isValid1 = false;
+ }
+
+ isValid = isValid1;
}
/**
* Reads in json metadata and assigns values to variables
*/
- public void parseMetadata()
+ public boolean parseMetadata()
{
+ boolean isValid = true;
JSONParser jsonParser = new JSONParser(); //parser to read the file
try(FileReader reader = new FileReader(new File(thisDir, "metadata.json")))
@@ -104,7 +149,9 @@ public class Level
catch (Exception e)
{
e.printStackTrace();
+ isValid = false;
}
+ return isValid;
}
/**
@@ -165,8 +212,6 @@ public class Level
public void removeDiff(Difficulty diff)
{
File hold = diff.thisDir;
- diffList.remove(diff);
-
try {
Files.walk(hold.toPath())
.sorted(Comparator.reverseOrder())
@@ -175,6 +220,7 @@ public class Level
} catch (IOException e) {
e.printStackTrace();
}
+ readData();
}
/**
@@ -192,11 +238,14 @@ public class Level
readData();
}
- public ArrayList<Difficulty> getDiffList()
- {
+ public ObservableList<Difficulty> getDiffList() {
return diffList;
}
+ public ObservableList<Difficulty> getValidDiffList() {
+ return validDiffList;
+ }
+
public String getTitle()
{
return title;
@@ -214,4 +263,8 @@ public class Level
public void setArtist(String artist) {
this.artist = artist;
}
+
+ public boolean isValid() {
+ return isValid;
+ }
}
diff --git a/src/main/LevelController.java b/src/main/LevelController.java
index 78d638a..07ea3f8 100644
--- a/src/main/LevelController.java
+++ b/src/main/LevelController.java
@@ -12,7 +12,8 @@ import javafx.collections.ObservableList;
public class LevelController
{
File thisDir = new File("levels");
- public static ObservableList<Level> levelList;
+ private static ObservableList<Level> levelList;
+ private static ObservableList<Level> validLevelList;
/**
* Creates a levelController, which holds all the levels
@@ -28,11 +29,16 @@ public class LevelController
public void readData()
{
levelList = FXCollections.observableArrayList();
+ validLevelList = FXCollections.observableArrayList();
for (File cur: thisDir.listFiles()) //iterates through all files/folders in levels
{
Level level = new Level(cur);
level.readData();
levelList.add(level);
+ if (level.isValid())
+ {
+ validLevelList.add(level);
+ }
}
}
@@ -76,5 +82,14 @@ public class LevelController
} catch (IOException e) {
e.printStackTrace();
}
+ readData();
+ }
+
+ public static ObservableList<Level> getLevelList() {
+ return levelList;
+ }
+
+ public static ObservableList<Level> getValidLevelList() {
+ return validLevelList;
}
} \ No newline at end of file