use of mcjty.rftoolscontrol.logic.grid.ProgramCardInstance in project RFToolsControl by McJty.
the class GuiProgrammer method loadProgram.
private void loadProgram(int slot) {
ItemStack card = tileEntity.getStackInSlot(slot);
if (card.isEmpty()) {
return;
}
clearGrid(false);
ProgramCardInstance instance = ProgramCardInstance.parseInstance(card);
if (instance == null) {
return;
}
loadProgram(instance);
}
use of mcjty.rftoolscontrol.logic.grid.ProgramCardInstance in project RFToolsControl by McJty.
the class GuiProgrammer method validateProgram.
private void validateProgram() {
Panel panel = new Panel(mc, this).setLayout(new VerticalLayout()).setFilledBackground(0xff666666, 0xffaaaaaa).setFilledRectThickness(1);
panel.setBounds(new Rectangle(60, 10, 200, 130));
Window modalWindow = getWindowManager().createModalWindow(panel);
WidgetList errorList = new WidgetList(mc, this);
errorList.addSelectionEvent(new SelectionEvent() {
@Override
public void select(Widget parent, int index) {
}
@Override
public void doubleClick(Widget parent, int index) {
if (errorList.getSelected() != -1) {
Widget<?> child = errorList.getChild(errorList.getSelected());
GridPos pos = (GridPos) child.getUserObject();
if (pos != null) {
window.setTextFocus(getHolder(pos.getX(), pos.getY()));
}
}
getWindowManager().closeWindow(modalWindow);
}
});
panel.addChild(errorList);
panel.addChild(new Button(mc, this).addButtonEvent(w -> {
getWindowManager().closeWindow(modalWindow);
}).setText("Close"));
ProgramCardInstance instance = makeGridInstance(false);
List<Pair<GridPos, String>> errors = ProgramValidator.validate(instance);
for (Pair<GridPos, String> entry : errors) {
GridPos p = entry.getKey();
errorList.addChild(new Label(mc, this).setColor(0xffff0000).setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setText(entry.getValue()).setUserObject(p));
}
}
use of mcjty.rftoolscontrol.logic.grid.ProgramCardInstance in project RFToolsControl by McJty.
the class ProgramCommand method saveProgram.
private void saveProgram(ICommandSender sender, String arg, ItemStack item) {
ProgramCardInstance program = ProgramCardInstance.parseInstance(item);
String json = program.writeToJson();
// File file = new File("." + File.separator + "rftoolscontrol" + File.separator + arg);
File file = new File(arg);
if (file.exists()) {
file.delete();
}
try (PrintWriter writer = new PrintWriter(file)) {
writer.print(json);
} catch (FileNotFoundException e) {
ITextComponent component = new TextComponentString(TextFormatting.RED + "Error opening file for writing!");
if (sender instanceof EntityPlayer) {
((EntityPlayer) sender).sendStatusMessage(component, false);
} else {
sender.sendMessage(component);
}
return;
}
ITextComponent component = new TextComponentString("Saved program!");
if (sender instanceof EntityPlayer) {
((EntityPlayer) sender).sendStatusMessage(component, false);
} else {
sender.sendMessage(component);
}
}
use of mcjty.rftoolscontrol.logic.grid.ProgramCardInstance in project RFToolsControl by McJty.
the class ProgramCommand method loadProgram.
private void loadProgram(ICommandSender sender, String arg, ItemStack item) {
// File file = new File("." + File.separator + "rftoolscontrol" + File.separator + arg);
File file = new File(arg);
String json;
try (FileInputStream stream = new FileInputStream(file)) {
byte[] data = new byte[(int) file.length()];
stream.read(data);
json = new String(data, "UTF-8");
} catch (IOException e) {
ITextComponent component = new TextComponentString(TextFormatting.RED + "Error opening file for reading!");
if (sender instanceof EntityPlayer) {
((EntityPlayer) sender).sendStatusMessage(component, false);
} else {
sender.sendMessage(component);
}
return;
}
ProgramCardInstance program = ProgramCardInstance.readFromJson(json);
program.writeToNBT(item);
RFToolsCtrlMessages.INSTANCE.sendToServer(new PacketItemNBTToServer(item.getTagCompound()));
ITextComponent component = new TextComponentString("Loaded program!");
if (sender instanceof EntityPlayer) {
((EntityPlayer) sender).sendStatusMessage(component, false);
} else {
sender.sendMessage(component);
}
}
use of mcjty.rftoolscontrol.logic.grid.ProgramCardInstance in project RFToolsControl by McJty.
the class GuiProgrammer method makeGridInstance.
private ProgramCardInstance makeGridInstance(boolean selectionOnly) {
ProgramCardInstance instance = ProgramCardInstance.newInstance();
for (int x = 0; x < GRID_WIDTH; x++) {
for (int y = 0; y < GRID_HEIGHT; y++) {
IconHolder holder = getHolder(x, y);
IIcon icon = holder.getIcon();
if (icon != null) {
if (selectionOnly && !icon.hasOverlay("S")) {
continue;
}
String operandId = icon.getID();
GridInstance.Builder builder = GridInstance.builder(operandId);
for (Connection connection : Connection.values()) {
if (icon.hasOverlay(connection.getId())) {
if (connection.isPrimary()) {
builder.primaryConnection(connection);
} else {
builder.secondaryConnection(connection);
}
}
}
Opcode opcode = Opcodes.OPCODES.get(operandId);
Map<String, Object> data = icon.getData();
for (ParameterDescription description : opcode.getParameters()) {
ParameterValue value = data == null ? null : (ParameterValue) data.get(description.getName());
if (value == null) {
value = ParameterValue.constant(null);
}
Parameter parameter = Parameter.builder().type(description.getType()).value(value).build();
builder.parameter(parameter);
}
instance.putGridInstance(x, y, builder.build());
}
}
}
return instance;
}
Aggregations