aboutsummaryrefslogtreecommitdiff
path: root/src/main/Difficulty.java
diff options
context:
space:
mode:
authorZach Jordan <zxjordan5@gmail.com>2023-05-30 09:39:41 -0400
committerZach Jordan <zxjordan5@gmail.com>2023-05-30 09:39:41 -0400
commit042685d2230a164a0da9e68e2cc881ec8b087a27 (patch)
tree1e3e0d6985f314de11bed813fae0ce8b1abcfe3c /src/main/Difficulty.java
parentd283ab67988fe1c7f63b27c70077d3b599171d07 (diff)
downloadNPEhero-042685d2230a164a0da9e68e2cc881ec8b087a27.tar.gz
NPEhero-042685d2230a164a0da9e68e2cc881ec8b087a27.tar.bz2
NPEhero-042685d2230a164a0da9e68e2cc881ec8b087a27.zip
working on difficulty stuff. difficulty should be ready, but leaderboard is a wip.
Diffstat (limited to 'src/main/Difficulty.java')
-rw-r--r--src/main/Difficulty.java80
1 files changed, 76 insertions, 4 deletions
diff --git a/src/main/Difficulty.java b/src/main/Difficulty.java
index 24480e4..30b81d4 100644
--- a/src/main/Difficulty.java
+++ b/src/main/Difficulty.java
@@ -1,27 +1,99 @@
package main;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.text.ParseException;
import java.time.LocalDate;
+
+import javax.lang.model.util.ElementScanner14;
+
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class Difficulty
{
public String title;
- private ObservableList<LeaderboardEntry> leaderboard = FXCollections.observableArrayList();
+ private ObservableList<LeaderboardEntry> leaderboard;
public File notes;
public int bpm;
public File song;
public int numBeats;
+ public JSONObject diffStuff;
+ public JSONObject leaderboardStuff;
public void parseMetadata(File file) {
- //hi zach put json reader stuff here
- title = "placeholderDiff";
+ JSONParser jsonParser = new JSONParser(); //parser to read the file
+
+ try(FileReader reader = new FileReader(file))
+ {
+ Object obj = jsonParser.parse(reader);
+
+ diffStuff = (JSONObject)(obj); //converts read object to a JSONObject
+
+ title = (String) diffStuff.get("title");
+ bpm = (int) diffStuff.get("bpm");
+ numBeats = (int) diffStuff.get("numBeats");
+ }
+ catch (FileNotFoundException e)
+ {
+ e.printStackTrace();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ } catch (org.json.simple.parser.ParseException e)
+ {
+ e.printStackTrace();
+ }
+
}
public void parseLeaderboard(File file) {
//and here
- leaderboard.add(new LeaderboardEntry("placeholderScore", 0, "0/0/0"));
+ //leaderboard.add(new LeaderboardEntry("placeholderScore", 0, "0/0/0"));
+
+ String tracker = "leaderBoardEntry1"; //you gotta follow this format in ascending order in order for the file to be read properly
+ //basically this tracker is going to be used as the changing key name to be read in from the file. the substring later on is to be used to increase its value.
+ boolean jsonHasNext = true;
+ JSONParser jsonParser = new JSONParser(); //parser to read the file
+
+ try(FileReader reader = new FileReader(file))
+ {
+ Object obj = jsonParser.parse(reader);
+
+ leaderboardStuff = (JSONObject)(obj); //converts read object to a JSONObject
+ while(jsonHasNext)
+ {
+ if(leaderboardStuff.containsKey(tracker))
+ {
+ int num = (tracker.charAt(tracker.length()-1)) + 1; //get the number at the end of tracker and increase it by one
+ tracker = tracker.substring(0, tracker.length()-1) + num; //substring tracker to take off the end number and add the new end number.
+
+ //read in the actual leaderboard stuff now
+ }
+ else
+ {
+ jsonHasNext = false;
+ }
+ }
+ }
+ catch (FileNotFoundException e)
+ {
+ e.printStackTrace();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ } catch (org.json.simple.parser.ParseException e)
+ {
+ e.printStackTrace();
+ }
+
}
public void addToLeaderboard(String name, int score) {