Пример #1
0
        protected override IEnumerator Execute(Block block)
        {
            int  n         = 0;
            bool satisfyIf = false;

            do
            {
                CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "IF" + n);
                yield return(ctor);

                DataStruct condition = ctor.Data;
                if (!condition.IsUndefined && condition.IsBoolean && condition.BooleanValue)
                {
                    yield return(CSharp.Interpreter.StatementRun(block, "DO" + n));

                    satisfyIf = true;
                    break;
                }
                ++n;
            } while (block.GetInput("IF" + n) != null);

            if (!satisfyIf && block.GetInput("ELSE") != null)
            {
                yield return(CSharp.Interpreter.StatementRun(block, "ELSE"));
            }
        }
Пример #2
0
        protected override IEnumerator Execute(Block block)
        {
            ResetFlowState();

            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "TIMES", new DataStruct(0));

            yield return(ctor);

            DataStruct repeats = ctor.Data;

            if (repeats.Type != Define.EDataType.Number)
            {
                throw new Exception("input value \"TIMES\" of block controls_repeat_ext must be a number type");
            }
            int repeatsInt = (int)repeats.NumberValue.Value;

            for (int i = 0; i < repeatsInt; i++)
            {
                yield return(CSharp.Interpreter.StatementRun(block, "DO"));

                //reset flow control
                if (NeedBreak)
                {
                    break;
                }
                if (NeedContinue)
                {
                    ResetFlowState();
                }
            }
        }
Пример #3
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "VALUE", new DataStruct(""));

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            ctor = CSharp.Interpreter.ValueReturn(block, "FIND", new DataStruct(""));
            yield return(ctor);

            DataStruct arg1 = ctor.Data;

            string end = block.GetFieldValue("END");

            switch (end)
            {
            case "FIRST":
                ReturnData(arg0.IsString
                        ? new DataStruct(arg0.StringValue.IndexOf(arg1.StringValue) + 1)
                        : new DataStruct(arg0.ListValue.IndexOf(arg1.Value) + 1));
                break;

            case "LAST":
                ReturnData(arg0.IsString
                        ? new DataStruct(arg0.StringValue.LastIndexOf(arg1.StringValue) + 1)
                        : new DataStruct(arg0.ListValue.LastIndexOf(arg1.Value) + 1));
                break;
            }
        }
Пример #4
0
        protected override IEnumerator Execute(Block block)
        {
            string op = block.GetFieldValue("OP");

            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "A", new DataStruct(false));

            yield return(ctor);

            DataStruct argument0 = ctor.Data;

            ctor = CSharp.Interpreter.ValueReturn(block, "B", new DataStruct(false));
            yield return(ctor);

            DataStruct argument1 = ctor.Data;

            if (argument0.Type != argument1.Type || argument0.Type != Define.EDataType.Boolean)
            {
                throw new Exception("arguments of block logic_operation should be the same BOOLEAN type");
            }

            DataStruct returnData = new DataStruct(false);

            switch (op)
            {
            case "AND":
                returnData.BooleanValue = argument0.BooleanValue && argument1.BooleanValue;
                break;

            case "OR":
                returnData.BooleanValue = argument0.BooleanValue || argument1.BooleanValue;
                break;
            }
            ReturnData(returnData);
        }
Пример #5
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "LIST", new DataStruct(""));

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            string type      = block.GetFieldValue("TYPE");
            string direction = block.GetFieldValue("DIRECTION");

            switch (type)
            {
            case "NUMERIC":
                arg0.ListValue.ArraySort(CompareNumeric, direction == "-1");
                ReturnData(new DataStruct(arg0.ListValue));
                break;

            case "TEXT":
                arg0.ListValue.ArraySort(CompareText, direction == "-1");
                ReturnData(new DataStruct(arg0.ListValue));
                break;

            case "IGNORE_CASE":
                arg0.ListValue.ArraySort(CompareImgoreCase, direction == "-1");
                ReturnData(new DataStruct(arg0.ListValue));
                break;
            }
        }
