remove bloat code
This commit is contained in:
parent
f078d92af7
commit
9f674f2d1f
@ -1,7 +0,0 @@
|
|||||||
package com.josyf.macrobuttons;
|
|
||||||
|
|
||||||
public class CommandObject {
|
|
||||||
|
|
||||||
public CommandObject(String name, String command) {
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,9 +2,6 @@ package com.josyf.macrobuttons;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.cedarsoftware.util.io.JsonWriter;
|
import com.cedarsoftware.util.io.JsonWriter;
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.josyf.macrobuttons.gui.ButtonGUI;
|
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
@ -15,49 +12,9 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class ConfigFile {
|
public class ConfigFile {
|
||||||
|
|
||||||
|
|
||||||
static JSONParser parser = new JSONParser();
|
static JSONParser parser = new JSONParser();
|
||||||
|
|
||||||
private static FileWriter fileWriter;
|
private static FileWriter fileWriter;
|
||||||
|
|
||||||
public static void serializeCommand() {
|
|
||||||
// CREATE OBJECT
|
|
||||||
CommandObject newCommand = new CommandObject("Say hello", "hello command");
|
|
||||||
|
|
||||||
// add new object to config
|
|
||||||
appendToFile(newCommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadSerialization() {
|
|
||||||
String JSONConfig = ButtonGUI.getConfig();
|
|
||||||
if (JSONConfig == null) {
|
|
||||||
MacroButtons.runCommand("GUI Configuration not yet initialized!");
|
|
||||||
} else {
|
|
||||||
System.out.println(readFile());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if commands.json exists, read it, convert it to an array, and append
|
|
||||||
// DEPRECATED PROBABLY DELETABLE
|
|
||||||
private static void appendToFile(CommandObject commandObject) {
|
|
||||||
JSONArray jsonArray = new JSONArray();
|
|
||||||
try {
|
|
||||||
// if commands.json exists, read it, convert it to an array, and append
|
|
||||||
Object obj = parser.parse(new FileReader("commands.json"));
|
|
||||||
|
|
||||||
JSONArray array = (JSONArray) obj;
|
|
||||||
JSONObject obj2 = (JSONObject)array.get(0);
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Commands.json doesn't exist. Creating one...");
|
|
||||||
// create json
|
|
||||||
jsonArray.add(commandObject);
|
|
||||||
writeToFile(jsonArray);
|
|
||||||
} catch (ParseException e) {
|
|
||||||
System.out.println("Something went wrong |o|");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if command.json exists, read it, convert it to an array, and append A JSON OBJECT
|
// if command.json exists, read it, convert it to an array, and append A JSON OBJECT
|
||||||
public static void appendToFile(JSONObject jsonObject) {
|
public static void appendToFile(JSONObject jsonObject) {
|
||||||
try {
|
try {
|
||||||
@ -119,42 +76,4 @@ public class ConfigFile {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEPRECATED CAN PROBABLY DELETE
|
|
||||||
private static void writeToFile(String jsonMessage) {
|
|
||||||
try {
|
|
||||||
// these both write to the correct location
|
|
||||||
fileWriter = new FileWriter("commands.json");
|
|
||||||
// file = new FileWriter(MinecraftClient.getInstance().runDirectory + "/command.json");
|
|
||||||
System.out.println("APPENDING!");
|
|
||||||
|
|
||||||
fileWriter.write(jsonMessage);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
fileWriter.flush();
|
|
||||||
fileWriter.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String readFile() {
|
|
||||||
try {
|
|
||||||
Object obj = parser.parse(new FileReader("commands.json"));
|
|
||||||
String jsonString = obj.toString();
|
|
||||||
//String jsonString = JSONObject.toJSONString(obj);
|
|
||||||
System.out.println(jsonString);
|
|
||||||
return jsonString;
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return "Not yet initialized yo";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,63 +17,21 @@ public class ButtonGUI extends LightweightGuiDescription {
|
|||||||
int xValue = 0;
|
int xValue = 0;
|
||||||
int yValue = 1;
|
int yValue = 1;
|
||||||
|
|
||||||
private static String ConfigSettings = ConfigFile.readFile();
|
|
||||||
|
|
||||||
public ButtonGUI() {
|
public ButtonGUI() {
|
||||||
|
|
||||||
// initialize root panel of GUI
|
// initialize root panel of GUI
|
||||||
WGridPanel root = new WGridPanel();
|
WGridPanel root = new WGridPanel();
|
||||||
|
|
||||||
setupBackground(root);
|
setupBackground(root);
|
||||||
|
|
||||||
// ######### DEBUG BUTTONS ############
|
|
||||||
// example button to create config JSON
|
|
||||||
WButton button = new WButton(new TranslatableText("Serialize"));
|
|
||||||
button.setOnClick(() -> {
|
|
||||||
ConfigFile.serializeCommand();
|
|
||||||
});
|
|
||||||
root.add(button, xValue, yValue + 9, 4, 1);
|
|
||||||
|
|
||||||
// example load serialization button
|
|
||||||
WButton button2 = new WButton(new TranslatableText("Load Serialization"));
|
|
||||||
button2.setOnClick(() -> {
|
|
||||||
ConfigFile.loadSerialization();
|
|
||||||
});
|
|
||||||
root.add(button2, xValue + 4, yValue + 9, 6, 1);
|
|
||||||
|
|
||||||
// read json file button
|
|
||||||
WButton button3 = new WButton(new TranslatableText("Read command json"));
|
|
||||||
button3.setOnClick(() -> {
|
|
||||||
ConfigFile.readFile();
|
|
||||||
});
|
|
||||||
root.add(button3, xValue + 10, yValue + 9, 6, 1);
|
|
||||||
|
|
||||||
|
|
||||||
// read mastercommlist
|
|
||||||
// read json file button
|
|
||||||
WButton button4 = new WButton(new TranslatableText("Read master list"));
|
|
||||||
button4.setOnClick(() -> {
|
|
||||||
System.out.println(MacroButtons.getMasterCommList());
|
|
||||||
});
|
|
||||||
root.add(button4, xValue + 10, yValue + 8, 6, 1);
|
|
||||||
|
|
||||||
// ######### DEBUG BUTTONS ############
|
|
||||||
|
|
||||||
// Text GUI, not needed yet
|
// Text GUI, not needed yet
|
||||||
// WLabel label = new WLabel(new LiteralText("Test"), 0xFFFFFF);
|
// WLabel label = new WLabel(new LiteralText("Test"), 0xFFFFFF);
|
||||||
// root.add(label, 0, 4, 2, 1);
|
// root.add(label, 0, 4, 2, 1);
|
||||||
|
|
||||||
addSavedButtons(root);
|
addSavedButtons(root);
|
||||||
|
|
||||||
addCommandSection(root);
|
addCommandSection(root);
|
||||||
|
|
||||||
root.validate(this);
|
root.validate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getConfig() {
|
|
||||||
return ConfigSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addCommandSection(WGridPanel root) {
|
private void addCommandSection(WGridPanel root) {
|
||||||
// Add text field for command NAME entry
|
// Add text field for command NAME entry
|
||||||
WTextField nameTextField = new WTextField();
|
WTextField nameTextField = new WTextField();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user