re-fix create json when adding initial btns

This commit is contained in:
Joseph Garcia 2020-12-18 13:43:50 -06:00
parent 46bc34af38
commit f078d92af7
3 changed files with 24 additions and 11 deletions

View File

@ -65,8 +65,14 @@ public class ConfigFile {
JSONArray array = (JSONArray) obj; JSONArray array = (JSONArray) obj;
array.add(jsonObject); array.add(jsonObject);
writeToFile(array); writeToFile(array);
MacroButtons.initArray();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); System.out.println("Commands.json doesn't exist. Creating one...!");
// create json
JSONArray jsonArray = new JSONArray();
jsonArray.add(jsonObject);
writeToFile(jsonArray);
MacroButtons.initArray();
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -50,7 +50,7 @@ public class MacroButtons implements ModInitializer {
} }
// Assign masterCommList to an array of JSON objects (from commands.json) // Assign masterCommList to an array of JSON objects (from commands.json)
private void initArray() { static void initArray() {
masterCommList = ConfigFile.initArray(); masterCommList = ConfigFile.initArray();
if (masterCommList == null) { if (masterCommList == null) {
System.out.println("Error! Master Command List is null"); System.out.println("Error! Master Command List is null");

View File

@ -117,13 +117,17 @@ public class ButtonGUI extends LightweightGuiDescription {
ArrayList<JSONObject> commListCopy = MacroButtons.getMasterCommList(); ArrayList<JSONObject> commListCopy = MacroButtons.getMasterCommList();
if (commListCopy != null) {
commListCopy.add(newJsonObject); commListCopy.add(newJsonObject);
System.out.println(MacroButtons.masterCommList);
// Add jsonObject to commands.json // Add jsonObject to commands.json
ConfigFile.appendToFile(newJsonObject); ConfigFile.appendToFile(newJsonObject);
MacroButtons.setMasterCommList(commListCopy); MacroButtons.setMasterCommList(commListCopy);
} else {
ConfigFile.appendToFile(newJsonObject);
}
adjustBounds(); adjustBounds();
@ -176,6 +180,7 @@ public class ButtonGUI extends LightweightGuiDescription {
// Array will contain String class types. Convert these to objects // Array will contain String class types. Convert these to objects
System.out.println("I be doin my thing here"); System.out.println("I be doin my thing here");
// Then convert the objects to buttons // Then convert the objects to buttons
if (commListCopy != null) {
for (int i = 0; i < commListCopy.size(); i++) { for (int i = 0; i < commListCopy.size(); i++) {
String name = commListCopy.get(i).get("name").toString(); String name = commListCopy.get(i).get("name").toString();
String command = commListCopy.get(i).get("command").toString(); String command = commListCopy.get(i).get("command").toString();
@ -183,6 +188,8 @@ public class ButtonGUI extends LightweightGuiDescription {
} }
} }
}
private void adjustBounds() { private void adjustBounds() {
if (xValue % 12 == 0 && xValue != 0) { if (xValue % 12 == 0 && xValue != 0) {