diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2023-05-25 20:00:13 -0400 | 
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2023-05-25 20:00:13 -0400 | 
| commit | 742b5ca228b5c52e21a48586a17cab8a89c939e3 (patch) | |
| tree | 6c340781098da6611fbe043c9bc4305a64fa8143 /src | |
| parent | cb9076941d76b4395d19d30076481bfeea35cacb (diff) | |
| download | NPEhero-742b5ca228b5c52e21a48586a17cab8a89c939e3.tar.gz NPEhero-742b5ca228b5c52e21a48586a17cab8a89c939e3.tar.bz2 NPEhero-742b5ca228b5c52e21a48586a17cab8a89c939e3.zip | |
add file reading system in levelcontroller
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/Difficulty.java | 11 | ||||
| -rw-r--r-- | src/main/Level.java | 36 | ||||
| -rw-r--r-- | src/main/LevelController.java | 93 | 
3 files changed, 66 insertions, 74 deletions
| diff --git a/src/main/Difficulty.java b/src/main/Difficulty.java index 2d2b5c3..926d8d6 100644 --- a/src/main/Difficulty.java +++ b/src/main/Difficulty.java @@ -1,7 +1,6 @@  package main;  import java.io.File; -import java.util.ArrayList;  import javafx.collections.FXCollections;  import javafx.collections.ObservableList; @@ -12,8 +11,12 @@ public class Difficulty      public ObservableList<LeaderboardEntry> leaderboard = FXCollections.observableArrayList();      public File notes; -    public String toString() -    { -        return title; +    public void parseMetadata(File file) { +        title = "placeholderDiff"; +    } + +    public void parseLeaderboard(File file) { +        //and here +        leaderboard.add(new LeaderboardEntry("placeholderScore", 0, "0/0/0"));      }  } diff --git a/src/main/Level.java b/src/main/Level.java index eb8d60e..a9b5c48 100644 --- a/src/main/Level.java +++ b/src/main/Level.java @@ -35,12 +35,21 @@ public class Level          colors = newColors;      } -    //all below is required for table view -    public Level() +    public String getTitle()  +    { +        return title; +    } + +    public String getArtist()  +    { +        return artist; +    } + +    public void parseMetadata(File file)       {          JSONParser jsonParser = new JSONParser(); //parser to read the file -		try(FileReader reader = new FileReader("src/assets/levels/test level/metadata.json")) +		try(FileReader reader = new FileReader(file))  		{  			Object obj = jsonParser.parse(reader);  @@ -62,25 +71,10 @@ public class Level  		catch (IOException e)   		{  			e.printStackTrace(); -		} catch (ParseException e) { -            // TODO Auto-generated catch block +		}  +        catch (ParseException e)  +        {              e.printStackTrace();          }      } - -    public String getTitle() { -        return title; -    } - -    public String getArtist() { -        return artist; -    } - -    // public void setTitle(String title) { -    //     this.title.set(title); -    // } - -    // public void setArtist(String artist) { -    //     this.artist.set(artist); -    // }  } diff --git a/src/main/LevelController.java b/src/main/LevelController.java index 4ba34e1..c364962 100644 --- a/src/main/LevelController.java +++ b/src/main/LevelController.java @@ -1,11 +1,9 @@  package main; -import org.json.simple.parser.ParseException; - +import java.io.File;  import javafx.collections.FXCollections;  import javafx.collections.ObservableList;  import javafx.scene.image.Image; -import javafx.scene.paint.Color;  public class LevelController  { @@ -13,51 +11,48 @@ public class LevelController      public LevelController()      { - -        Difficulty d1 = new Difficulty(); -        d1.title = "Easy"; -        LeaderboardEntry lb = new LeaderboardEntry("t-bone", 1000, "DATE"); -        //lb.setName("t-bone"); -        //lb.setScore(1000); -        d1.leaderboard.add(lb); - -        Difficulty d2 = new Difficulty(); -        d2.title = "Medium"; -        Difficulty d3 = new Difficulty(); -        d3.title = "Hard"; -        Difficulty d4 = new Difficulty(); -        d4.title = "Expert"; -        Difficulty d5 = new Difficulty(); -        d5.title = "Impossible"; - -        Level testLevel = new Level(); -        //testLevel.setTitle("test level class"); -        testLevel.desc = "this level is being used to test the LevelController class"; -        //testLevel.setArtist("testArtist"); -        testLevel.setColors(Color.RED, Color.BLUE, Color.GREEN, Color.ORANGE, Color.PURPLE); -        testLevel.diffList.add(d1); -        testLevel.diffList.add(d2); -        levelList.add(testLevel); - -        Level testLevel2 = new Level(); -        //testLevel2.setTitle("another one"); -        testLevel2.desc = "it can say something else too"; -        //testLevel2.setAritst("testArtist2"); -        testLevel2.setColors(Color.RED, Color.BLUE, Color.GREEN, Color.ORANGE, Color.PURPLE); -        testLevel2.diffList.add(d2); -        testLevel2.diffList.add(d3); -        testLevel2.diffList.add(d4); -        testLevel2.preview = new Image("assets/pico.png"); -        levelList.add(testLevel2); -          -         +        for (File curFileInLevels: new File("src/assets/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")) +                        { +                            diff.parseMetadata(curFileInCurDiff); +                        } +                        if (curFileInCurDiff.getName().equals("leaderboard.json")) +                        { +                            diff.parseLeaderboard(curFileInCurDiff); +                        } +                        if (curFileInCurDiff.getName().equals("notes.txt")) +                        { +                            diff.notes = 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); +        }      } - -    public void readInLevels() -    { -        //oh boy time for a flowchart -    }  - - -  }
\ No newline at end of file | 
