From 9e0efb69279e86e7462fa3a4bdb8b9198cc29a9f Mon Sep 17 00:00:00 2001 From: Zach Jordan Date: Thu, 25 May 2023 09:56:14 -0400 Subject: metadata for test level and a json reader --- src/main/Level.java | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'src/main/Level.java') diff --git a/src/main/Level.java b/src/main/Level.java index d492c88..2b367d3 100644 --- a/src/main/Level.java +++ b/src/main/Level.java @@ -7,6 +7,15 @@ import javafx.beans.property.SimpleStringProperty; import javafx.scene.image.Image; import javafx.scene.paint.Color; +import java.io.FileWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + public class Level { public Image preview; //optional @@ -18,16 +27,42 @@ public class Level public Image background; //optional public Color[] colors; //optional, have default colors + private JSONObject levelStuff; + public void setColors(Color... newColors) { colors = newColors; } //all below is required for table view - public Level(String title, String artist) + public Level() throws ParseException { - this.title = new SimpleStringProperty(title); - this.artist = new SimpleStringProperty(artist); + JSONParser jsonParser = new JSONParser(); //parser to read the file + + try(FileReader reader = new FileReader(".json")) + { + Object obj = jsonParser.parse(reader); + + levelStuff = (JSONObject)(obj); //converts read object to a JSONObject + + title = (SimpleStringProperty)(levelStuff.get("title")); + artist = (SimpleStringProperty)(levelStuff.get("title")); + desc = (String)(levelStuff.get("title")); + + + + + + + } + catch (FileNotFoundException e) + { + e.printStackTrace(); + } + catch (IOException e) + { + e.printStackTrace(); + } } public String getTitle() { -- cgit v1.2.3 From 27a49de2ad86556d9b3251f7fc22a552b83308f2 Mon Sep 17 00:00:00 2001 From: Zach Jordan Date: Thu, 25 May 2023 10:23:53 -0400 Subject: changes to level class --- src/main/Level.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/main/Level.java') diff --git a/src/main/Level.java b/src/main/Level.java index 2b367d3..f02bb46 100644 --- a/src/main/Level.java +++ b/src/main/Level.java @@ -25,7 +25,7 @@ public class Level public ArrayList diffList = new ArrayList(); public Image background; //optional - public Color[] colors; //optional, have default colors + public Color[] colors = new Color[5];//optional, have default colors private JSONObject levelStuff; @@ -49,11 +49,10 @@ public class Level artist = (SimpleStringProperty)(levelStuff.get("title")); desc = (String)(levelStuff.get("title")); - - - - - + if(levelStuff.has("color1")) + { + + } } catch (FileNotFoundException e) { -- cgit v1.2.3 From 1d0890cf11f88e274beddf9fbc132fb80c2f054c Mon Sep 17 00:00:00 2001 From: Zach Jordan Date: Thu, 25 May 2023 10:24:44 -0400 Subject: changes to level class --- src/main/Level.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/Level.java') diff --git a/src/main/Level.java b/src/main/Level.java index f02bb46..ee60d47 100644 --- a/src/main/Level.java +++ b/src/main/Level.java @@ -49,7 +49,7 @@ public class Level artist = (SimpleStringProperty)(levelStuff.get("title")); desc = (String)(levelStuff.get("title")); - if(levelStuff.has("color1")) + if(( levelStuff).containsKey("color1")) { } -- cgit v1.2.3