diff options
| author | Zach Jordan <zjordan58@fairport.org> | 2023-05-17 08:55:18 -0400 | 
|---|---|---|
| committer | Zach Jordan <zjordan58@fairport.org> | 2023-05-17 08:55:18 -0400 | 
| commit | bfc04de7027e476b22f1201d25b7d9a1f505201c (patch) | |
| tree | b942a8cee5d6c00476a3a7f639e4c8280caf1c2a | |
| parent | 3f9c9d2aee2475b14df00f61f245a12e34e8cc10 (diff) | |
| download | NPEhero-bfc04de7027e476b22f1201d25b7d9a1f505201c.tar.gz NPEhero-bfc04de7027e476b22f1201d25b7d9a1f505201c.tar.bz2 NPEhero-bfc04de7027e476b22f1201d25b7d9a1f505201c.zip | |
finished the reading file method, will work on rewriting the file tomoro
| -rw-r--r-- | src/assets/settings.json | 5 | ||||
| -rw-r--r-- | src/gui/SettingsController.java | 38 | 
2 files changed, 35 insertions, 8 deletions
| 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();
 +		}
 +				
  	}
  }
 | 
