MultiCondition Expression


Node Information
Compares multiple values with specified conditions, if all conditions are met then result will be TRUE else result will be FALSE.
General Information
• This node has other options, you can view them by clicking on the info button, this also means according to the node you might be able to add more ports than what is already listed.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
A IN Object ONE FALSE FALSE
== IN OP NONE FALSE FALSE
B IN Object ONE FALSE FALSE
Result OUT Boolean MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Conditions
{
    [IsNode("MultiCondition Expression")]
    public class MultiConditionExpression : Node
    {
        Port a = new Port(PortType.IN, typeof(object), AcceptsLinks.ONE, "A");
        Port c = new Port(PortType.IN, typeof(OP), AcceptsLinks.NONE, "==");
        Port b = new Port(PortType.IN, typeof(object), AcceptsLinks.ONE, "B");
        Port result = new Port(PortType.OUT, typeof(bool), AcceptsLinks.MULTIPLE, "Result");
        public MultiConditionExpression()
        {
            NodeType = KGraph.NodeType.Function;
            ReturnType = typeof(bool);
            this.Name = "MultiCondition Expression";
            AddPort(a);
            AddPort(c);
            c.CanEditText = true;
            AddPort(b);
            AddPort(result);
            OptionsAvilable = true;
            CreateMenu();
            Information = "Compares multiple values with specified conditions, if all conditions are met then result will be TRUE else result will be FALSE.";
        }
        void CreateMenu()
        {
            System.Windows.Controls.ContextMenu menu = new System.Windows.Controls.ContextMenu();
            System.Windows.Controls.MenuItem addVariable = new System.Windows.Controls.MenuItem();
            addVariable.Header = "Add Variable";
            System.Windows.Controls.MenuItem addOperator = new System.Windows.Controls.MenuItem();
            addOperator.Header = "Add Operator";
            addVariable.Click += addVariable_Click;
            addOperator.Click += addOperator_Click;
            menu.Items.Add(addVariable);
            menu.Items.Add(addOperator);
            InfoContextMenu = menu;
        }
        void addOperator_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            Port aa = new Port(PortType.IN, typeof(OP), AcceptsLinks.ONE, "==");
            aa.IsRemovable = true;
            aa.CanEditText = true;
            AddPort(aa);
        }
        void addVariable_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            string name = GetABC(PortCount);
            Port aa = new Port(PortType.IN, typeof(object), AcceptsLinks.NONE, name);
            aa.IsRemovable = true;
            AddPort(aa);
        }
        public override string Code()
        {
            string code = "if(";
            foreach (var p in Ports)
            {
                if (p.DataType == typeof(OP))
                {
                    code += " " + p.Text + " ";
                }
                else if (p.DataType != typeof(RUN) && p != result)
                {
                    code += GetValue(p);
                }
            }
            code += ")\r\n{\r\n return true; \r\n}\r\n else \r\n{ \r\n return false; \r\n}";
            return code;
        }
    }
}