Comparision


Node Information
Compares two given values, if they are the same 'A==B' will be fired, else 'A!=B' will be fired.
General Information
• This node doesn't have other available options.
• Some of the ports of this node can change their types and accept types automatically.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Compare IN RUN MULTIPLE FALSE FALSE
A IN Object ONE FALSE TRUE
B IN Object ONE FALSE TRUE
A==B OUT RUN MULTIPLE FALSE FALSE
A!=B OUT RUN MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Conditions
{
    [IsNode("Comparision")]
    public class Comparison : Node
    {
        Port run = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Compare");
        Port a = new Port(PortType.IN, typeof(object), AcceptsLinks.ONE, "A");
        Port b = new Port(PortType.IN, typeof(object), AcceptsLinks.ONE, "B");
        Port tr = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "A==B");
        Port fl = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "A!=B");
        public Comparison()
        {
            this.Name = "Comparision";
            this.NodeType = KGraph.NodeType.Method;
            AddPort(run);
            AddPort(a);
            AddPort(b);
            AddPort(tr);
            AddPort(fl);
            a.CustomAcception = Accepts;
            b.CustomAcception = Accepts;
            Information = "Compares two given values, if they are the same 'A==B' will be fired, else 'A!=B' will be fired.";
        }
        private bool Accepts(Port port)
        {
            if (port == null)
            {
                return false;
            }
            if (a.IsConnected || b.IsConnected)
            {
                if (port.DataType == a.DataType)
                {
                    return true;
                }
            }
            else
            {
                ReturnType = port.DataType;
                a.DataType = port.DataType;
                a.Refresh();
                b.DataType = port.DataType;
                b.Refresh();
                return true;
            }
            return false;
        }
        public override string Code()
        {
            return "if(" + GetValue(a) + " == " + GetValue(b) + ")\r\n" + "{\r\n" + GetValue(tr) + "}\r\nelse\r\n{\r\n" + GetValue(fl) + "}";
        }
    }
}