Search in sources :

Example 1 with ParameterType

use of mcjty.rftoolscontrol.api.parameters.ParameterType in project RFToolsControl by McJty.

the class Functions method register.

public static void register(Function function) {
    FUNCTIONS.put(function.getId(), function);
    ParameterType type = function.getReturnType();
    if (!FUNCTIONS_BY_TYPE.containsKey(type)) {
        FUNCTIONS_BY_TYPE.put(type, new ArrayList<>());
    }
    FUNCTIONS_BY_TYPE.get(type).add(function);
}
Also used : ParameterType(mcjty.rftoolscontrol.api.parameters.ParameterType)

Example 2 with ParameterType

use of mcjty.rftoolscontrol.api.parameters.ParameterType in project RFToolsControl by McJty.

the class AbstractParameterEditor method createEditorPanel.

void createEditorPanel(Minecraft mc, Gui gui, Panel panel, ParameterEditorCallback callback, Panel constantPanel, ParameterType type) {
    Panel variablePanel = new Panel(mc, gui).setLayout(new HorizontalLayout()).setDesiredHeight(18);
    variableIndex = new TextField(mc, gui).setDesiredHeight(14).setTooltips("Index (in the processor)", "of the variable", "(first variable has index 0)").addTextEvent((parent, newText) -> callback.valueChanged(readValue()));
    variablePanel.addChild(new Label(mc, gui).setText("Index:")).setTooltips("Index (in the processor)", "of the variable", "(first variable has index 0)").setDesiredHeight(14).addChild(variableIndex);
    Panel functionPanel = new Panel(mc, gui).setLayout(new HorizontalLayout());
    functionLabel = new ChoiceLabel(mc, gui).setDesiredWidth(120);
    List<Function> functions = Functions.getFunctionsByType(type);
    for (Function function : functions) {
        functionLabel.addChoices(function.getId());
        functionLabel.setChoiceTooltip(function.getId(), function.getDescription().toArray(new String[function.getDescription().size()]));
    }
    functionPanel.addChild(functionLabel);
    functionLabel.addChoiceEvent(((parent, newChoice) -> callback.valueChanged(readValue())));
    tabbedPanel = new TabbedPanel(mc, gui).addPage(PAGE_CONSTANT, constantPanel).addPage(PAGE_VARIABLE, variablePanel).addPage(PAGE_FUNCTION, functionPanel);
    tabbedPanel.setLayoutHint(new PositionalLayout.PositionalHint(5, 5 + 18, 190 - 10, 60 + getHeight() - 5 - 18 - 40));
    buttonPanel = new Panel(mc, gui).setLayout(new HorizontalLayout()).setLayoutHint(new PositionalLayout.PositionalHint(5, 5, 190 - 10, 18));
    ToggleButton constantButton = new ToggleButton(mc, gui).setText(PAGE_CONSTANT).addButtonEvent(w -> switchPage(PAGE_CONSTANT, callback));
    variableButton = new ToggleButton(mc, gui).setText(PAGE_VARIABLE).addButtonEvent(w -> switchPage(PAGE_VARIABLE, callback));
    functionButton = new ToggleButton(mc, gui).setText(PAGE_FUNCTION).addButtonEvent(w -> switchPage(PAGE_FUNCTION, callback));
    buttonPanel.addChild(constantButton).addChild(variableButton).addChild(functionButton);
    panel.addChild(buttonPanel).addChild(tabbedPanel);
}
Also used : Window(mcjty.lib.gui.Window) ParameterType(mcjty.rftoolscontrol.api.parameters.ParameterType) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) Gui(net.minecraft.client.gui.Gui) List(java.util.List) mcjty.lib.gui.widgets(mcjty.lib.gui.widgets) ParameterValue(mcjty.rftoolscontrol.api.parameters.ParameterValue) Minecraft(net.minecraft.client.Minecraft) HorizontalAlignment(mcjty.lib.gui.layout.HorizontalAlignment) Function(mcjty.rftoolscontrol.api.code.Function) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) Functions(mcjty.rftoolscontrol.logic.registry.Functions) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) Function(mcjty.rftoolscontrol.api.code.Function)

Example 3 with ParameterType

use of mcjty.rftoolscontrol.api.parameters.ParameterType in project RFToolsControl by McJty.

the class Commands method handleDebugCommand.

