コード例 #1
0
        /// <summary>
        /// Parse script line by line.
        /// </summary>
        private void ParseScript()
        {
            Dynamic dyn = (Dynamic)currentlySelectedObject;
            int atindex = -1; // If -1, @ token was not found
            dyn.Instructions.Clear();

            // Mark flag to enable scripted movement
            dyn.IsScripted = cbox_Scripted.Checked;

            // Parse instructions and send to object
            Regex reg = new Regex(EditorConstants.WINFORM_NEWLINE);
            List<string> instructions = new List<string>(reg.Split(tb_Script.Text));
            instructions.RemoveAll(IsEmptyString);

            for (int i = 0; i < instructions.Count; i++)
            {
                string line = instructions[i];
                Instruction inst = new Instruction();

                if (line[0] == '@')
                {
                    atindex = dyn.Instructions.Count;
                    line = line.Substring(1);
                    if (inst.Initialize(line))
                        dyn.Instructions.Add(inst);

                }
                else if (line == "goto @" && atindex > -1)
                {
                    line = "goto " + atindex;
                    if (inst.Initialize(line))
                        dyn.Instructions.Add(inst);
                }
                else
                {
                    if (inst.Initialize(line))
                        dyn.Instructions.Add(inst);
                }

            }
        }