private static Position.Direction CharFits(char found, Position.Direction direction) { if (found == '+' || found == '#') { switch (direction) { case Position.Direction.North: return Position.Direction.East | Position.Direction.West | Position.Direction.North; case Position.Direction.East: return Position.Direction.North | Position.Direction.East | Position.Direction.South; case Position.Direction.South: return Position.Direction.East | Position.Direction.West | Position.Direction.South; case Position.Direction.West: return Position.Direction.West | Position.Direction.North | Position.Direction.South; default: return Position.Direction.None; } } if (found == '|') { switch (direction) { case Position.Direction.North: return Position.Direction.North; case Position.Direction.South: return Position.Direction.South; default: return Position.Direction.None; } } if (found == '-') { switch (direction) { case Position.Direction.East: return Position.Direction.East; case Position.Direction.West: return Position.Direction.West; default: return Position.Direction.None; } } if (found >= 'a' && found <= 'z') { return direction; } if (found >= '0' && found <= '9') { return direction; } return Position.Direction.None; }
/// <summary> /// Add a node to the flow. Nodes may only be included once per flow /// </summary> /// <param name="newNode"></param> public void AddNode(TaskNode newNode, Position position) { _nodes.Add(newNode); if(String.IsNullOrEmpty(newNode.Name )) newNode.Name = "node " + _nodes.Count.ToString(); newNode.OwningFlow = this; newNode.Position = position; }
private static List<PositionedConnection> FindConnectionJoin(Position p, char[,] artChars) { List<PositionedConnection> result = new List<PositionedConnection>(); ExtractConnectionEndFor(p, artChars, Position.Direction.North, 'V', result); ExtractConnectionEndFor(p, artChars, Position.Direction.South, '^', result); ExtractConnectionEndFor(p, artChars, Position.Direction.West, '>', result); ExtractConnectionEndFor(p, artChars, Position.Direction.East, '<', result); return result; }
public static IEnumerable<Position.Direction> GetContainedDirections(Position.Direction dir) { foreach (var possibleDir in Position.AllDirections) { if (possibleDir == Position.Direction.None) continue; if((dir & possibleDir) == possibleDir) yield return possibleDir; } }
private static void ExtractConnectionEndFor(Position pos, char[,] artChars, Position.Direction dir, char pointerSymbol, List<PositionedConnection> pointers) { int difX = (dir == Position.Direction.East ? 1 : (dir == Position.Direction.West ? -1 : 0)); int difY = (dir == Position.Direction.South ? 1 : (dir == Position.Direction.North ? -1 : 0)); pos.x += difX; pos.y += difY; if (pos.x < 0 || pos.y < 0 || pos.x >= artChars.GetLength(0) || pos.y >= artChars.GetLength(1)) { return; } if (artChars[pos.x, pos.y] == pointerSymbol) { PositionedConnection newConn = new PositionedConnection() { tailDirection = dir }; newConn.track.Add(pos); pointers.Add(newConn); } }