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;
}
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();
}
}
}
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;
}
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);
}
}
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;
}
Aggregations