private void HandleConnect(MouseOverInteractable interactable) { if (ImprovedMouse.DidJustRightClick && !GameState.GameOver) { if (interactable.Type == InteractableType.Node) { startConnection = interactable.Entity; if (IsAlive(startConnection)) { var connectionLine = new ConnectionLine(startConnection, this); Parent.Add(connectionLine); connecting = connectionLine; } } SetTexture("handclick"); } if (IsConnecting && ImprovedMouse.DidJustRightRelease) { if (interactable.Type == InteractableType.Node && CanConnect(connecting, startConnection, interactable.Entity)) { connecting.Connected(startConnection, interactable.Entity); ConnectionHelper.RealignAllConnections(); } else { Parent.Remove(connecting); } SetTexture("hand"); connecting = null; } }
private static void SwapEndsIfNeeded(ConnectionLine connection, Entity entity) { if (connection.End != entity) { var tmp = connection.Start; connection.Start = connection.End; connection.End = tmp; } }
private bool CanConnect(ConnectionLine connection, Entity e1, Entity e2) { var areSame = e1 == e2; var twoContracts = e1 is ContractEntity && e2 is ContractEntity; var areBothAlive = IsAlive(e1) && IsAlive(e2); return(!areSame && !twoContracts && areBothAlive && !connection.AlreadyHasConnection(e1, e2)); }
private static void EnforceContractDirection(ConnectionLine connection) { if (connection.End is ContractEntity) { return; } var tmp = connection.Start; connection.Start = connection.End; connection.End = tmp; }