aboutsummaryrefslogtreecommitdiff
path: root/src/main/Difficulty.java
diff options
context:
space:
mode:
authorzxjordan <zxjordan5@gmail.com>2023-06-05 22:48:07 -0400
committerzxjordan <zxjordan5@gmail.com>2023-06-05 22:48:07 -0400
commit144b9e9a16272da2a7cdde01b16dfb83f5353b07 (patch)
treec9876abbe02ee74d68d75e827d9a26da7495e941 /src/main/Difficulty.java
parent85037099c9ff60d55501c0ff9a70ccfaccbb95f2 (diff)
parent5f6b84a1d3a4cf1936e7d495d03400ce5c7478f6 (diff)
downloadNPEhero-144b9e9a16272da2a7cdde01b16dfb83f5353b07.tar.gz
NPEhero-144b9e9a16272da2a7cdde01b16dfb83f5353b07.tar.bz2
NPEhero-144b9e9a16272da2a7cdde01b16dfb83f5353b07.zip
Merge branch 'main' of https://gitlab.sowgro.net/npeinc/npehero
Diffstat (limited to 'src/main/Difficulty.java')
-rw-r--r--src/main/Difficulty.java52
1 files changed, 48 insertions, 4 deletions
diff --git a/src/main/Difficulty.java b/src/main/Difficulty.java
index 7174c33..3dba47b 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 implements Comparable<Difficulty>
{
public File thisDir;
public String title = "Unnamed";
@@ -21,6 +21,7 @@ public class Difficulty
public int numBeats;
public Level level;
public boolean isValid = false;
+ public int priority = 0;
/**
* Creates a new Difficulty and gives it a file path
@@ -88,9 +89,46 @@ public class Difficulty
Object obj = jsonParser.parse(reader);
JSONObject diffStuff = (JSONObject)(obj); //converts read object to a JSONObject
- title = (String) diffStuff.get("title");
- bpm = Double.parseDouble(diffStuff.get("bpm")+"");
- numBeats = Integer.parseInt(diffStuff.get("numBeats")+"");
+ if (diffStuff.containsKey("title"))
+ {
+ title = (String) diffStuff.get("title");
+ }
+ else
+ {
+ System.err.println(file+" is missing properety title");
+ isValid = false;
+ }
+
+ if (diffStuff.containsKey("bpm"))
+ {
+ bpm = Double.parseDouble(diffStuff.get("bpm")+"");
+ }
+ else
+ {
+ System.err.println(file+" is missing properety bpm");
+ isValid = false;
+ }
+
+ if (diffStuff.containsKey("numBeats"))
+ {
+ numBeats = Integer.parseInt(diffStuff.get("numBeats")+"");
+ }
+ else
+ {
+ System.err.println(file+" is missing properety numBeats");
+ isValid = false;
+ }
+
+ if (diffStuff.containsKey("priority"))
+ {
+ priority = Integer.parseInt(diffStuff.get("priority")+"");
+
+ }
+ else
+ {
+ System.err.println(file+" is missing properety priority");
+ isValid = false;
+ }
}
catch (Exception e)
{
@@ -114,6 +152,7 @@ public class Difficulty
obj.put("title", title);
obj.put("bpm", bpm);
obj.put("numBeats", numBeats);
+ obj.put("priority", priority);
obj.writeJSONString(fileWriter);
fileWriter.flush();
}
@@ -213,4 +252,9 @@ public class Difficulty
public String getTitle() {
return title;
}
+
+ @Override
+ public int compareTo(Difficulty d) {
+ return priority - d.priority;
+ }
}