add preliminary pseudocode for loading buttons from json
This commit is contained in:
parent
4ee594b033
commit
6db63b8f8c
@ -2,6 +2,6 @@ package com.josyf.macrobuttons;
|
||||
|
||||
public class CommandObject {
|
||||
|
||||
public String name;
|
||||
public String command;
|
||||
public CommandObject(String name, String command) {
|
||||
}
|
||||
}
|
||||
|
@ -29,9 +29,7 @@ public class ConfigFile {
|
||||
public static void serializeCommand() {
|
||||
|
||||
// CREATE OBJECT
|
||||
CommandObject newCommand = new CommandObject();
|
||||
newCommand.name = "Say Hello";
|
||||
newCommand.command = "Hello 2";
|
||||
CommandObject newCommand = new CommandObject("Say hello", "hello command");
|
||||
|
||||
// add new object to config
|
||||
appendToFile(newCommand);
|
||||
@ -101,6 +99,21 @@ public class ConfigFile {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: create func initArray to assign global JSONArray masterCommList to commands.json
|
||||
public static JSONArray initArray() {
|
||||
Object obj = null;
|
||||
try {
|
||||
obj = parser.parse(new FileReader("commands.json"));
|
||||
JSONArray array = (JSONArray) parser.parse(obj.toString());
|
||||
return array;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void writeToFile(String jsonMessage) {
|
||||
try {
|
||||
// these both write to the correct location
|
||||
|
@ -10,15 +10,19 @@ import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public class MacroButtons implements ModInitializer {
|
||||
|
||||
public static final String MOD_ID = "mgbuttons";
|
||||
public static JSONArray masterCommList;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
assignGuiToKey();
|
||||
// TODO: call initArray(); here
|
||||
initArray();
|
||||
}
|
||||
|
||||
private void assignGuiToKey() {
|
||||
@ -37,7 +41,6 @@ public class MacroButtons implements ModInitializer {
|
||||
while (keyBinding.wasPressed()) {
|
||||
// client.player.sendMessage(new LiteralText("Key 1 was pressed!"), false);
|
||||
MinecraftClient.getInstance().openScreen(new ButtonGUIScreen(new ButtonGUI()));
|
||||
// printMessage();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -51,7 +54,13 @@ public class MacroButtons implements ModInitializer {
|
||||
MinecraftClient.getInstance().player.sendChatMessage(message);
|
||||
}
|
||||
|
||||
|
||||
// TODO: create func initArray to assign global JSONArray masterCommList to commands.json
|
||||
private void initArray() {
|
||||
masterCommList = ConfigFile.initArray();
|
||||
if (masterCommList == null) {
|
||||
System.out.println("Error! Master Command List is null");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@ import io.github.cottonmc.cotton.gui.widget.WButton;
|
||||
import io.github.cottonmc.cotton.gui.widget.WGridPanel;
|
||||
import io.github.cottonmc.cotton.gui.widget.WTextField;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class ButtonGUI extends LightweightGuiDescription {
|
||||
|
||||
@ -52,6 +54,9 @@ public class ButtonGUI extends LightweightGuiDescription {
|
||||
// WLabel label = new WLabel(new LiteralText("Test"), 0xFFFFFF);
|
||||
// root.add(label, 0, 4, 2, 1);
|
||||
|
||||
// TODO: addSavedButtons();
|
||||
addSavedButtons();
|
||||
|
||||
addCommandSection(root);
|
||||
|
||||
root.validate(this);
|
||||
@ -112,6 +117,22 @@ public class ButtonGUI extends LightweightGuiDescription {
|
||||
|
||||
}
|
||||
|
||||
// TODO: addSavedButtons
|
||||
// TODO: Iterate over masterCommList to add corresponding buttons
|
||||
// Array will contain String class types. Convert these to objects.
|
||||
private void addSavedButtons() {
|
||||
JSONArray stringCommList = MacroButtons.masterCommList;
|
||||
JSONArray objCommList;
|
||||
// Array will contain String class types. Convert these to objects
|
||||
for (int i = 0; i < stringCommList.size(); i++) {
|
||||
Object anObject = stringCommList.get(i);
|
||||
//System.out.println(stringCommList.get(i).getClass());
|
||||
//anObject
|
||||
}
|
||||
// Then convert the objects to buttons
|
||||
}
|
||||
|
||||
|
||||
private void adjustBounds() {
|
||||
if (xValue % 12 == 0 && xValue != 0) {
|
||||
yValue += 2;
|
||||
|
Loading…
x
Reference in New Issue
Block a user