diff --git a/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java b/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java index 413f1e9..b50193c 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java +++ b/app/src/main/java/com/codigoparallevar/minicards/CanvasView.java @@ -16,8 +16,9 @@ import com.codigoparallevar.minicards.types.PartConnection; import com.codigoparallevar.minicards.parts.buttons.RoundButton; import com.codigoparallevar.minicards.parts.samples.ColorBox; import com.codigoparallevar.minicards.parts.samples.Placeholder; -import com.codigoparallevar.minicards.types.InputConnector; -import com.codigoparallevar.minicards.types.OutputConnector; +import com.codigoparallevar.minicards.types.connectors.input.InputConnector; +import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector; +import com.codigoparallevar.minicards.types.connectors.output.OutputConnector; import com.codigoparallevar.minicards.types.Part; import com.codigoparallevar.minicards.types.PartGrid; import com.codigoparallevar.minicards.types.Position; @@ -374,7 +375,7 @@ class CanvasView extends View implements PartGrid { } } // Then with input ones - for (InputConnector inputConnector : part.getInputConnectors()){ + for (InputConnector inputConnector : part.getSignalInputConnectors()){ if (inputConnector.containsPoint(x, y)){ return inputConnector; } @@ -386,13 +387,13 @@ class CanvasView extends View implements PartGrid { @Override @Nullable - public InputConnector getInputConnectorOn(int x, int y) { + public SignalInputConnector getSignalInputConnectorOn(int x, int y) { // If no part was found, do the same for connectors for (int i = parts.size() - 1; i >= 0; i--){ final Part part = parts.get(i); // Then with input ones - for (InputConnector inputConnector : part.getInputConnectors()){ + for (SignalInputConnector inputConnector : part.getSignalInputConnectors()){ if (inputConnector.containsPoint(x, y)){ return inputConnector; } diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/buttons/RoundButton.java b/app/src/main/java/com/codigoparallevar/minicards/parts/buttons/RoundButton.java index 0c8e957..6f2aac1 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/parts/buttons/RoundButton.java +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/buttons/RoundButton.java @@ -7,9 +7,10 @@ import android.util.Log; import com.codigoparallevar.minicards.types.PartConnection; import com.codigoparallevar.minicards.types.Tuple2; -import com.codigoparallevar.minicards.types.InputConnector; +import com.codigoparallevar.minicards.types.connectors.input.InputConnector; import com.codigoparallevar.minicards.types.Moveable; -import com.codigoparallevar.minicards.types.OutputConnector; +import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector; +import com.codigoparallevar.minicards.types.connectors.output.OutputConnector; import com.codigoparallevar.minicards.types.Part; import com.codigoparallevar.minicards.types.PartGrid; import com.codigoparallevar.minicards.types.RoundInputConnector; @@ -152,7 +153,7 @@ public class RoundButton implements Part { } @Override - public List getInputConnectors() { + public List getSignalInputConnectors() { return Collections.emptyList(); } diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/samples/ColorBox.java b/app/src/main/java/com/codigoparallevar/minicards/parts/samples/ColorBox.java index b294ca5..f86a775 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/parts/samples/ColorBox.java +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/samples/ColorBox.java @@ -6,9 +6,10 @@ import android.graphics.Paint; import android.graphics.Rect; import android.util.Log; -import com.codigoparallevar.minicards.types.InputConnector; +import com.codigoparallevar.minicards.types.connectors.input.InputConnector; import com.codigoparallevar.minicards.types.Moveable; -import com.codigoparallevar.minicards.types.OutputConnector; +import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector; +import com.codigoparallevar.minicards.types.connectors.output.OutputConnector; import com.codigoparallevar.minicards.types.Part; import com.codigoparallevar.minicards.types.PartGrid; import com.codigoparallevar.minicards.types.RoundInputConnector; @@ -30,8 +31,8 @@ public class ColorBox implements Part { private int _top; private int _right; private int _bottom; - private List inputConnectors; - private InputConnector _toggleInputConnector; + private List inputConnectors; + private SignalInputConnector _toggleInputConnector; private ColorBox(String id, PartGrid partGrid, int left, int top, int right, int bottom) { _id = id; @@ -135,7 +136,7 @@ public class ColorBox implements Part { } @Override - public List getInputConnectors() { + public List getSignalInputConnectors() { return inputConnectors; } diff --git a/app/src/main/java/com/codigoparallevar/minicards/parts/samples/Placeholder.java b/app/src/main/java/com/codigoparallevar/minicards/parts/samples/Placeholder.java index af6ebe1..6271fc2 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/parts/samples/Placeholder.java +++ b/app/src/main/java/com/codigoparallevar/minicards/parts/samples/Placeholder.java @@ -5,9 +5,10 @@ import android.graphics.Color; import android.graphics.Paint; import android.util.Log; -import com.codigoparallevar.minicards.types.InputConnector; +import com.codigoparallevar.minicards.types.connectors.input.InputConnector; import com.codigoparallevar.minicards.types.Moveable; -import com.codigoparallevar.minicards.types.OutputConnector; +import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector; +import com.codigoparallevar.minicards.types.connectors.output.OutputConnector; import com.codigoparallevar.minicards.types.Part; import com.codigoparallevar.minicards.types.PartGrid; import com.codigoparallevar.minicards.types.RoundInputConnector; @@ -102,7 +103,7 @@ public class Placeholder implements Part { } @Override - public List getInputConnectors() { + public List getSignalInputConnectors() { return Collections.emptyList(); } diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/Dropper.java b/app/src/main/java/com/codigoparallevar/minicards/types/Dropper.java index fedea4f..13b7139 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/types/Dropper.java +++ b/app/src/main/java/com/codigoparallevar/minicards/types/Dropper.java @@ -1,5 +1,5 @@ package com.codigoparallevar.minicards.types; -interface Dropper { - void drop(Wire wire); +public interface Dropper { + void drop(T wire); } diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/InputConnector.java b/app/src/main/java/com/codigoparallevar/minicards/types/InputConnector.java deleted file mode 100644 index a8f84e3..0000000 --- a/app/src/main/java/com/codigoparallevar/minicards/types/InputConnector.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.codigoparallevar.minicards.types; - -public interface InputConnector extends Selectable, Dropper { - void updatePosition(int x, int y); - - int getX(); - int getY(); - - void sendSignal(); - - void getAttachment(Wire wire); - - Part getPart(); - - String getId(); -} diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/OutputConnector.java b/app/src/main/java/com/codigoparallevar/minicards/types/OutputConnector.java deleted file mode 100644 index 814bff5..0000000 --- a/app/src/main/java/com/codigoparallevar/minicards/types/OutputConnector.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.codigoparallevar.minicards.types; - -import android.graphics.Canvas; - -import java.util.List; - -public interface OutputConnector extends Selectable, Dropper { - void drawWires(Canvas canvas, boolean devMode); - void updatePosition(int x, int y); - - List> getConnectionEndpoints(); - - void connectTo(InputConnector inputConnector); -} diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/Part.java b/app/src/main/java/com/codigoparallevar/minicards/types/Part.java index 05326e7..3dc11ae 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/types/Part.java +++ b/app/src/main/java/com/codigoparallevar/minicards/types/Part.java @@ -1,6 +1,8 @@ package com.codigoparallevar.minicards.types; -import android.graphics.Canvas; +import com.codigoparallevar.minicards.types.connectors.input.InputConnector; +import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector; +import com.codigoparallevar.minicards.types.connectors.output.OutputConnector; import org.json.JSONException; import org.json.JSONObject; @@ -15,7 +17,7 @@ public interface Part extends Selectable, Moveable, Drawable { void touched(); - List getInputConnectors(); + List getSignalInputConnectors(); List getOutputConnectors(); JSONObject serialize() throws JSONException; @@ -27,4 +29,5 @@ public interface Part extends Selectable, Moveable, Drawable { InputConnector getConnectorWithId(String inputConnectorId); String getConnectorId(InputConnector inputConnector); + } diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/PartConnection.java b/app/src/main/java/com/codigoparallevar/minicards/types/PartConnection.java index 176662c..a5bdbd4 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/types/PartConnection.java +++ b/app/src/main/java/com/codigoparallevar/minicards/types/PartConnection.java @@ -1,6 +1,6 @@ package com.codigoparallevar.minicards.types; -import com.codigoparallevar.minicards.parts.buttons.RoundButton; +import com.codigoparallevar.minicards.types.connectors.output.OutputConnector; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/PartGrid.java b/app/src/main/java/com/codigoparallevar/minicards/types/PartGrid.java index a63f19d..2502b0c 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/types/PartGrid.java +++ b/app/src/main/java/com/codigoparallevar/minicards/types/PartGrid.java @@ -1,7 +1,10 @@ package com.codigoparallevar.minicards.types; +import com.codigoparallevar.minicards.types.connectors.input.InputConnector; +import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector; + public interface PartGrid { Selectable getPartOn(int x, int y); - InputConnector getInputConnectorOn(int x, int y); + SignalInputConnector getSignalInputConnectorOn(int x, int y); } diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/RoundInputConnector.java b/app/src/main/java/com/codigoparallevar/minicards/types/RoundInputConnector.java index e34bc5b..6e976c7 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/types/RoundInputConnector.java +++ b/app/src/main/java/com/codigoparallevar/minicards/types/RoundInputConnector.java @@ -2,10 +2,13 @@ package com.codigoparallevar.minicards.types; import android.util.Log; +import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector; +import com.codigoparallevar.minicards.types.wireData.Signal; + import java.util.LinkedList; import java.util.List; -public class RoundInputConnector implements InputConnector { +public class RoundInputConnector implements SignalInputConnector { private final Part _part; private int _xposition; private int _yposition; @@ -57,8 +60,9 @@ public class RoundInputConnector implements InputConnector { _part.sendSignal(this); } + @Override - public void getAttachment(Wire wire) { + public void getAttachment(Wire wire) { _attachments.add(wire); } diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/RoundOutputConnector.java b/app/src/main/java/com/codigoparallevar/minicards/types/RoundOutputConnector.java index a5e7b66..b139d47 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/types/RoundOutputConnector.java +++ b/app/src/main/java/com/codigoparallevar/minicards/types/RoundOutputConnector.java @@ -3,17 +3,23 @@ package com.codigoparallevar.minicards.types; import android.graphics.Canvas; import android.util.Log; +import com.codigoparallevar.minicards.types.connectors.input.InputConnector; +import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector; +import com.codigoparallevar.minicards.types.connectors.output.OutputConnector; +import com.codigoparallevar.minicards.types.connectors.output.SignalOutputConnector; +import com.codigoparallevar.minicards.types.wireData.Signal; + import java.util.LinkedList; import java.util.List; -public class RoundOutputConnector implements OutputConnector, Drawable { +public class RoundOutputConnector implements Drawable, SignalOutputConnector { private PartGrid _partGrid; private int _centerX; private int _centerY; private final int _radius; private final Part _part; - private Wire _currentWire = null; - private final List _wires; + private SignalWire _currentWire = null; + private final List _wires; public RoundOutputConnector(Part part, PartGrid partGrid, int centerX, int centerY, int radius) { _part = part; @@ -41,15 +47,17 @@ public class RoundOutputConnector implements OutputConnector, Drawable { } private void startWire() { - _currentWire = new Wire(this, _centerX, _centerY); + _currentWire = new SignalWire(this, _centerX, _centerY); } @Override - public void drop(Wire wire) { + public void drop(SignalWire wire) { + if (wire == _currentWire){ _currentWire = null; - InputConnector resultPoint = _partGrid.getInputConnectorOn(wire.getXEnd(), wire.getYEnd()); + SignalInputConnector resultPoint = _partGrid.getSignalInputConnectorOn( + wire.getXEnd(), wire.getYEnd()); Log.d("RoundOutputConnector", "Dropped wire on " + resultPoint); @@ -69,7 +77,7 @@ public class RoundOutputConnector implements OutputConnector, Drawable { @Override public void drawWires(Canvas canvas, boolean devMode) { - for (Wire wire : _wires) { + for (SignalWire wire : _wires) { wire.draw(canvas, devMode); } @@ -83,7 +91,7 @@ public class RoundOutputConnector implements OutputConnector, Drawable { _centerX = x; _centerY = y; - for (Wire wire : _wires){ + for (SignalWire wire : _wires){ wire.moveStart(x, y); } } @@ -92,7 +100,7 @@ public class RoundOutputConnector implements OutputConnector, Drawable { public List> getConnectionEndpoints() { List> endpointIds = new LinkedList<>(); - for (Wire wire : _wires) { + for (SignalWire wire : _wires) { InputConnector inputConnector = wire.getAttachedTo(); Part endPart = inputConnector.getPart(); endpointIds.add(new Tuple2<>(inputConnector.getId(), endPart.getId())); @@ -102,8 +110,8 @@ public class RoundOutputConnector implements OutputConnector, Drawable { } @Override - public void connectTo(InputConnector inputConnector) { - Wire wire = new Wire(this, _centerX, _centerY); + public void connectTo(SignalInputConnector inputConnector) { + SignalWire wire = new SignalWire(this, _centerX, _centerY); wire.attachTo(inputConnector); _wires.add(wire); } @@ -114,7 +122,7 @@ public class RoundOutputConnector implements OutputConnector, Drawable { } public void sendSignal() { - for (Wire wire : _wires){ + for (SignalWire wire : _wires){ wire.sendSignal(); } } diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/SignalWire.java b/app/src/main/java/com/codigoparallevar/minicards/types/SignalWire.java new file mode 100644 index 0000000..17eb660 --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/types/SignalWire.java @@ -0,0 +1,16 @@ +package com.codigoparallevar.minicards.types; + +import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector; +import com.codigoparallevar.minicards.types.wireData.Signal; + +public class SignalWire extends Wire implements Moveable, Drawable { + public SignalWire(Dropper dropper, int xInit, int yInit) { + super(dropper, xInit, yInit); + } + + public void sendSignal() { + if (_attachedTo != null) { + _attachedTo.sendSignal(); + } + } +} diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/Wire.java b/app/src/main/java/com/codigoparallevar/minicards/types/Wire.java index 552d9c8..1531e47 100644 --- a/app/src/main/java/com/codigoparallevar/minicards/types/Wire.java +++ b/app/src/main/java/com/codigoparallevar/minicards/types/Wire.java @@ -5,17 +5,21 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; -public class Wire implements Moveable, Drawable { +import com.codigoparallevar.minicards.types.connectors.input.InputConnector; +import com.codigoparallevar.minicards.types.wireData.WireDataType; + +public class Wire> + implements Moveable, Drawable { + private final Dropper _dropper; private int _xinit; private int _yinit; private int _xend; private int _yend; private final static int _pathRunWay = 100; - private InputConnector _attachedTo = null; + protected InputConnectorType _attachedTo = null; public Wire(Dropper dropper, int xInit, int yInit) { - super(); _dropper = dropper; _xinit = xInit; _yinit = yInit; @@ -67,19 +71,13 @@ public class Wire implements Moveable, Drawable { return _yend; } - public void attachTo(InputConnector resultPoint) { + public void attachTo(InputConnectorType resultPoint) { _attachedTo = resultPoint; _xend = resultPoint.getX(); _yend = resultPoint.getY(); resultPoint.getAttachment(this); } - public void sendSignal() { - if (_attachedTo != null) { - _attachedTo.sendSignal(); - } - } - public InputConnector getAttachedTo() { return _attachedTo; } diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/connectors/input/InputConnector.java b/app/src/main/java/com/codigoparallevar/minicards/types/connectors/input/InputConnector.java new file mode 100644 index 0000000..7431fe0 --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/types/connectors/input/InputConnector.java @@ -0,0 +1,22 @@ +package com.codigoparallevar.minicards.types.connectors.input; + +import com.codigoparallevar.minicards.types.Dropper; +import com.codigoparallevar.minicards.types.Part; +import com.codigoparallevar.minicards.types.Selectable; +import com.codigoparallevar.minicards.types.Wire; +import com.codigoparallevar.minicards.types.wireData.WireDataType; + +public interface InputConnector> + extends Selectable, Dropper { + + void updatePosition(int x, int y); + + int getX(); + int getY(); + + void getAttachment(Wire wire); + + Part getPart(); + + String getId(); +} diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/connectors/input/SignalInputConnector.java b/app/src/main/java/com/codigoparallevar/minicards/types/connectors/input/SignalInputConnector.java new file mode 100644 index 0000000..9e32fa9 --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/types/connectors/input/SignalInputConnector.java @@ -0,0 +1,7 @@ +package com.codigoparallevar.minicards.types.connectors.input; + +import com.codigoparallevar.minicards.types.wireData.Signal; + +public interface SignalInputConnector extends InputConnector { + void sendSignal(); +} 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 new file mode 100644 index 0000000..56840cb --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/types/connectors/output/OutputConnector.java @@ -0,0 +1,25 @@ +package com.codigoparallevar.minicards.types.connectors.output; + +import android.graphics.Canvas; + +import com.codigoparallevar.minicards.types.Dropper; +import com.codigoparallevar.minicards.types.Selectable; +import com.codigoparallevar.minicards.types.Tuple2; +import com.codigoparallevar.minicards.types.Wire; +import com.codigoparallevar.minicards.types.connectors.input.InputConnector; +import com.codigoparallevar.minicards.types.wireData.WireDataType; + +import java.util.List; + +public interface OutputConnector, + T2 extends Wire> + extends Selectable, Dropper { + + void drawWires(Canvas canvas, boolean devMode); + void updatePosition(int x, int y); + + List> getConnectionEndpoints(); + + void connectTo(T1 inputConnector); +} diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/connectors/output/SignalOutputConnector.java b/app/src/main/java/com/codigoparallevar/minicards/types/connectors/output/SignalOutputConnector.java new file mode 100644 index 0000000..128a917 --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/types/connectors/output/SignalOutputConnector.java @@ -0,0 +1,9 @@ +package com.codigoparallevar.minicards.types.connectors.output; + +import com.codigoparallevar.minicards.types.SignalWire; +import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector; +import com.codigoparallevar.minicards.types.wireData.Signal; + +public interface SignalOutputConnector extends OutputConnector { + void sendSignal(); +} diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/wireData/Signal.java b/app/src/main/java/com/codigoparallevar/minicards/types/wireData/Signal.java new file mode 100644 index 0000000..0afe474 --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/types/wireData/Signal.java @@ -0,0 +1,4 @@ +package com.codigoparallevar.minicards.types.wireData; + +public class Signal implements WireDataType { +} diff --git a/app/src/main/java/com/codigoparallevar/minicards/types/wireData/WireDataType.java b/app/src/main/java/com/codigoparallevar/minicards/types/wireData/WireDataType.java new file mode 100644 index 0000000..6d073f8 --- /dev/null +++ b/app/src/main/java/com/codigoparallevar/minicards/types/wireData/WireDataType.java @@ -0,0 +1,4 @@ +package com.codigoparallevar.minicards.types.wireData; + +public interface WireDataType { +}