Пример #6
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "TEXT", new DataStruct(""));

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            string mode = block.GetFieldValue("MODE");

            switch (mode)
            {
            case "BOTH":
                ReturnData(new DataStruct(arg0.StringValue.Trim()));
                break;

            case "LEFT":
                ReturnData(new DataStruct(arg0.StringValue.TrimStart()));
                break;

            case "RIGHT":
                ReturnData(new DataStruct(arg0.StringValue.TrimEnd()));
                break;
            }
        }
Пример #7
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "TEXT", new DataStruct(""));

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            ctor = CSharp.Interpreter.ValueReturn(block, "SUB", new DataStruct(""));
            yield return(ctor);

            DataStruct arg1 = ctor.Data;

            int    count = 0;
            string tmp   = arg0.StringValue;

            while (true)
            {
                if (tmp.Contains(arg1.StringValue))
                {
                    count++;
                    tmp = tmp.Substring(tmp.IndexOf(arg1.StringValue) + 1);
                }
                else
                {
                    break;
                }
            }
            ReturnData(new DataStruct(count));
        }
Пример #8
0
        protected override IEnumerator Execute(Block block)
        {
            Debug.Log(">>>>>> block wait_time start: " + Time.time);

            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "TIME", new DataStruct(0));

            yield return(ctor);

            DataStruct time = ctor.Data;

            string unit = block.GetFieldValue("UNIT");

            switch (unit)
            {
            case "MILLISECOND":
                yield return(new WaitForSeconds(time.NumberValue.Value * 0.001f));

                break;

            case "SECONDS":
                yield return(new WaitForSeconds(time.NumberValue.Value));

                break;

            case "MINUTES":
                yield return(new WaitForSeconds(time.NumberValue.Value * 60f));

                break;

            case "TOOHIGH":
                Debug.Log("wait time too long");
                break;
            }
            Debug.Log(">>>>>> block wait_time end: " + Time.time);
        }
Пример #9
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "A", new DataStruct(false));

            yield return(ctor);

            DataStruct argument0 = ctor.Data;

            ctor = CSharp.Interpreter.ValueReturn(block, "B", new DataStruct(false));
            yield return(ctor);

            DataStruct argument1 = ctor.Data;

            ctor = CSharp.Interpreter.ValueReturn(block, "C", new DataStruct(false));
            yield return(ctor);

            DataStruct argument2 = ctor.Data;

            if (argument0.Type != argument1.Type || argument0.Type != Define.EDataType.Boolean)
            {
                throw new Exception("arguments of block logic_operation should be the same BOOLEAN type");
            }

            DataStruct returnData = new DataStruct(false);

            returnData.BooleanValue = argument0.BooleanValue && argument1.BooleanValue && argument2.BooleanValue;

            ReturnData(returnData);
        }
Пример #10
0
        /// <summary>
        /// run code representing the specified value input. WITH a default DataStruct
        /// </summary>
        public CustomEnumerator ValueReturn(Block block, string name, DataStruct defaultData)
        {
            CustomEnumerator etor = ValueReturn(block, name);

            etor.Cmdtor.DefaultData = defaultData;
            return(etor);
        }
Пример #11
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "NUM", new DataStruct(0));

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            string op = block.GetFieldValue("OP");

            switch (op)
            {
            case "ROUND":
                ReturnData(new DataStruct(System.Math.Round(arg0.NumberValue.Value)));
                break;

            case "ROUNDUP":
                ReturnData(new DataStruct(System.Math.Ceiling(arg0.NumberValue.Value)));
                break;

            case "ROUNDDOWN":
                ReturnData(new DataStruct(System.Math.Floor(arg0.NumberValue.Value)));
                break;
            }
        }
Пример #12
0
        protected override IEnumerator Execute(Block block)
        {
            ResetFlowState();

            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "LIST");

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            if (arg0.IsUndefined)
            {
                arg0 = new DataStruct(new ArrayList());
            }
            if (!arg0.IsList)
            {
                throw new Exception("input value \"LIST\" of block controls_forEach must be LIST type");
            }

            string variable0 = CSharp.VariableNames.GetName(block.GetFieldValue("VAR"), Variables.NAME_TYPE);

            foreach (var e  in arg0.ListValue)
            {
                DataStruct data;
                if (e is bool)
                {
                    data = new DataStruct((bool)e);
                }
                else if (e is float)
                {
                    data = new DataStruct(new Number((float)e));
                }
                else if (e is string)
                {
                    data = new DataStruct((string)e);
                }
                else if (e is ArrayList)
                {
                    data = new DataStruct((ArrayList)e);
                }
                else
                {
                    throw new Exception("LIST element is undefined type.");
                }

                CSharp.VariableDatas.SetData(variable0, data);
                yield return(CSharp.Interpreter.StatementRun(block, "DO"));

                //reset flow control
                if (NeedBreak)
                {
                    break;
                }
                if (NeedContinue)
                {
                    ResetFlowState();
                }
            }
        }
Пример #13
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "TEXT", new DataStruct(""));

            yield return(ctor);

            DataStruct returnData = new DataStruct(new string(ctor.Data.StringValue.Reverse().ToArray()));

            ReturnData(returnData);
        }
Пример #14
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "VALUE", new DataStruct(new ArrayList()));

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            ReturnData(arg0.IsList ? new DataStruct(arg0.ListValue.Count) : new DataStruct(arg0.StringValue.Length));
        }
Пример #15
0
        public IEnumerator Run(Block block)
        {
            Reset();
            yield return(OnRun(block));

            if (mData.IsUndefined && !mDefaultData.IsUndefined)
            {
                mData = mDefaultData;
            }
        }
Пример #16
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "LIST", new DataStruct(new ArrayList()));

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            arg0.ListValue.Reverse();
            ReturnData(new DataStruct(arg0.ListValue));
        }
Пример #17
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "TEXT", new DataStruct(""));

            yield return(ctor);

            DataStruct input = ctor.Data;

            //todo: 暂时用Debug.Log,后面根据UI输出框再定
            UnityEngine.Debug.Log("c# print: " + input.ToString());
        }
Пример #18
0
 public override bool Equals(object obj)
 {
     if (obj is DataStruct)
     {
         DataStruct data = (DataStruct)obj;
         return(data.Type == this.Type && data.Value == this.Value);
     }
     else
     {
         return(false);
     }
 }
Пример #19
0
 public static ArrayList ConvertBoolean(this ArrayList list)
 {
     for (int i = 0; i < list.Count; i++)
     {
         DataStruct ds = (DataStruct)list[i];
         if (ds.IsBoolean)
         {
             list[i] = new DataStruct(ds.BooleanValue ? new Number(1): new Number(0));
         }
     }
     return(list);
 }
Пример #20
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "NUMBER_TO_CHECK", new DataStruct(0));

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            string op = block.GetFieldValue("PROPERTY");

            switch (op)
            {
            case "EVEN":
                ReturnData(new DataStruct(arg0.NumberValue.Value % 2 == 0));
                break;

            case "ODD":
                ReturnData(new DataStruct(arg0.NumberValue.Value % 2 == 1));
                break;

            case "PRIME":
                ReturnData(new DataStruct(CheckPrime(arg0.NumberValue)));
                break;

            case "WHOLE":
                ReturnData(new DataStruct(arg0.NumberValue.Value % 1 == 0));
                break;

            case "POSITIVE":
                ReturnData(new DataStruct(arg0.NumberValue.Value > 0));
                break;

            case "NEGATIVE":
                ReturnData(new DataStruct(arg0.NumberValue.Value < 0));
                break;

            case "DIVISIBLE_BY":
                ctor = CSharp.Interpreter.ValueReturn(block, "DIVISOR", new DataStruct(0));
                yield return(ctor);

                DataStruct arg1 = ctor.Data;
                if (arg1.NumberValue.Value == 0)
                {
                    ReturnData(DataStruct.Undefined);
                }
                else
                {
                    ReturnData(new DataStruct((arg0.NumberValue % arg1.NumberValue).Value == 0));
                }
                break;
            }
        }
Пример #21
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "VALUE", new DataStruct(""));

            yield return(ctor);

            DataStruct arg0       = ctor.Data;
            DataStruct returnData = arg0.IsString
                ? new DataStruct(string.IsNullOrEmpty(arg0.StringValue))
                : new DataStruct(arg0.ListValue.Count <= 0);

            ReturnData(returnData);
        }
Пример #22
0
        protected override IEnumerator Execute(Block block)
        {
            string colour = block.GetFieldValue("TYPE");

            string msg = (colour == "RED" ? 2 : (colour == "GREEN" ? 3 : 4)).ToString();

            DataStruct returnData = new DataStruct(false);

            returnData.BooleanValue = MessageManager.Instance.SendBoolMessage(msg, MSG_TYPE.CELL_OCCUPIED);

            yield return(null);

            ReturnData(returnData);
        }
Пример #23
0
        public static bool HasList(this ArrayList list)
        {
            bool hasList = false;

            for (int i = 0; i < list.Count; i++)
            {
                DataStruct ds = (DataStruct)list[i];
                if (ds.IsList)
                {
                    hasList = true;
                }
            }
            return(hasList);
        }
Пример #24
0
        protected override IEnumerator Execute(Block block)
        {
            string tmp = block.GetFieldValue("VAR");

            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "TEXT", new DataStruct(""));

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            string result = CSharp.VariableDatas.GetData(tmp) + arg0.StringValue;

            CSharp.VariableDatas.SetData(tmp, new DataStruct(result));
        }
Пример #25
0
        protected override IEnumerator Execute(Block block)
        {
            string tmp = block.GetFieldValue("VAR");

            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "DELTA", new DataStruct(0));

            yield return(ctor);

            DataStruct arg1 = ctor.Data;

            Number result = CSharp.VariableDatas.GetData(tmp).NumberValue + arg1.NumberValue;

            CSharp.VariableDatas.SetData(tmp, new DataStruct(result));
        }
Пример #26
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "BOOL", new DataStruct(false));

            yield return(ctor);

            DataStruct argument = ctor.Data;

            if (argument.Type != Define.EDataType.Boolean)
            {
                throw new Exception("argument of block logic_negate should be the BOOLEAN type");
            }

            ReturnData(new DataStruct(!argument.BooleanValue));
        }
Пример #27
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "AMOUNT", new DataStruct(0));

            yield return(ctor);

            DataStruct arg0   = ctor.Data;
            Number     amount = arg0.NumberValue;

            string msg = "1 " + amount.ToString();

            MessageManager.Instance.SendMessage(msg, MSG_TYPE.CHANGE_INTENSITY);

            yield return(new WaitForSeconds(Times.instructionWaitTime));
        }
Пример #28
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "FROM", new DataStruct(0));

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            ctor = CSharp.Interpreter.ValueReturn(block, "TO", new DataStruct(0));
            yield return(ctor);

            DataStruct arg1 = ctor.Data;

            ReturnData(new DataStruct(UnityEngine.Random.Range((int)arg0.NumberValue.Value, (int)arg1.NumberValue.Value)));
        }
Пример #29
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "INPUT", new DataStruct(""));

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            ctor = CSharp.Interpreter.ValueReturn(block, "DELIM", new DataStruct(""));
            yield return(ctor);

            DataStruct arg1 = ctor.Data;

            ReturnData(new DataStruct(string.Join(arg1.StringValue, (string[])arg0.ListValue.ToArray())));
        }
Пример #30
0
        protected override IEnumerator Execute(Block block)
        {
            CustomEnumerator ctor = CSharp.Interpreter.ValueReturn(block, "INPUT", new DataStruct(""));

            yield return(ctor);

            DataStruct arg0 = ctor.Data;

            ctor = CSharp.Interpreter.ValueReturn(block, "DELIM", new DataStruct(""));
            yield return(ctor);

            DataStruct arg1 = ctor.Data;

            ReturnData(new DataStruct(new ArrayList(arg0.StringValue.Split(new string[] { arg1.StringValue }, StringSplitOptions.None))));
        }