protected override CodeblockSystem BuildSystem()
        {
            CodeblockSystem system = new CodeblockSystem();

            const int   desiredLoopCount   = 4;
            int         loopRunCount       = 0;
            ActionBlock loopCountIncrement = new ActionBlock();

            loopCountIncrement.Action = () => loopRunCount++;

            DynamicInputOperator <int> count = new DynamicInputOperator <int>();

            count.Value = desiredLoopCount;

            ForLoopBlock forLoop = new ForLoopBlock();

            forLoop.LoopCount = count;

            AssertTestBlock assert = new AssertTestBlock();

            assert.Condition = () => loopRunCount == desiredLoopCount;

            forLoop.Children.InsertItem(loopCountIncrement, null);

            system.Blocks.InsertItem(forLoop, null);
            system.Blocks.InsertItem(assert, forLoop);

            return(system);
        }
        protected override CodeblockSystem BuildSystem()
        {
            CodeblockSystem system = new CodeblockSystem();

            AssertTestBlock poisonedBlock = new AssertTestBlock();

            poisonedBlock.Condition = () => false;

            BreakCodeblock breakBlock = new BreakCodeblock();

            DynamicInputOperator <int> count = new DynamicInputOperator <int>();

            count.Value = 100;

            ForLoopBlock flb = new ForLoopBlock();

            flb.LoopCount = count;

            flb.Children.InsertItem(breakBlock, null);
            flb.Children.InsertItem(poisonedBlock, breakBlock);

            system.Blocks.InsertItem(flb, null);

            return(system);
        }
        protected override CodeblockSystem BuildSystem()
        {
            CodeblockSystem system = new CodeblockSystem();

            DynamicInputOperator <int>[] inputs = new DynamicInputOperator <int> [4];
            for (int i = 0; i < 4; i++)
            {
                DynamicInputOperator <int> input = new DynamicInputOperator <int>();
                input.Value = i * 2;
                inputs[i]   = input;
            }

            ComparisonOperationCodeblock left = new ComparisonOperationCodeblock()
            {
                Left      = inputs[0],
                Right     = inputs[1],
                Operation = ComparisonOperation.SmallerOrEqual
            };
            ComparisonOperationCodeblock right = new ComparisonOperationCodeblock()
            {
                Left      = inputs[2],
                Right     = inputs[3],
                Operation = ComparisonOperation.Equal
            };

            LogicOperationCodeblock logic = new LogicOperationCodeblock()
            {
                Left      = left,
                Right     = right,
                Operation = LogicalOperation.OR
            };

            AssertTestBlock ifTrue = new AssertTestBlock();

            ifTrue.Condition = () => true;

            AssertTestBlock ifFalse = new AssertTestBlock();

            ifFalse.Condition = () => false;

            IfElseBlock ifElseBlock = new IfElseBlock();

            ifElseBlock.Condition = logic;

            ifElseBlock.Children.InsertItem(ifTrue, null);
            ifElseBlock.ElseChildren.InsertItem(ifFalse, null);

            system.Blocks.InsertItem(ifElseBlock, null);

            return(system);
        }
        protected override CodeblockSystem BuildSystem()
        {
            CodeblockSystem system = new CodeblockSystem();

            AssertTestBlock ifTrue = new AssertTestBlock();

            ifTrue.Condition = () => true;

            AssertTestBlock ifFalse = new AssertTestBlock();

            ifFalse.Condition = () => false;

            var left = new DynamicInputOperator <float>();

            left.Value = 5;
            var right = new DynamicInputOperator <string>();

            right.Value = "1";

            ComparisonOperationCodeblock coc = new ComparisonOperationCodeblock();

            coc.Operation = ComparisonOperation.GreaterThan;
            coc.Left      = left;
            coc.Right     = right;

            IfElseBlock ifelse = new IfElseBlock();

            ifelse.Condition = coc;

            ifelse.Children.InsertItem(ifTrue, null);
            ifelse.ElseChildren.InsertItem(ifFalse, null);

            system.Blocks.InsertItem(ifelse, null);

            return(system);
        }
Beispiel #5
0
        private void PrepareInputOfType(Type type)
        {
            _input = GetComponentInChildren <TMP_InputField>();
            if (IsInputFieldType(type))
            {
                _input.onValueChanged.AddListener(OnTextChanged);

                if (type == typeof(string))
                {
                    DynamicInputOperator <string> input = new DynamicInputOperator <string>();

                    _input.contentType = TMP_InputField.ContentType.Standard;
                    _input.text        = "";

                    _evaluateInputMethod = () => input.Value = _input.text;
                    CurrentInputOperator = input;
                }
                if (type == typeof(int))
                {
                    _input.contentType = TMP_InputField.ContentType.IntegerNumber;
                    _input.text        = "0";

                    _evaluateInputMethod = () => int.Parse(_input.text);
                }
                if (type == typeof(float))
                {
                    _input.contentType = TMP_InputField.ContentType.DecimalNumber;
                    _input.text        = "0";

                    _evaluateInputMethod = () => float.Parse(_input.text);
                }
            }
            else
            {
                _input.gameObject.SetActive(false);
            }

            _dropdown = GetComponentInChildren <TMP_Dropdown>();
            if (IsDropdownType(type))
            {
                _dropdown.onValueChanged.AddListener(OnDropdownChanged);

                if (type == typeof(bool))
                {
                    _dropdown.options = GenerateOptionsFromStrings("true", "false");
                    _dropdown.value   = 0;

                    _evaluateInputMethod = () => _dropdown.value == 0;
                }
                if (type.IsEnum)
                {
                    var displayValues = GenerateOptionsFromStrings(Enum.GetValues(type).OfType <object>().Select(v => v.ToString()).ToArray());
                    _dropdown.options = displayValues;
                    _dropdown.value   = 0;

                    _evaluateInputMethod = () => Enum.GetValues(type).OfType <object>().Select(e => Convert.ChangeType(e, type)).ElementAt(_dropdown.value);
                }

                OnDropdownChanged(_dropdown.value);
            }
            else
            {
                _dropdown.gameObject.SetActive(false);
            }

            _dropArea = transform.GetChild(2);
        }