private static void handleDebugCommand(ProcessorTileEntity processor, String[] splitted) {
    List<CpuCore> cores = processor.getCpuCores();
    String sub = splitted[1].toLowerCase();
    if ("debug".equals(sub)) {
        if (splitted.length > 2) {
            try {
                int core = Integer.parseInt(splitted[2]);
                cores.get(core).setDebug(true);
                processor.log(TextFormatting.YELLOW + "Debug mode for core: " + core);
            } catch (Exception e) {
                processor.log(TextFormatting.RED + "Bad core number");
                return;
            }
        } else {
            for (CpuCore core : cores) {
                core.setDebug(true);
            }
            processor.log(TextFormatting.YELLOW + "Debug mode for all cores");
        }
    } else if ("resume".equals(sub)) {
        if (splitted.length > 2) {
            try {
                int core = Integer.parseInt(splitted[2]);
                cores.get(core).setDebug(false);
                processor.log(TextFormatting.YELLOW + "Resume core: " + core);
            } catch (Exception e) {
                processor.log(TextFormatting.RED + "Bad core number");
                return;
            }
        } else {
            for (CpuCore core : cores) {
                core.setDebug(false);
            }
            processor.log(TextFormatting.YELLOW + "Resume all cores");
        }
    } else if ("info".equals(sub)) {
        for (int i = 0; i < cores.size(); i++) {
            CpuCore core = cores.get(i);
            if (core.isDebug()) {
                RunningProgram program = core.getProgram();
                if (program == null) {
                    processor.log("Core " + i + ": " + "not running");
                } else {
                    showCurrent(processor, i, program);
                }
            }
        }
    } else if ("last".equals(sub)) {
        if (splitted.length > 2) {
            try {
                int i = Integer.parseInt(splitted[2]);
                CpuCore core = cores.get(i);
                if (core.hasProgram()) {
                    Parameter value = core.getProgram().getLastValue();
                    if (value == null || value.getParameterValue() == null) {
                        processor.log(TextFormatting.YELLOW + "Last value not set");
                    } else {
                        ParameterType type = value.getParameterType();
                        processor.log(TextFormatting.YELLOW + "Last " + type.getName() + ": " + TypeConverters.convertToString(value));
                    }
                } else {
                    processor.log(TextFormatting.YELLOW + "No program!");
                }
            } catch (Exception e) {
                processor.log(TextFormatting.RED + "Bad core number");
                return;
            }
        } else {
            int i = 0;
            for (CpuCore core : cores) {
                if (core.hasProgram()) {
                    Parameter value = core.getProgram().getLastValue();
                    if (value == null || value.getParameterValue() == null) {
                        processor.log(TextFormatting.YELLOW + "" + i + ": Last value not set");
                    } else {
                        ParameterType type = value.getParameterType();
                        processor.log(TextFormatting.YELLOW + "" + i + ": Last " + type.getName() + ": " + TypeConverters.convertToString(value));
                    }
                }
                i++;
            }
        }
    } else if ("step".equals(sub) || "s".equals(sub)) {
        int cnt = 0;
        for (CpuCore core : cores) {
            if (core.isDebug()) {
                cnt++;
            }
        }
        int c = 0;
        if (cnt == 0) {
            processor.log(TextFormatting.RED + "Not debugging");
            return;
        } else if (cnt > 1) {
            if (splitted.length <= 2) {
                processor.log(TextFormatting.RED + "Missing core number");
                return;
            }
            try {
                c = Integer.parseInt(splitted[2]);
            } catch (Exception e) {
                processor.log(TextFormatting.RED + "Bad core number");
                return;
            }
        }
        CpuCore core = cores.get(c);
        RunningProgram program = core.getProgram();
        if (program == null) {
            processor.log(TextFormatting.RED + "Core " + c + ": " + "not running");
            return;
        }
        core.step(processor);
        showCurrent(processor, c, program);
    } else {
        processor.log("Unknown 'db' command!");
    }
}
Also used : ParameterType(mcjty.rftoolscontrol.api.parameters.ParameterType) CpuCore(mcjty.rftoolscontrol.logic.running.CpuCore) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) RunningProgram(mcjty.rftoolscontrol.logic.running.RunningProgram)

Example 4 with ParameterType

use of mcjty.rftoolscontrol.api.parameters.ParameterType in project RFToolsControl by McJty.

the class GuiProcessor method openValueEditor.

