From af9352de42a6c63857362dc243547eb805d4ddae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Mon, 1 Jun 2020 16:49:38 +0200 Subject: [PATCH] Extend removal mechanism for all wires. --- .../minicards/CanvasView.java | 19 ++++++++----------- .../connectors/AnyRoundOutputConnector.java | 6 ++++++ .../BooleanRoundOutputConnector.java | 6 ++++++ .../StringRoundOutputConnector.java | 6 ++++++ .../connectors/output/OutputConnector.java | 2 ++ 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java b/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java index e09319c..499a14a 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java +++ b/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java @@ -368,17 +368,14 @@ public class CanvasView extends View implements PartGrid { List outputConnectors = part.getOutputConnectors(); if (outputConnectors != null) { for (OutputConnector outputConnector : outputConnectors) { - if (outputConnector instanceof SignalRoundOutputConnector) { - SignalRoundOutputConnector conn = (SignalRoundOutputConnector) outputConnector; - List wires = conn.getWires(); - if (wires == null) { - continue; - } - for (Wire wire : wires) { - if (wire.containsPoint(x, y)) { - Log.d(LogTag, "Point in wire " + wire); - return wire; - } + List wires = outputConnector.getWires(); + if (wires == null) { + continue; + } + for (Wire wire : wires) { + if (wire.containsPoint(x, y)) { + Log.d(LogTag, "Point in wire " + wire); + return wire; } } } diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/connectors/AnyRoundOutputConnector.java b/app/src/main/java/com/codigoparallevar/minicards/parts/connectors/AnyRoundOutputConnector.java index bae7fdc..e2b9431 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/parts/connectors/AnyRoundOutputConnector.java +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/connectors/AnyRoundOutputConnector.java @@ -97,6 +97,7 @@ public class AnyRoundOutputConnector implements Drawable, AnyOutputConnector, @Override public void unlinkWire(AnyWire wire) { _wires.remove(wire); + _connections.remove(wire.getAttachedTo()); } @Override @@ -162,6 +163,11 @@ public class AnyRoundOutputConnector implements Drawable, AnyOutputConnector, return _part.query(lastValue); } + @Override + public List getWires() { + return _wires; + } + public int getX() { return _centerX; } diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/connectors/BooleanRoundOutputConnector.java b/app/src/main/java/com/codigoparallevar/minicards/parts/connectors/BooleanRoundOutputConnector.java index f68b04f..3d96b7e 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/parts/connectors/BooleanRoundOutputConnector.java +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/connectors/BooleanRoundOutputConnector.java @@ -96,6 +96,7 @@ public class BooleanRoundOutputConnector implements Drawable, BooleanOutputConne @Override public void unlinkWire(BooleanWire wire) { _wires.remove(wire); + _connections.remove(wire.getAttachedTo()); } @Override @@ -160,4 +161,9 @@ public class BooleanRoundOutputConnector implements Drawable, BooleanOutputConne public Object query(Object lastValue) { return _part.query(lastValue); } + + @Override + public List getWires() { + return _wires; + } } diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/connectors/StringRoundOutputConnector.java b/app/src/main/java/com/codigoparallevar/minicards/parts/connectors/StringRoundOutputConnector.java index 1aa3232..264f4cd 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/parts/connectors/StringRoundOutputConnector.java +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/connectors/StringRoundOutputConnector.java @@ -96,6 +96,7 @@ public class StringRoundOutputConnector implements Drawable, StringOutputConnect @Override public void unlinkWire(StringWire wire) { _wires.remove(wire); + _connections.remove(wire.getAttachedTo()); } @Override @@ -160,4 +161,9 @@ public class StringRoundOutputConnector implements Drawable, StringOutputConnect public Object query(Object lastValue) { return _part.query(lastValue); } + + @Override + public List getWires() { + return _wires; + } } diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/connectors/output/OutputConnector.java b/app/src/main/java/com/codigoparallevar/minicards/types/connectors/output/OutputConnector.java index 8401363..c5811d5 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/types/connectors/output/OutputConnector.java +++ b/app/src/main/java/com/codigoparallevar/minicards/types/connectors/output/OutputConnector.java @@ -25,4 +25,6 @@ public interface OutputConnector getWires(); }