use of mcjty.rftoolscontrol.logic.grid.GridPos in project RFToolsControl by McJty.
the class GuiProgrammer method gridIconClicked.
private void gridIconClicked(IIcon icon, int x, int y, int dx, int dy) {
if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)) {
long time = System.currentTimeMillis();
boolean doubleclick = false;
if (prevTime != -1L && time - prevTime < 250L) {
doubleclick = true;
}
prevTime = time;
if (icon.hasOverlay("S")) {
if (doubleclick) {
// Reverse because first click also did something
selectSequence(new GridPos(x, y), new HashSet<>(), true);
} else {
icon.removeOverlay("S");
}
} else {
if (doubleclick) {
// Reverse because first click also did something
selectSequence(new GridPos(x, y), new HashSet<>(), false);
} else {
icon.addOverlay(selectionIcon);
}
}
return;
}
clearSelection();
long time = System.currentTimeMillis();
boolean doubleclick = !GeneralConfiguration.doubleClickToChangeConnector;
if (prevTime != -1L && time - prevTime < 250L) {
doubleclick = true;
}
prevTime = time;
if (doubleclick) {
Connection connection = getConnectionHandle(dx, dy);
if (connection != null) {
handleIconOverlay(icon, connection);
}
}
}
use of mcjty.rftoolscontrol.logic.grid.GridPos in project RFToolsControl by McJty.
the class GuiProgrammer method validateAndHilight.
private void validateAndHilight() {
ProgramCardInstance instance = makeGridInstance(false);
for (int x = 0; x < GRID_WIDTH; x++) {
for (int y = 0; y < GRID_HEIGHT; y++) {
IconHolder h = getHolder(x, y);
if (h.getIcon() != null) {
h.getIcon().removeOverlay("E1");
h.getIcon().removeOverlay("E2");
}
}
}
long time = System.currentTimeMillis();
List<Pair<GridPos, String>> errors = ProgramValidator.validate(instance);
for (Pair<GridPos, String> entry : errors) {
GridPos p = entry.getKey();
IconHolder h = getHolder(p.getX(), p.getY());
h.getIcon().addOverlay((time % 2000) < 1000 ? errorIcon1 : errorIcon2);
}
}
use of mcjty.rftoolscontrol.logic.grid.GridPos in project RFToolsControl by McJty.
the class CompiledCard method compile.
public static CompiledCard compile(ProgramCardInstance cardInstance) {
if (cardInstance == null) {
return null;
}
CompiledCard card = new CompiledCard();
Map<GridPos, GridInstance> gridInstances = cardInstance.getGridInstances();
// First find the indices of all compiled grid instances
Map<GridPos, Integer> posToIndex = new HashMap<>();
for (Map.Entry<GridPos, GridInstance> entry : gridInstances.entrySet()) {
GridPos location = entry.getKey();
posToIndex.put(location, posToIndex.size());
}
// Index of a dummy stop opcode that we can use to go too in case there is no real connection
int stopIdx = posToIndex.size();
for (Map.Entry<GridPos, GridInstance> entry : gridInstances.entrySet()) {
GridPos location = entry.getKey();
GridInstance grid = entry.getValue();
String id = grid.getId();
Opcode opcode = Opcodes.OPCODES.get(id);
GridPos primaryOutput = grid.getPrimaryConnection() != null ? grid.getPrimaryConnection().offset(location) : null;
GridPos secondaryOutput = grid.getSecondaryConnection() != null ? grid.getSecondaryConnection().offset(location) : null;
CompiledOpcode.Builder opcodeBuilder = CompiledOpcode.builder().opcode(opcode);
opcodeBuilder.grid(location.getX(), location.getY());
if (primaryOutput != null && posToIndex.containsKey(primaryOutput)) {
opcodeBuilder.primaryIndex(posToIndex.get(primaryOutput));
} else {
opcodeBuilder.primaryIndex(stopIdx);
}
if (secondaryOutput != null && posToIndex.containsKey(secondaryOutput)) {
opcodeBuilder.secondaryIndex(posToIndex.get(secondaryOutput));
} else {
opcodeBuilder.secondaryIndex(stopIdx);
}
List<ParameterDescription> parameters = opcode.getParameters();
boolean single = false;
for (int i = 0; i < grid.getParameters().size(); i++) {
Parameter parameter = grid.getParameters().get(i);
if (i < parameters.size() && "single".equals(parameters.get(i).getName())) {
single = TypeConverters.convertToBool(parameter);
}
opcodeBuilder.parameter(parameter);
}
if (opcode.isEvent()) {
card.events.putIfAbsent(opcode, new ArrayList<>());
card.events.get(opcode).add(new CompiledEvent(card.opcodes.size(), single));
}
card.opcodes.add(opcodeBuilder.build());
}
card.opcodes.add(CompiledOpcode.builder().opcode(Opcodes.DO_STOP_OR_RESUME).build());
for (Opcode opcode : Opcodes.OPCODES.values()) {
if (!card.events.containsKey(opcode)) {
card.events.put(opcode, Collections.emptyList());
}
}
return card;
}
Aggregations