Search in sources :

Example 1 with Parameter

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

the class GridInstance method getJsonElement.

public JsonElement getJsonElement() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.add("id", new JsonPrimitive(getId()));
    if (primaryConnection != null) {
        jsonObject.add("primary", new JsonPrimitive(primaryConnection.getId()));
    }
    if (secondaryConnection != null) {
        jsonObject.add("secondary", new JsonPrimitive(secondaryConnection.getId()));
    }
    JsonArray array = new JsonArray();
    for (Parameter parameter : getParameters()) {
        array.add(ParameterTools.getJsonElement(parameter));
    }
    jsonObject.add("parameters", array);
    return jsonObject;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter)

Example 2 with Parameter

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

the class RunningProgram method popLoopStack.

public void popLoopStack(ProcessorTileEntity processor) {
    if (loopStack.isEmpty()) {
        killMe();
    } else {
        FlowStack pair = loopStack.get(loopStack.size() - 1);
        current = pair.getCurrent();
        Integer varIdx = pair.getVar();
        loopStack.remove(loopStack.size() - 1);
        if (varIdx == null) {
        // We are returning from a function call
        } else {
            // We are ending a loop
            Parameter parameter = processor.getVariableArray()[varIdx];
            int i = TypeConverters.convertToInt(parameter);
            i++;
            processor.getVariableArray()[varIdx] = Parameter.builder().type(ParameterType.PAR_INTEGER).value(ParameterValue.constant(i)).build();
        }
    }
}
Also used : Parameter(mcjty.rftoolscontrol.api.parameters.Parameter)

Example 3 with Parameter

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

the class ProgramValidator method validate.

public static List<Pair<GridPos, String>> validate(ProgramCardInstance program) {
    List<Pair<GridPos, String>> errors = new ArrayList<>();
    Map<GridPos, GridInstance> grid = program.getGridInstances();
    // Find all unreachable instances:
    Set<GridPos> reachableLocations = new HashSet<>();
    for (Map.Entry<GridPos, GridInstance> entry : grid.entrySet()) {
        GridInstance g = entry.getValue();
        if (g.getPrimaryConnection() != null) {
            reachableLocations.add(g.getPrimaryConnection().offset(entry.getKey()));
        }
        if (g.getSecondaryConnection() != null) {
            reachableLocations.add(g.getSecondaryConnection().offset(entry.getKey()));
        }
    }
    for (Map.Entry<GridPos, GridInstance> entry : grid.entrySet()) {
        GridInstance g = entry.getValue();
        Opcode opcode = Opcodes.OPCODES.get(g.getId());
        GridPos p = entry.getKey();
        if (!opcode.isEvent() && !reachableLocations.contains(p)) {
            errors.add(Pair.of(p, "Unreachable: " + p.getX() + "," + p.getY()));
        }
    }
    // Find all missing required parameters:
    for (Map.Entry<GridPos, GridInstance> entry : grid.entrySet()) {
        GridPos p = entry.getKey();
        GridInstance g = entry.getValue();
        Opcode opcode = Opcodes.OPCODES.get(g.getId());
        List<ParameterDescription> descriptions = opcode.getParameters();
        List<Parameter> parameters = g.getParameters();
        for (int i = 0; i < descriptions.size(); i++) {
            ParameterDescription desc = descriptions.get(i);
            Parameter par = i < parameters.size() ? parameters.get(i) : null;
            if (!desc.isOptional()) {
                if (par == null || par.getParameterValue() == null || (par.getParameterValue().isConstant() && par.getParameterValue().getValue() == null)) {
                    errors.add(Pair.of(p, "Missing parameter (" + desc.getName() + "): " + p.getX() + "," + p.getY()));
                }
            }
        }
    }
    return errors;
}
Also used : Opcode(mcjty.rftoolscontrol.api.code.Opcode) GridInstance(mcjty.rftoolscontrol.logic.grid.GridInstance) GridPos(mcjty.rftoolscontrol.logic.grid.GridPos) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) ParameterDescription(mcjty.rftoolscontrol.api.parameters.ParameterDescription) Pair(org.apache.commons.lang3.tuple.Pair)

Example 4 with Parameter

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

the class TokenItem method addInformation.

@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, World playerIn, List<String> list, ITooltipFlag advanced) {
    super.addInformation(stack, playerIn, list, advanced);
    boolean hasContents = false;
    if (stack.hasTagCompound()) {
        NBTTagCompound parameter = stack.getTagCompound().getCompoundTag("parameter");
        if (!parameter.hasNoTags()) {
            Parameter par = ParameterTools.readFromNBT(parameter);
            hasContents = true;
            list.add(TextFormatting.BLUE + "Type: " + par.getParameterType().getName());
            list.add(TextFormatting.BLUE + "Value: " + ParameterTypeTools.stringRepresentation(par.getParameterType(), par.getParameterValue()));
        }
    }
    if (!hasContents) {
        list.add(TextFormatting.BLUE + "This token is empty");
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
        list.add(TextFormatting.WHITE + "This item is a simple token. It does");
        list.add(TextFormatting.WHITE + "not do anything but it can store");
        list.add(TextFormatting.WHITE + "information");
    } else {
        list.add(TextFormatting.WHITE + RFToolsControl.SHIFT_MESSAGE);
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with Parameter

use of mcjty.rftoolscontrol.api.parameters.Parameter 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;
}
Also used : ParameterValue(mcjty.rftoolscontrol.api.parameters.ParameterValue) IIcon(mcjty.lib.gui.icons.IIcon) Connection(mcjty.rftoolscontrol.logic.Connection) Opcode(mcjty.rftoolscontrol.api.code.Opcode) ProgramCardInstance(mcjty.rftoolscontrol.logic.grid.ProgramCardInstance) GridInstance(mcjty.rftoolscontrol.logic.grid.GridInstance) Parameter(mcjty.rftoolscontrol.api.parameters.Parameter) ParameterDescription(mcjty.rftoolscontrol.api.parameters.ParameterDescription)

Aggregations

Parameter (mcjty.rftoolscontrol.api.parameters.Parameter)15 Opcode (mcjty.rftoolscontrol.api.code.Opcode)7 ParameterDescription (mcjty.rftoolscontrol.api.parameters.ParameterDescription)6 GridInstance (mcjty.rftoolscontrol.logic.grid.GridInstance)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 IIcon (mcjty.lib.gui.icons.IIcon)3 GridPos (mcjty.rftoolscontrol.logic.grid.GridPos)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 Window (mcjty.lib.gui.Window)2 PositionalLayout (mcjty.lib.gui.layout.PositionalLayout)2 VerticalLayout (mcjty.lib.gui.layout.VerticalLayout)2 Button (mcjty.lib.gui.widgets.Button)2 Label (mcjty.lib.gui.widgets.Label)2 Panel (mcjty.lib.gui.widgets.Panel)2 ParameterType (mcjty.rftoolscontrol.api.parameters.ParameterType)2 ParameterValue (mcjty.rftoolscontrol.api.parameters.ParameterValue)2 Connection (mcjty.rftoolscontrol.logic.Connection)2 ParameterEditor (mcjty.rftoolscontrol.logic.editors.ParameterEditor)2 ProgramCardInstance (mcjty.rftoolscontrol.logic.grid.ProgramCardInstance)2