Implement usage of save_to field.
This commit is contained in:
parent
948a04c78f
commit
a2bcf79309
@ -400,11 +400,9 @@ public class CanvasView extends View implements PartGrid {
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public BooleanInputConnector getBooleanInputConnectorOn(int x, int y) {
|
public BooleanInputConnector getBooleanInputConnectorOn(int x, int y) {
|
||||||
// If no part was found, do the same for connectors
|
|
||||||
for (int i = parts.size() - 1; i >= 0; i--){
|
for (int i = parts.size() - 1; i >= 0; i--){
|
||||||
final Part part = parts.get(i);
|
final Part part = parts.get(i);
|
||||||
|
|
||||||
// Then with input ones
|
|
||||||
for (InputConnector inputConnector : part.getInputConnectors()){
|
for (InputConnector inputConnector : part.getInputConnectors()){
|
||||||
BooleanInputConnector booleanInputConnector;
|
BooleanInputConnector booleanInputConnector;
|
||||||
if (inputConnector instanceof BooleanInputConnector){
|
if (inputConnector instanceof BooleanInputConnector){
|
||||||
@ -426,6 +424,25 @@ public class CanvasView extends View implements PartGrid {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AnyInputConnector getAnyInputConnectorOn(int x, int y) {
|
||||||
|
for (int i = parts.size() - 1; i >= 0; i--){
|
||||||
|
final Part part = parts.get(i);
|
||||||
|
|
||||||
|
for (InputConnector inputConnector : part.getInputConnectors()){
|
||||||
|
if (!(inputConnector instanceof AnyInputConnector)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputConnector.containsPoint(x, y)){
|
||||||
|
return (AnyInputConnector) inputConnector;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public StringInputConnector getStringInputConnectorOn(int x, int y) {
|
public StringInputConnector getStringInputConnectorOn(int x, int y) {
|
||||||
|
@ -58,9 +58,10 @@ public class SignalListenerManager implements ProgramakerSignalListener {
|
|||||||
remainingListeners.remove(listener);
|
remainingListeners.remove(listener);
|
||||||
if (remainingListeners.size() == 0) {
|
if (remainingListeners.size() == 0) {
|
||||||
ProgramakerListeningChannel channel = idToChannel.get(id);
|
ProgramakerListeningChannel channel = idToChannel.get(id);
|
||||||
channel.stop();
|
|
||||||
idToChannel.remove(id);
|
idToChannel.remove(id);
|
||||||
channelToListener.remove(id);
|
channelToListener.remove(id);
|
||||||
|
|
||||||
|
channel.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,6 +70,15 @@ public class SignalListenerManager implements ProgramakerSignalListener {
|
|||||||
Log.w(LogTag, "Connection lost to (bridge="+bridgeId+",key="+key + ")");
|
Log.w(LogTag, "Connection lost to (bridge="+bridgeId+",key="+key + ")");
|
||||||
Tuple2<String, String> id = new Tuple2<>(bridgeId, key);
|
Tuple2<String, String> id = new Tuple2<>(bridgeId, key);
|
||||||
|
|
||||||
|
// Check that there is still someone listening
|
||||||
|
if (!this.channelToListener.containsKey(id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.channelToListener.get(id).size() == 0) {
|
||||||
|
this.channelToListener.remove(id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// On disconnect disable the connection, wait 2 seconds and retry
|
// On disconnect disable the connection, wait 2 seconds and retry
|
||||||
idToChannel.put(id, null);
|
idToChannel.put(id, null);
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package com.codigoparallevar.minicards;
|
|||||||
|
|
||||||
import com.codigoparallevar.minicards.types.PartGrid;
|
import com.codigoparallevar.minicards.types.PartGrid;
|
||||||
import com.codigoparallevar.minicards.types.Selectable;
|
import com.codigoparallevar.minicards.types.Selectable;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.input.AnyInputConnector;
|
||||||
import com.codigoparallevar.minicards.types.functional.Tuple2;
|
import com.codigoparallevar.minicards.types.functional.Tuple2;
|
||||||
import com.codigoparallevar.minicards.types.connectors.input.BooleanInputConnector;
|
import com.codigoparallevar.minicards.types.connectors.input.BooleanInputConnector;
|
||||||
import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector;
|
import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector;
|
||||||
@ -34,6 +35,16 @@ class StubPartGrid implements PartGrid {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AnyInputConnector getAnyInputConnectorOn(int x, int y) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StringInputConnector getStringInputConnectorOn(int xEnd, int yEnd) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tuple2<Integer, Integer> getCenteredOn() {
|
public Tuple2<Integer, Integer> getCenteredOn() {
|
||||||
return null;
|
return null;
|
||||||
@ -43,8 +54,4 @@ class StubPartGrid implements PartGrid {
|
|||||||
public void update() {
|
public void update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public StringInputConnector getStringInputConnectorOn(int xEnd, int yEnd) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,10 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.codigoparallevar.minicards.ScrolledCanvas;
|
import com.codigoparallevar.minicards.ScrolledCanvas;
|
||||||
import com.codigoparallevar.minicards.parts.connectors.AnyRoundInputConnector;
|
import com.codigoparallevar.minicards.parts.connectors.AnyRoundInputConnector;
|
||||||
|
import com.codigoparallevar.minicards.parts.connectors.AnyRoundOutputConnector;
|
||||||
import com.codigoparallevar.minicards.parts.connectors.ConnectorTypeInfo;
|
import com.codigoparallevar.minicards.parts.connectors.ConnectorTypeInfo;
|
||||||
import com.codigoparallevar.minicards.parts.connectors.RoundOutputConnector;
|
import com.codigoparallevar.minicards.parts.connectors.RoundOutputConnector;
|
||||||
|
import com.codigoparallevar.minicards.parts.connectors.SignalRoundOutputConnector;
|
||||||
import com.codigoparallevar.minicards.types.Moveable;
|
import com.codigoparallevar.minicards.types.Moveable;
|
||||||
import com.codigoparallevar.minicards.types.Part;
|
import com.codigoparallevar.minicards.types.Part;
|
||||||
import com.codigoparallevar.minicards.types.PartConnection;
|
import com.codigoparallevar.minicards.types.PartConnection;
|
||||||
@ -17,6 +19,7 @@ import com.codigoparallevar.minicards.types.PartGrid;
|
|||||||
import com.codigoparallevar.minicards.types.connectors.input.InputConnector;
|
import com.codigoparallevar.minicards.types.connectors.input.InputConnector;
|
||||||
import com.codigoparallevar.minicards.types.connectors.output.OutputConnector;
|
import com.codigoparallevar.minicards.types.connectors.output.OutputConnector;
|
||||||
import com.codigoparallevar.minicards.types.functional.Tuple2;
|
import com.codigoparallevar.minicards.types.functional.Tuple2;
|
||||||
|
import com.codigoparallevar.minicards.types.wireData.AnySignal;
|
||||||
import com.codigoparallevar.minicards.types.wireData.Signal;
|
import com.codigoparallevar.minicards.types.wireData.Signal;
|
||||||
import com.codigoparallevar.minicards.types.wireData.WireDataType;
|
import com.codigoparallevar.minicards.types.wireData.WireDataType;
|
||||||
import com.codigoparallevar.minicards.ui_helpers.DoAsync;
|
import com.codigoparallevar.minicards.ui_helpers.DoAsync;
|
||||||
@ -59,8 +62,8 @@ public class ProgramakerCustomBlockPart implements Part, ProgramakerSignalListen
|
|||||||
private String token = null;
|
private String token = null;
|
||||||
private Object[] lastValues;
|
private Object[] lastValues;
|
||||||
private boolean active = true;
|
private boolean active = true;
|
||||||
private Tuple2<ConnectorTypeInfo, RoundOutputConnector> saveToOutput;
|
private Tuple2<ConnectorTypeInfo, AnyRoundOutputConnector> saveToOutput;
|
||||||
private RoundOutputConnector pulseOutput;
|
private SignalRoundOutputConnector pulseOutput;
|
||||||
|
|
||||||
public ProgramakerCustomBlockPart(String id, PartGrid grid, Tuple2<Integer, Integer> center, ProgramakerCustomBlock block) {
|
public ProgramakerCustomBlockPart(String id, PartGrid grid, Tuple2<Integer, Integer> center, ProgramakerCustomBlock block) {
|
||||||
this._id = id;
|
this._id = id;
|
||||||
@ -141,7 +144,7 @@ public class ProgramakerCustomBlockPart implements Part, ProgramakerSignalListen
|
|||||||
final List<Tuple2<ConnectorTypeInfo, AnyRoundInputConnector>> inputs = new LinkedList<>();
|
final List<Tuple2<ConnectorTypeInfo, AnyRoundInputConnector>> inputs = new LinkedList<>();
|
||||||
final List<Tuple2<ConnectorTypeInfo, RoundOutputConnector>> outputs = new LinkedList<>();
|
final List<Tuple2<ConnectorTypeInfo, RoundOutputConnector>> outputs = new LinkedList<>();
|
||||||
|
|
||||||
RoundOutputConnector pulseOutput = null;
|
SignalRoundOutputConnector pulseOutput = null;
|
||||||
|
|
||||||
// Add pulses
|
// Add pulses
|
||||||
if (has_pulse_input) {
|
if (has_pulse_input) {
|
||||||
@ -151,7 +154,7 @@ public class ProgramakerCustomBlockPart implements Part, ProgramakerSignalListen
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (has_pulse_output) {
|
if (has_pulse_output) {
|
||||||
pulseOutput = new RoundOutputConnector(this, this._partGrid, 0, 0,
|
pulseOutput = new SignalRoundOutputConnector(this, this._partGrid, 0, 0,
|
||||||
IO_RADIUS);
|
IO_RADIUS);
|
||||||
outputs.add(new Tuple2<>(new ConnectorTypeInfo(ConnectorTypeInfo.Type.PULSE),
|
outputs.add(new Tuple2<>(new ConnectorTypeInfo(ConnectorTypeInfo.Type.PULSE),
|
||||||
pulseOutput)
|
pulseOutput)
|
||||||
@ -188,17 +191,17 @@ public class ProgramakerCustomBlockPart implements Part, ProgramakerSignalListen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Tuple2<ConnectorTypeInfo, RoundOutputConnector> saveToOutput = null;
|
Tuple2<ConnectorTypeInfo, AnyRoundOutputConnector> saveToOutput = null;
|
||||||
|
|
||||||
if (savedTo != null) {
|
if (savedTo != null) {
|
||||||
saveToOutput = new Tuple2<>(ConnectorTypeInfo.FromTypeName(savedTo.getType()),
|
saveToOutput = new Tuple2<>(ConnectorTypeInfo.FromTypeName(savedTo.getType()),
|
||||||
new RoundOutputConnector(this, this._partGrid, 0, 0, IO_RADIUS));
|
new AnyRoundOutputConnector(this, this._partGrid, 0, 0, IO_RADIUS));
|
||||||
outputs.add(saveToOutput);
|
outputs.add(new Tuple2<>(saveToOutput.item1, saveToOutput.item2));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasImplicitOutput) {
|
if (hasImplicitOutput) {
|
||||||
outputs.add(new Tuple2<>(ConnectorTypeInfo.FromTypeName(_block.getBlock_result_type()),
|
outputs.add(new Tuple2<>(ConnectorTypeInfo.FromTypeName(_block.getBlock_result_type()),
|
||||||
new RoundOutputConnector(this, this._partGrid, 0, 0, IO_RADIUS)));
|
new AnyRoundOutputConnector(this, this._partGrid, 0, 0, IO_RADIUS)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tie everything
|
// Tie everything
|
||||||
@ -410,13 +413,16 @@ public class ProgramakerCustomBlockPart implements Part, ProgramakerSignalListen
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onExecutionCompleted(ProgramakerFunctionCallResult result) {
|
private void onExecutionCompleted(ProgramakerFunctionCallResult result) {
|
||||||
Tuple2<ConnectorTypeInfo, RoundOutputConnector> savedTo = this.saveToOutput;
|
Tuple2<ConnectorTypeInfo, AnyRoundOutputConnector> savedTo = this.saveToOutput;
|
||||||
if (savedTo != null) {
|
if (savedTo != null) {
|
||||||
// TODO: Fix output typing
|
Object value = null;
|
||||||
// savedTo.item2.send((WireDataType<Object>) () -> result.getResult());
|
if (result != null) {
|
||||||
|
result.getResult();
|
||||||
|
}
|
||||||
|
savedTo.item2.send(new AnySignal(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
RoundOutputConnector pulseOutput = this.pulseOutput;
|
SignalRoundOutputConnector pulseOutput = this.pulseOutput;
|
||||||
if (pulseOutput != null) {
|
if (pulseOutput != null) {
|
||||||
pulseOutput.send(new Signal());
|
pulseOutput.send(new Signal());
|
||||||
}
|
}
|
||||||
@ -537,7 +543,7 @@ public class ProgramakerCustomBlockPart implements Part, ProgramakerSignalListen
|
|||||||
// Stream object on save_to, then trigger pulse
|
// Stream object on save_to, then trigger pulse
|
||||||
Object content = signal.get("content");
|
Object content = signal.get("content");
|
||||||
if (this.saveToOutput != null) {
|
if (this.saveToOutput != null) {
|
||||||
// this.saveToOutput.item2.send(content); // TODO: Have an output type that allows this
|
this.saveToOutput.item2.send(new AnySignal(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.pulseOutput != null) {
|
if (this.pulseOutput != null) {
|
||||||
|
@ -6,7 +6,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.codigoparallevar.minicards.PartInstantiator;
|
import com.codigoparallevar.minicards.PartInstantiator;
|
||||||
import com.codigoparallevar.minicards.ScrolledCanvas;
|
import com.codigoparallevar.minicards.ScrolledCanvas;
|
||||||
import com.codigoparallevar.minicards.parts.connectors.RoundOutputConnector;
|
import com.codigoparallevar.minicards.parts.connectors.SignalRoundOutputConnector;
|
||||||
import com.codigoparallevar.minicards.parts.style.CardTheme;
|
import com.codigoparallevar.minicards.parts.style.CardTheme;
|
||||||
import com.codigoparallevar.minicards.types.Moveable;
|
import com.codigoparallevar.minicards.types.Moveable;
|
||||||
import com.codigoparallevar.minicards.types.Part;
|
import com.codigoparallevar.minicards.types.Part;
|
||||||
@ -39,7 +39,7 @@ public class RoundButton implements Part {
|
|||||||
private final int _outerRadiusThickness = 10;
|
private final int _outerRadiusThickness = 10;
|
||||||
private final int _pathRunWay = 200;
|
private final int _pathRunWay = 200;
|
||||||
private List<OutputConnector> _outputConnectors;
|
private List<OutputConnector> _outputConnectors;
|
||||||
private final RoundOutputConnector _pressedOutputConnector;
|
private final SignalRoundOutputConnector _pressedOutputConnector;
|
||||||
private final static int DEFAULT_INNER_RADIUS = 80;
|
private final static int DEFAULT_INNER_RADIUS = 80;
|
||||||
private final static int DEFAULT_OUTER_RADIUS = 100;
|
private final static int DEFAULT_OUTER_RADIUS = 100;
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ public class RoundButton implements Part {
|
|||||||
_outerRadius = outerRadius;
|
_outerRadius = outerRadius;
|
||||||
|
|
||||||
// Create connectors
|
// Create connectors
|
||||||
_pressedOutputConnector = new RoundOutputConnector(
|
_pressedOutputConnector = new SignalRoundOutputConnector(
|
||||||
this,
|
this,
|
||||||
_partGrid,
|
_partGrid,
|
||||||
getOutputConnectorCenterX(), getOutputConnectorCenterY(),
|
getOutputConnectorCenterX(), getOutputConnectorCenterY(),
|
||||||
@ -234,7 +234,7 @@ public class RoundButton implements Part {
|
|||||||
return null; // Only pulse output, so no relevant data
|
return null; // Only pulse output, so no relevant data
|
||||||
}
|
}
|
||||||
|
|
||||||
public RoundOutputConnector getPressedOutputConnector(){
|
public SignalRoundOutputConnector getPressedOutputConnector(){
|
||||||
return _pressedOutputConnector;
|
return _pressedOutputConnector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,14 +4,15 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.codigoparallevar.minicards.types.Moveable;
|
import com.codigoparallevar.minicards.types.Moveable;
|
||||||
import com.codigoparallevar.minicards.types.Part;
|
import com.codigoparallevar.minicards.types.Part;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.RoundConnector;
|
||||||
import com.codigoparallevar.minicards.types.connectors.Wiring.Wire;
|
import com.codigoparallevar.minicards.types.connectors.Wiring.Wire;
|
||||||
import com.codigoparallevar.minicards.types.connectors.input.AnyInputConnector;
|
import com.codigoparallevar.minicards.types.connectors.input.AnyInputConnector;
|
||||||
import com.codigoparallevar.minicards.types.wireData.WireDataType;
|
import com.codigoparallevar.minicards.types.wireData.AnySignal;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AnyRoundInputConnector extends AnyInputConnector {
|
public class AnyRoundInputConnector extends AnyInputConnector implements RoundConnector {
|
||||||
private final Part _part;
|
private final Part _part;
|
||||||
private int _xposition;
|
private int _xposition;
|
||||||
private int _yposition;
|
private int _yposition;
|
||||||
@ -81,7 +82,7 @@ public class AnyRoundInputConnector extends AnyInputConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(WireDataType signal) {
|
public void send(AnySignal signal) {
|
||||||
_part.send(this, signal);
|
_part.send(this, signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,176 @@
|
|||||||
|
package com.codigoparallevar.minicards.parts.connectors;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.codigoparallevar.minicards.ScrolledCanvas;
|
||||||
|
import com.codigoparallevar.minicards.types.Drawable;
|
||||||
|
import com.codigoparallevar.minicards.types.Moveable;
|
||||||
|
import com.codigoparallevar.minicards.types.Part;
|
||||||
|
import com.codigoparallevar.minicards.types.PartGrid;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.Wiring.AnyWire;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.input.AnyInputConnector;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.input.InputConnector;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.output.AnyOutputConnector;
|
||||||
|
import com.codigoparallevar.minicards.types.functional.Tuple2;
|
||||||
|
import com.codigoparallevar.minicards.types.wireData.AnySignal;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AnyRoundOutputConnector implements Drawable, AnyOutputConnector,
|
||||||
|
RoundOutputConnector<AnySignal, AnyInputConnector, AnyWire> {
|
||||||
|
private PartGrid _partGrid;
|
||||||
|
private int _centerX;
|
||||||
|
private int _centerY;
|
||||||
|
private final int _radius;
|
||||||
|
private final Part _part;
|
||||||
|
private AnyWire _currentWire = null;
|
||||||
|
private final List<AnyWire> _wires;
|
||||||
|
private final HashSet<InputConnector> _connections;
|
||||||
|
|
||||||
|
public AnyRoundOutputConnector(Part part, PartGrid partGrid, int centerX, int centerY, int radius) {
|
||||||
|
_part = part;
|
||||||
|
_partGrid = partGrid;
|
||||||
|
_centerX = centerX;
|
||||||
|
_centerY = centerY;
|
||||||
|
_radius = radius;
|
||||||
|
_wires = new LinkedList<>();
|
||||||
|
_connections = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsPoint(int x, int y) {
|
||||||
|
return ((Math.abs(x - _centerX) <= _radius)
|
||||||
|
&& (Math.abs(y - _centerY) <= _radius));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Moveable getMoveable() {
|
||||||
|
if (_currentWire == null) {
|
||||||
|
startWire();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _currentWire;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlink() {}
|
||||||
|
|
||||||
|
private void startWire() {
|
||||||
|
_currentWire = new AnyWire(this, _centerX, _centerY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drop(AnyWire wire) {
|
||||||
|
|
||||||
|
if (wire == _currentWire){
|
||||||
|
_currentWire = null;
|
||||||
|
|
||||||
|
AnyInputConnector resultPoint = _partGrid.getAnyInputConnectorOn(
|
||||||
|
wire.getXEnd(), wire.getYEnd());
|
||||||
|
|
||||||
|
Log.d("RoundOutputConnector", "Dropped wire on " + resultPoint);
|
||||||
|
|
||||||
|
// Not connected
|
||||||
|
if (resultPoint == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Already connected
|
||||||
|
if (_connections.contains(resultPoint)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_connections.add(resultPoint);
|
||||||
|
|
||||||
|
wire.attachTo(resultPoint, this);
|
||||||
|
_wires.add(wire);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log.w("RoundOutputConnector",
|
||||||
|
"Asked to drop non matching wire "
|
||||||
|
+ "(expected " + _currentWire + ", got " + wire + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlinkWire(AnyWire wire) {
|
||||||
|
_wires.remove(wire);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawWires(ScrolledCanvas canvas, boolean devMode) {
|
||||||
|
for (AnyWire wire : _wires) {
|
||||||
|
wire.draw(canvas, devMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_currentWire != null) {
|
||||||
|
_currentWire.draw(canvas, devMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePosition(int x, int y) {
|
||||||
|
_centerX = x;
|
||||||
|
_centerY = y;
|
||||||
|
|
||||||
|
for (AnyWire wire : _wires){
|
||||||
|
wire.moveStart(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Tuple2<String, String>> getConnectionEndpoints() {
|
||||||
|
List<Tuple2<String, String>> endpointIds = new LinkedList<>();
|
||||||
|
|
||||||
|
for (AnyWire wire : _wires) {
|
||||||
|
InputConnector inputConnector = wire.getAttachedTo();
|
||||||
|
Part endPart = inputConnector.getPart();
|
||||||
|
endpointIds.add(new Tuple2<>(inputConnector.getId(), endPart.get_id()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return endpointIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connectTo(AnyInputConnector inputConnector) {
|
||||||
|
if (_connections.contains(inputConnector)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_connections.add(inputConnector);
|
||||||
|
|
||||||
|
AnyWire wire = new AnyWire(this, _centerX, _centerY);
|
||||||
|
wire.attachTo(inputConnector, this);
|
||||||
|
_wires.add(wire);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(ScrolledCanvas canvas, boolean devMode) {
|
||||||
|
// TODO: Complete this part
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(AnySignal signal) {
|
||||||
|
for (AnyWire wire : _wires){
|
||||||
|
wire.send(signal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object query(Object lastValue) {
|
||||||
|
return _part.query(lastValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return _centerX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return _centerY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getRadius() {
|
||||||
|
return _radius;
|
||||||
|
}
|
||||||
|
}
|
@ -7,11 +7,11 @@ import com.codigoparallevar.minicards.types.Drawable;
|
|||||||
import com.codigoparallevar.minicards.types.Moveable;
|
import com.codigoparallevar.minicards.types.Moveable;
|
||||||
import com.codigoparallevar.minicards.types.Part;
|
import com.codigoparallevar.minicards.types.Part;
|
||||||
import com.codigoparallevar.minicards.types.PartGrid;
|
import com.codigoparallevar.minicards.types.PartGrid;
|
||||||
import com.codigoparallevar.minicards.types.functional.Tuple2;
|
|
||||||
import com.codigoparallevar.minicards.types.connectors.Wiring.BooleanWire;
|
import com.codigoparallevar.minicards.types.connectors.Wiring.BooleanWire;
|
||||||
import com.codigoparallevar.minicards.types.connectors.input.BooleanInputConnector;
|
import com.codigoparallevar.minicards.types.connectors.input.BooleanInputConnector;
|
||||||
import com.codigoparallevar.minicards.types.connectors.input.InputConnector;
|
import com.codigoparallevar.minicards.types.connectors.input.InputConnector;
|
||||||
import com.codigoparallevar.minicards.types.connectors.output.BooleanOutputConnector;
|
import com.codigoparallevar.minicards.types.connectors.output.BooleanOutputConnector;
|
||||||
|
import com.codigoparallevar.minicards.types.functional.Tuple2;
|
||||||
import com.codigoparallevar.minicards.types.wireData.BooleanSignal;
|
import com.codigoparallevar.minicards.types.wireData.BooleanSignal;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -1,175 +1,14 @@
|
|||||||
package com.codigoparallevar.minicards.parts.connectors;
|
package com.codigoparallevar.minicards.parts.connectors;
|
||||||
|
|
||||||
import android.util.Log;
|
import com.codigoparallevar.minicards.types.connectors.RoundConnector;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.Wiring.Wire;
|
||||||
import com.codigoparallevar.minicards.ScrolledCanvas;
|
|
||||||
import com.codigoparallevar.minicards.types.Drawable;
|
|
||||||
import com.codigoparallevar.minicards.types.Moveable;
|
|
||||||
import com.codigoparallevar.minicards.types.Part;
|
|
||||||
import com.codigoparallevar.minicards.types.PartGrid;
|
|
||||||
import com.codigoparallevar.minicards.types.functional.Tuple2;
|
|
||||||
import com.codigoparallevar.minicards.types.connectors.Wiring.SignalWire;
|
|
||||||
import com.codigoparallevar.minicards.types.connectors.input.InputConnector;
|
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.WireDataType;
|
||||||
import com.codigoparallevar.minicards.types.wireData.Signal;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
public interface RoundOutputConnector<
|
||||||
import java.util.LinkedList;
|
T1 extends WireDataType,
|
||||||
import java.util.List;
|
T2 extends InputConnector<T1, T2>,
|
||||||
|
T3 extends Wire<T1, T2>
|
||||||
public class RoundOutputConnector implements Drawable, SignalOutputConnector {
|
> extends RoundConnector, OutputConnector<T1, T2, T3> {
|
||||||
private PartGrid _partGrid;
|
|
||||||
private int _centerX;
|
|
||||||
private int _centerY;
|
|
||||||
private final int _radius;
|
|
||||||
private final Part _part;
|
|
||||||
private SignalWire _currentWire = null;
|
|
||||||
private final List<SignalWire> _wires;
|
|
||||||
private final HashSet<InputConnector> _connections;
|
|
||||||
|
|
||||||
public RoundOutputConnector(Part part, PartGrid partGrid, int centerX, int centerY, int radius) {
|
|
||||||
_part = part;
|
|
||||||
_partGrid = partGrid;
|
|
||||||
_centerX = centerX;
|
|
||||||
_centerY = centerY;
|
|
||||||
_radius = radius;
|
|
||||||
_wires = new LinkedList<>();
|
|
||||||
_connections = new HashSet<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean containsPoint(int x, int y) {
|
|
||||||
return ((Math.abs(x - _centerX) <= _radius)
|
|
||||||
&& (Math.abs(y - _centerY) <= _radius));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Moveable getMoveable() {
|
|
||||||
if (_currentWire == null) {
|
|
||||||
startWire();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _currentWire;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unlink() {}
|
|
||||||
|
|
||||||
private void startWire() {
|
|
||||||
_currentWire = new SignalWire(this, _centerX, _centerY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drop(SignalWire wire) {
|
|
||||||
|
|
||||||
if (wire == _currentWire){
|
|
||||||
_currentWire = null;
|
|
||||||
|
|
||||||
SignalInputConnector resultPoint = _partGrid.getSignalInputConnectorOn(
|
|
||||||
wire.getXEnd(), wire.getYEnd());
|
|
||||||
|
|
||||||
Log.d("RoundOutputConnector", "Dropped wire on " + resultPoint);
|
|
||||||
|
|
||||||
// Not connected
|
|
||||||
if (resultPoint == null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Already connected
|
|
||||||
if (_connections.contains(resultPoint)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_connections.add(resultPoint);
|
|
||||||
|
|
||||||
wire.attachTo(resultPoint, this);
|
|
||||||
_wires.add(wire);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Log.w("RoundOutputConnector",
|
|
||||||
"Asked to drop non matching wire "
|
|
||||||
+ "(expected " + _currentWire + ", got " + wire + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unlinkWire(SignalWire wire) {
|
|
||||||
_wires.remove(wire);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drawWires(ScrolledCanvas canvas, boolean devMode) {
|
|
||||||
for (SignalWire wire : _wires) {
|
|
||||||
wire.draw(canvas, devMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_currentWire != null) {
|
|
||||||
_currentWire.draw(canvas, devMode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updatePosition(int x, int y) {
|
|
||||||
_centerX = x;
|
|
||||||
_centerY = y;
|
|
||||||
|
|
||||||
for (SignalWire wire : _wires){
|
|
||||||
wire.moveStart(x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Tuple2<String, String>> getConnectionEndpoints() {
|
|
||||||
List<Tuple2<String, String>> endpointIds = new LinkedList<>();
|
|
||||||
|
|
||||||
for (SignalWire wire : _wires) {
|
|
||||||
InputConnector inputConnector = wire.getAttachedTo();
|
|
||||||
Part endPart = inputConnector.getPart();
|
|
||||||
endpointIds.add(new Tuple2<>(inputConnector.getId(), endPart.get_id()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return endpointIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void connectTo(SignalInputConnector inputConnector) {
|
|
||||||
if (_connections.contains(inputConnector)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_connections.add(inputConnector);
|
|
||||||
|
|
||||||
SignalWire wire = new SignalWire(this, _centerX, _centerY);
|
|
||||||
wire.attachTo(inputConnector, this);
|
|
||||||
_wires.add(wire);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(ScrolledCanvas canvas, boolean devMode) {
|
|
||||||
// TODO: Complete this part
|
|
||||||
}
|
|
||||||
|
|
||||||
public void send(Signal signal) {
|
|
||||||
for (SignalWire wire : _wires){
|
|
||||||
wire.send(signal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object query(Object lastValue) {
|
|
||||||
return _part.query(lastValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getX() {
|
|
||||||
return _centerX;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getY() {
|
|
||||||
return _centerY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getRadius() {
|
|
||||||
return _radius;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,176 @@
|
|||||||
|
package com.codigoparallevar.minicards.parts.connectors;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.codigoparallevar.minicards.ScrolledCanvas;
|
||||||
|
import com.codigoparallevar.minicards.types.Drawable;
|
||||||
|
import com.codigoparallevar.minicards.types.Moveable;
|
||||||
|
import com.codigoparallevar.minicards.types.Part;
|
||||||
|
import com.codigoparallevar.minicards.types.PartGrid;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.Wiring.SignalWire;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.input.InputConnector;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.output.SignalOutputConnector;
|
||||||
|
import com.codigoparallevar.minicards.types.functional.Tuple2;
|
||||||
|
import com.codigoparallevar.minicards.types.wireData.Signal;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SignalRoundOutputConnector implements Drawable, SignalOutputConnector,
|
||||||
|
RoundOutputConnector<Signal, SignalInputConnector, SignalWire> {
|
||||||
|
private PartGrid _partGrid;
|
||||||
|
private int _centerX;
|
||||||
|
private int _centerY;
|
||||||
|
private final int _radius;
|
||||||
|
private final Part _part;
|
||||||
|
private SignalWire _currentWire = null;
|
||||||
|
private final List<SignalWire> _wires;
|
||||||
|
private final HashSet<InputConnector> _connections;
|
||||||
|
|
||||||
|
public SignalRoundOutputConnector(Part part, PartGrid partGrid, int centerX, int centerY, int radius) {
|
||||||
|
_part = part;
|
||||||
|
_partGrid = partGrid;
|
||||||
|
_centerX = centerX;
|
||||||
|
_centerY = centerY;
|
||||||
|
_radius = radius;
|
||||||
|
_wires = new LinkedList<>();
|
||||||
|
_connections = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsPoint(int x, int y) {
|
||||||
|
return ((Math.abs(x - _centerX) <= _radius)
|
||||||
|
&& (Math.abs(y - _centerY) <= _radius));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Moveable getMoveable() {
|
||||||
|
if (_currentWire == null) {
|
||||||
|
startWire();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _currentWire;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlink() {}
|
||||||
|
|
||||||
|
private void startWire() {
|
||||||
|
_currentWire = new SignalWire(this, _centerX, _centerY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drop(SignalWire wire) {
|
||||||
|
|
||||||
|
if (wire == _currentWire){
|
||||||
|
_currentWire = null;
|
||||||
|
|
||||||
|
SignalInputConnector resultPoint = _partGrid.getSignalInputConnectorOn(
|
||||||
|
wire.getXEnd(), wire.getYEnd());
|
||||||
|
|
||||||
|
Log.d("RoundOutputConnector", "Dropped wire on " + resultPoint);
|
||||||
|
|
||||||
|
// Not connected
|
||||||
|
if (resultPoint == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Already connected
|
||||||
|
if (_connections.contains(resultPoint)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_connections.add(resultPoint);
|
||||||
|
|
||||||
|
wire.attachTo(resultPoint, this);
|
||||||
|
_wires.add(wire);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log.w("RoundOutputConnector",
|
||||||
|
"Asked to drop non matching wire "
|
||||||
|
+ "(expected " + _currentWire + ", got " + wire + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlinkWire(SignalWire wire) {
|
||||||
|
_wires.remove(wire);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawWires(ScrolledCanvas canvas, boolean devMode) {
|
||||||
|
for (SignalWire wire : _wires) {
|
||||||
|
wire.draw(canvas, devMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_currentWire != null) {
|
||||||
|
_currentWire.draw(canvas, devMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePosition(int x, int y) {
|
||||||
|
_centerX = x;
|
||||||
|
_centerY = y;
|
||||||
|
|
||||||
|
for (SignalWire wire : _wires){
|
||||||
|
wire.moveStart(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Tuple2<String, String>> getConnectionEndpoints() {
|
||||||
|
List<Tuple2<String, String>> endpointIds = new LinkedList<>();
|
||||||
|
|
||||||
|
for (SignalWire wire : _wires) {
|
||||||
|
InputConnector inputConnector = wire.getAttachedTo();
|
||||||
|
Part endPart = inputConnector.getPart();
|
||||||
|
endpointIds.add(new Tuple2<>(inputConnector.getId(), endPart.get_id()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return endpointIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connectTo(SignalInputConnector inputConnector) {
|
||||||
|
if (_connections.contains(inputConnector)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_connections.add(inputConnector);
|
||||||
|
|
||||||
|
SignalWire wire = new SignalWire(this, _centerX, _centerY);
|
||||||
|
wire.attachTo(inputConnector, this);
|
||||||
|
_wires.add(wire);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(ScrolledCanvas canvas, boolean devMode) {
|
||||||
|
// TODO: Complete this part
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(Signal signal) {
|
||||||
|
for (SignalWire wire : _wires){
|
||||||
|
wire.send(signal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object query(Object lastValue) {
|
||||||
|
return _part.query(lastValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return _centerX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return _centerY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getRadius() {
|
||||||
|
return _radius;
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.codigoparallevar.minicards.PartInstantiator;
|
import com.codigoparallevar.minicards.PartInstantiator;
|
||||||
import com.codigoparallevar.minicards.ScrolledCanvas;
|
import com.codigoparallevar.minicards.ScrolledCanvas;
|
||||||
import com.codigoparallevar.minicards.parts.connectors.RoundOutputConnector;
|
import com.codigoparallevar.minicards.parts.connectors.SignalRoundOutputConnector;
|
||||||
import com.codigoparallevar.minicards.parts.style.CardTheme;
|
import com.codigoparallevar.minicards.parts.style.CardTheme;
|
||||||
import com.codigoparallevar.minicards.types.Moveable;
|
import com.codigoparallevar.minicards.types.Moveable;
|
||||||
import com.codigoparallevar.minicards.types.Part;
|
import com.codigoparallevar.minicards.types.Part;
|
||||||
@ -40,7 +40,7 @@ public class Ticker implements Part {
|
|||||||
private int _right;
|
private int _right;
|
||||||
private int _bottom;
|
private int _bottom;
|
||||||
private List<OutputConnector> _outputConnectors;
|
private List<OutputConnector> _outputConnectors;
|
||||||
private final RoundOutputConnector _signalOutputConnector;
|
private final SignalRoundOutputConnector _signalOutputConnector;
|
||||||
private final long SLEEP_TIME = 1000;
|
private final long SLEEP_TIME = 1000;
|
||||||
private Thread _thread = null;
|
private Thread _thread = null;
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ public class Ticker implements Part {
|
|||||||
_bottom = bottom;
|
_bottom = bottom;
|
||||||
|
|
||||||
// Create connectors
|
// Create connectors
|
||||||
_signalOutputConnector = new RoundOutputConnector(
|
_signalOutputConnector = new SignalRoundOutputConnector(
|
||||||
this,
|
this,
|
||||||
_partGrid,
|
_partGrid,
|
||||||
getOutputConnectorCenterX(), getOutputConnectorCenterY(),
|
getOutputConnectorCenterX(), getOutputConnectorCenterY(),
|
||||||
|
@ -257,7 +257,7 @@ public class ConvertToString implements Part {
|
|||||||
encoded = value.toString();
|
encoded = value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((_lastValue != null) && !_lastValue.equals(encoded)) {
|
if ((_lastValue == null) || !_lastValue.equals(encoded)) {
|
||||||
_lastValue = encoded;
|
_lastValue = encoded;
|
||||||
|
|
||||||
_stringOutputConnector.send(new StringSignal(encoded));
|
_stringOutputConnector.send(new StringSignal(encoded));
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.codigoparallevar.minicards.types;
|
package com.codigoparallevar.minicards.types;
|
||||||
|
|
||||||
import com.codigoparallevar.minicards.SignalListenerManager;
|
import com.codigoparallevar.minicards.SignalListenerManager;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.input.AnyInputConnector;
|
||||||
import com.codigoparallevar.minicards.types.connectors.input.BooleanInputConnector;
|
import com.codigoparallevar.minicards.types.connectors.input.BooleanInputConnector;
|
||||||
import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector;
|
import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector;
|
||||||
import com.codigoparallevar.minicards.types.connectors.input.StringInputConnector;
|
import com.codigoparallevar.minicards.types.connectors.input.StringInputConnector;
|
||||||
@ -14,10 +15,11 @@ public interface PartGrid {
|
|||||||
|
|
||||||
SignalInputConnector getSignalInputConnectorOn(int x, int y);
|
SignalInputConnector getSignalInputConnectorOn(int x, int y);
|
||||||
BooleanInputConnector getBooleanInputConnectorOn(int x, int y);
|
BooleanInputConnector getBooleanInputConnectorOn(int x, int y);
|
||||||
|
AnyInputConnector getAnyInputConnectorOn(int x, int y);
|
||||||
|
StringInputConnector getStringInputConnectorOn(int xEnd, int yEnd);
|
||||||
|
|
||||||
Tuple2<Integer,Integer> getCenteredOn();
|
Tuple2<Integer,Integer> getCenteredOn();
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
StringInputConnector getStringInputConnectorOn(int xEnd, int yEnd);
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.codigoparallevar.minicards.types.connectors;
|
||||||
|
|
||||||
|
public interface RoundConnector {
|
||||||
|
int getX();
|
||||||
|
int getY();
|
||||||
|
float getRadius();
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.codigoparallevar.minicards.types.connectors.Wiring;
|
||||||
|
|
||||||
|
import com.codigoparallevar.minicards.types.Drawable;
|
||||||
|
import com.codigoparallevar.minicards.types.Moveable;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.input.AnyInputConnector;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.output.OutputConnector;
|
||||||
|
import com.codigoparallevar.minicards.types.wireData.AnySignal;
|
||||||
|
|
||||||
|
public class AnyWire extends Wire<AnySignal, AnyInputConnector> implements Moveable, Drawable {
|
||||||
|
public AnyWire(OutputConnector dropper, int xInit, int yInit) {
|
||||||
|
super(dropper, xInit, yInit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(AnySignal signal) {
|
||||||
|
if (_attachedTo != null) {
|
||||||
|
_attachedTo.send(signal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,13 +9,13 @@ import com.codigoparallevar.minicards.types.connectors.output.BooleanOutputConne
|
|||||||
import com.codigoparallevar.minicards.types.connectors.output.OutputConnector;
|
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.connectors.output.StringOutputConnector;
|
import com.codigoparallevar.minicards.types.connectors.output.StringOutputConnector;
|
||||||
|
import com.codigoparallevar.minicards.types.wireData.AnySignal;
|
||||||
import com.codigoparallevar.minicards.types.wireData.BooleanSignal;
|
import com.codigoparallevar.minicards.types.wireData.BooleanSignal;
|
||||||
import com.codigoparallevar.minicards.types.wireData.Signal;
|
import com.codigoparallevar.minicards.types.wireData.Signal;
|
||||||
import com.codigoparallevar.minicards.types.wireData.StringSignal;
|
import com.codigoparallevar.minicards.types.wireData.StringSignal;
|
||||||
import com.codigoparallevar.minicards.types.wireData.WireDataType;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class AnyInputConnector implements InputConnector<WireDataType, AnyInputConnector> {
|
public abstract class AnyInputConnector implements InputConnector<AnySignal, AnyInputConnector> {
|
||||||
|
|
||||||
public SignalInputConnector ToSignalInputConnector() {
|
public SignalInputConnector ToSignalInputConnector() {
|
||||||
return new WrapAsSignal(this);
|
return new WrapAsSignal(this);
|
||||||
@ -51,7 +51,7 @@ public abstract class AnyInputConnector implements InputConnector<WireDataType,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(Signal data) {
|
public void send(Signal data) {
|
||||||
baseInputConnector.send(data);
|
baseInputConnector.send(new AnySignal(data.get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ public abstract class AnyInputConnector implements InputConnector<WireDataType,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(BooleanSignal data) {
|
public void send(BooleanSignal data) {
|
||||||
baseInputConnector.send(data);
|
baseInputConnector.send(new AnySignal(data.get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ public abstract class AnyInputConnector implements InputConnector<WireDataType,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(StringSignal data) {
|
public void send(StringSignal data) {
|
||||||
baseInputConnector.send(data);
|
baseInputConnector.send(new AnySignal(data.get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.codigoparallevar.minicards.types.connectors.output;
|
||||||
|
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.Wiring.AnyWire;
|
||||||
|
import com.codigoparallevar.minicards.types.connectors.input.AnyInputConnector;
|
||||||
|
import com.codigoparallevar.minicards.types.wireData.AnySignal;
|
||||||
|
|
||||||
|
public interface AnyOutputConnector extends OutputConnector<AnySignal, AnyInputConnector, AnyWire> {
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.codigoparallevar.minicards.types.wireData;
|
||||||
|
|
||||||
|
public class AnySignal implements WireDataType<Object> {
|
||||||
|
public final Object value;
|
||||||
|
|
||||||
|
public AnySignal(Object value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user