private void openValueEditor(int varIdx) {
    if (fromServer_vars == null || varIdx > fromServer_vars.size()) {
        return;
    }
    if (fromServer_vars.get(varIdx) == null) {
        GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, "Variable is not defined!");
        return;
    }
    Parameter parameter = fromServer_vars.get(varIdx);
    if (parameter == null) {
        GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, "Variable is not defined!");
        return;
    }
    ParameterType type = parameter.getParameterType();
    ParameterEditor editor = ParameterEditors.getEditor(type);
    Panel editPanel;
    if (editor != null) {
        editPanel = new Panel(mc, this).setLayout(new PositionalLayout()).setFilledRectThickness(1);
        editor.build(mc, this, editPanel, o -> {
            NBTTagCompound tag = new NBTTagCompound();
            ParameterTypeTools.writeToNBT(tag, type, o);
            RFToolsCtrlMessages.INSTANCE.sendToServer(new PacketVariableToServer(tileEntity.getPos(), varIdx, tag));
        });
        editor.writeValue(parameter.getParameterValue());
        editor.constantOnly();
    } else {
        return;
    }
    Panel panel = new Panel(mc, this).setLayout(new VerticalLayout()).setFilledBackground(0xff666666, 0xffaaaaaa).setFilledRectThickness(1);
    panel.setBounds(new Rectangle(50, 50, 200, 60 + editor.getHeight()));
    Window modalWindow = getWindowManager().createModalWindow(panel);
    panel.addChild(new Label(mc, this).setText("Var " + varIdx + ":"));
    panel.addChild(editPanel);
    panel.addChild(new Button(mc, this).addButtonEvent(w -> {
        getWindowManager().closeWindow(modalWindow);
    }).setText("Close"));
}
Also used : Window(mcjty.lib.gui.Window) Panel(mcjty.lib.gui.widgets.Panel) ParameterType(mcjty.rftoolscontrol.api.parameters.ParameterType) Button(mcjty.lib.gui.widgets.Button) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Label(mcjty.lib.gui.widgets.Label) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) VerticalLayout(mcjty.lib.gui.layout.VerticalLayout) ParameterEditor(mcjty.rftoolscontrol.logic.editors.ParameterEditor)

Example 5 with ParameterType

use of mcjty.rftoolscontrol.api.parameters.ParameterType in project RFToolsControl by McJty.

the class RunningProgram method readFromNBT.

public static RunningProgram readFromNBT(NBTTagCompound tag) {
    if (!tag.hasKey("card")) {
        return null;
    }
    int cardIndex = tag.getInteger("card");
    RunningProgram program = new RunningProgram(cardIndex);
    program.setCurrent(tag.getInteger("current"));
    program.eventIndex = tag.getInteger("event");
    program.setDelay(tag.getInteger("delay"));
    program.dead = tag.getBoolean("dead");
    if (tag.hasKey("ticket")) {
        program.ticket = tag.getString("ticket");
    }
    if (tag.hasKey("lock")) {
        program.lock = tag.getString("lock");
    }
    if (tag.hasKey("lastvar")) {
        NBTTagCompound varTag = tag.getCompoundTag("lastvar");
        int t = varTag.getInteger("type");
        ParameterType type = ParameterType.values()[t];
        program.lastValue = Parameter.builder().type(type).value(ParameterTypeTools.readFromNBT(varTag, type)).build();
    }
    if (tag.hasKey("loopStack")) {
        program.loopStack.clear();
        NBTTagList loopList = tag.getTagList("loopStack", Constants.NBT.TAG_COMPOUND);
        for (int i = 0; i < loopList.tagCount(); i++) {
            NBTTagCompound t = loopList.getCompoundTagAt(i);
            int var = tag.getInteger("var");
            program.loopStack.add(new FlowStack(tag.getInteger("index"), var == -1 ? null : var));
        }
    }
    return program;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ParameterType(mcjty.rftoolscontrol.api.parameters.ParameterType) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

ParameterType (mcjty.rftoolscontrol.api.parameters.ParameterType)5 Window (mcjty.lib.gui.Window)2 PositionalLayout (mcjty.lib.gui.layout.PositionalLayout)2 Parameter (mcjty.rftoolscontrol.api.parameters.Parameter)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 List (java.util.List)1 HorizontalAlignment (mcjty.lib.gui.layout.HorizontalAlignment)1 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)1 VerticalLayout (mcjty.lib.gui.layout.VerticalLayout)1 mcjty.lib.gui.widgets (mcjty.lib.gui.widgets)1 Button (mcjty.lib.gui.widgets.Button)1 Label (mcjty.lib.gui.widgets.Label)1 Panel (mcjty.lib.gui.widgets.Panel)1 Function (mcjty.rftoolscontrol.api.code.Function)1 ParameterValue (mcjty.rftoolscontrol.api.parameters.ParameterValue)1 ParameterEditor (mcjty.rftoolscontrol.logic.editors.ParameterEditor)1 Functions (mcjty.rftoolscontrol.logic.registry.Functions)1 CpuCore (mcjty.rftoolscontrol.logic.running.CpuCore)1 RunningProgram (mcjty.rftoolscontrol.logic.running.RunningProgram)1 Minecraft (net.minecraft.client.Minecraft)1