aboutsummaryrefslogtreecommitdiff
path: root/src/main/LevelController.java
blob: 3abf810033ee3777b97ae809192f408161846a03 (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
package main;

import java.io.File;
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();

    public LevelController()
    {
        for (File curFileInLevels: new File("levels").listFiles()) //iterates through all files/folders in src/assets/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);
                }

                if (curFileInCurLevel.getName().equals("preview.png"))
                {
                    level.preview = new Image(curFileInCurLevel.toURI().toString());
                }

                if (curFileInCurLevel.getName().equals("metadata.json"))
                {
                    level.parseMetadata(curFileInCurLevel);
                }

                if (curFileInCurLevel.getName().equals("background.png"))
                {
                    level.background = new Image(curFileInCurLevel.toURI().toString());
                }
            }
            levelList.add(level);
        }
    }
}