示例#1
0
        public bool TryConnectNodes(OutputPipeNode output, InputPipeNode input)
        {
            bool connected = false;

            if (output != null && input != null)
            {
                if (!output.IsInputConnected(input))
                {
                    if (output.CanConnectedWith(input))
                    {
                        output.AddConnectedInput(input);

                        connected = true;
                    }
                }
            }
            return(connected);
        }
示例#2
0
        public bool TryConnectOutput(OutputPipeNode output)
        {
            bool canConnect = false;

            if (output != null)
            {
                if (Globals.UltraDebug)
                {
                    Printer.Info($"[N{ID}] Trying connecting {output.Print()}");
                }
                if (Inputs.Count == 0)
                {
                    if (Globals.UltraDebug)
                    {
                        Printer.Info($"[N{ID}] No inputs to connect.");
                    }
                }
                else
                {
                    if (Globals.UltraDebug)
                    {
                        Printer.Info($"[N{ID}] {Inputs.Count} inputs to connect.");
                    }
                    foreach (InputPipeNode input in Inputs)
                    {
                        if (!output.IsInputConnected(input))
                        {
                            if (Globals.UltraDebug)
                            {
                                Printer.Info($"[N{ID}] {input.Print()} not already connected");
                            }
                            if (output.CanConnectedWith(input))
                            {
                                canConnect = output.AddConnectedInput(input);
                                if (Globals.UltraDebug)
                                {
                                    Printer.Info($"[N{ID}] Can connect with {input.Print()}? -> {canConnect}");
                                }
                            }
                            else
                            {
                                if (Globals.UltraDebug)
                                {
                                    Printer.Info($"[N{ID}] Cannot connect with {input.Print()}");
                                }
                            }
                        }
                        else
                        {
                            if (Globals.UltraDebug)
                            {
                                Printer.Info($"[N{ID}] {input.Print()} already connected");
                            }
                            if (Globals.UltraDebug)
                            {
                                Printer.Info($"[N{ID}] Updating path from {output.Print()} to {input.Print()} connected");
                            }
                            List <PipeNode> path = output.GetPath(input);
                            if (path.Count > 0 && path.Last().Equals(input))
                            {
                                output.ConnectedInputs[input] = path;
                                if (Globals.UltraDebug)
                                {
                                    Printer.Info($"[N{ID}] Path succesfully updated!");
                                }
                            }
                            else
                            {
                                if (Globals.UltraDebug)
                                {
                                    Printer.Info($"[N{ID}] Error updating path");
                                }
                            }
                        }
                        input.UpdateSignal();
                    }
                    output.UpdateSignal();
                }
            }
            return(canConnect);
        }