aboutsummaryrefslogtreecommitdiff
path: root/src/main/Difficulty.java
blob: 30b81d4a4856587e7f48a2bd841927923475516d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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;
    public File notes;
    public int bpm;
    public File song;
    public int numBeats;
    public JSONObject diffStuff;
    public JSONObject leaderboardStuff;

    public void parseMetadata(File file) {
        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"));

        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) {
        leaderboard.add(new LeaderboardEntry(name, score, ""+LocalDate.now())); //do not delete this tho its not a placeholder
        //and make this write to the json also
    }

    public ObservableList<LeaderboardEntry> getLeaderboard() {
        return leaderboard;
    }
}