From bfc04de7027e476b22f1201d25b7d9a1f505201c Mon Sep 17 00:00:00 2001 From: Zach Jordan Date: Wed, 17 May 2023 08:55:18 -0400 Subject: finished the reading file method, will work on rewriting the file tomoro --- src/assets/settings.json | 5 +++++ src/gui/SettingsController.java | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/assets/settings.json (limited to 'src') diff --git a/src/assets/settings.json b/src/assets/settings.json new file mode 100644 index 0000000..37f05f1 --- /dev/null +++ b/src/assets/settings.json @@ -0,0 +1,5 @@ +{ + "musicVol": 100, + "effectsVol": 100, + "fullscreen": true +} \ No newline at end of file diff --git a/src/gui/SettingsController.java b/src/gui/SettingsController.java index 23b4f38..39072ac 100644 --- a/src/gui/SettingsController.java +++ b/src/gui/SettingsController.java @@ -1,20 +1,23 @@ package gui; -import org.json.simple.JSONObject; -import org.json.simple.JSONArray; + import java.util.Map; import java.util.HashMap; 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.JSONArray; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; public class SettingsController { private int effectsVol; private int musicVol; private boolean fullscreen; - - public SettingsController() - { - readFile(); - } + private JSONObject settings; public void saveAndWrite(int newEffVol, int newMusVol, boolean isFull) { @@ -25,9 +28,28 @@ public class SettingsController } - public void readFile() + public void readFile() throws ParseException { + JSONParser jsonParser = new JSONParser(); //parser to read the file + try(FileReader reader = new FileReader("settings.json")) + { + Object obj = jsonParser.parse(reader); + + settings = (JSONObject)(obj); //converts read object to a JSONObjec + effectsVol = settings.get("effectsVol"); + } + catch (FileNotFoundException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } -- cgit v1.2.3