Only allow one connection per in/out pair.

This commit is contained in:
kenkeiras 2017-10-30 22:34:58 +01:00
parent 8773f46b60
commit f63854c863
2 changed files with 17 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import com.codigoparallevar.minicards.types.connectors.output.OutputConnector;
import com.codigoparallevar.minicards.types.connectors.output.SignalOutputConnector; import com.codigoparallevar.minicards.types.connectors.output.SignalOutputConnector;
import com.codigoparallevar.minicards.types.wireData.Signal; import com.codigoparallevar.minicards.types.wireData.Signal;
import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -20,6 +21,7 @@ public class RoundOutputConnector implements Drawable, SignalOutputConnector {
private final Part _part; private final Part _part;
private SignalWire _currentWire = null; private SignalWire _currentWire = null;
private final List<SignalWire> _wires; private final List<SignalWire> _wires;
private final HashSet<InputConnector> _connections;
public RoundOutputConnector(Part part, PartGrid partGrid, int centerX, int centerY, int radius) { public RoundOutputConnector(Part part, PartGrid partGrid, int centerX, int centerY, int radius) {
_part = part; _part = part;
@ -28,6 +30,7 @@ public class RoundOutputConnector implements Drawable, SignalOutputConnector {
_centerY = centerY; _centerY = centerY;
_radius = radius; _radius = radius;
_wires = new LinkedList<>(); _wires = new LinkedList<>();
_connections = new HashSet<>();
} }
@Override @Override
@ -61,10 +64,17 @@ public class RoundOutputConnector implements Drawable, SignalOutputConnector {
Log.d("RoundOutputConnector", "Dropped wire on " + resultPoint); Log.d("RoundOutputConnector", "Dropped wire on " + resultPoint);
// Not connected
if (resultPoint == null){ if (resultPoint == null){
return; return;
} }
// Already connected
if (_connections.contains(resultPoint)) {
return;
}
_connections.add(resultPoint);
wire.attachTo(resultPoint); wire.attachTo(resultPoint);
_wires.add(wire); _wires.add(wire);
} }
@ -111,6 +121,12 @@ public class RoundOutputConnector implements Drawable, SignalOutputConnector {
@Override @Override
public void connectTo(SignalInputConnector inputConnector) { public void connectTo(SignalInputConnector inputConnector) {
if (_connections.contains(inputConnector)) {
return;
}
_connections.add(inputConnector);
SignalWire wire = new SignalWire(this, _centerX, _centerY); SignalWire wire = new SignalWire(this, _centerX, _centerY);
wire.attachTo(inputConnector); wire.attachTo(inputConnector);
_wires.add(wire); _wires.add(wire);

View File

@ -7,7 +7,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha5' classpath 'com.android.tools.build:gradle:3.0.0-beta2'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong