示例#1
0
 public EventHandlerDelcaration()
 {
     Params = new List <Parameter>();
     Body   = new BlockStatement();
 }
示例#2
0
 public LoopStatement()
 {
     Body = new BlockStatement();
 }
示例#3
0
 public FunctionDeclaration()
 {
     Params = new List <Parameter>();
     Body   = new BlockStatement();
 }
示例#4
0
 public ForInStatement()
 {
     Body = new BlockStatement();
 }
示例#5
0
        private static Sprite LoadSprite(XmlNode root)
        {
            if (root.Name != "Sprite")
            {
                return(null);
            }
            Sprite sp = new Sprite();

            PropertyInfo[] pinfo = sp.GetType().GetProperties();
            Dictionary <string, PropertyInfo> pMap = new Dictionary <string, PropertyInfo>();

            foreach (PropertyInfo p in pinfo)
            {
                pMap.Add(p.Name, p);
            }
            foreach (XmlNode node in root.ChildNodes)
            {
                string name = node.Name;
                if (name == "Variables")
                {
                    foreach (XmlNode eNode in node.ChildNodes)
                    {
                        Variable v = LoadVariable(eNode);
                        sp.Variables.Add(v);
                    }
                }
                else if (name == "Expressions")
                {
                    foreach (XmlNode eNode in node.ChildNodes)
                    {
                        Expression exp = LoadExpression(eNode);
                        sp.Expressions.Add(exp);
                        Point pt = new Point();
                        if (eNode.Attributes["x"] != null && eNode.Attributes["y"] != null)
                        {
                            pt = new Point(double.Parse(eNode.Attributes["x"].Value),
                                           double.Parse(eNode.Attributes["y"].Value));
                        }
                        sp.Positions.Add(exp, pt);
                    }
                }
                else if (name == "BlockStatements")
                {
                    foreach (XmlNode bnode in node.ChildNodes)
                    {
                        BlockStatement bs = LoadBlockStatement(bnode);
                        sp.BlockStatements.Add(bs);
                        Point pt = new Point();
                        if (bnode.Attributes["x"] != null && bnode.Attributes["y"] != null)
                        {
                            pt = new Point(double.Parse(bnode.Attributes["x"].Value),
                                           double.Parse(bnode.Attributes["y"].Value));
                        }
                        sp.Positions.Add(bs, pt);
                    }
                }
                else if (name == "Handlers")
                {
                    foreach (XmlNode bnode in node.ChildNodes)
                    {
                        Function func = LoadFunction(bnode);
                        sp.Handlers.Add(func as EventHandler);
                        Point pt = new Point();
                        if (bnode.Attributes["x"] != null && bnode.Attributes["y"] != null)
                        {
                            pt = new Point(double.Parse(bnode.Attributes["x"].Value),
                                           double.Parse(bnode.Attributes["y"].Value));
                        }
                        sp.Positions.Add(func, pt);
                    }
                }
                else if (name == "Functions")
                {
                    foreach (XmlNode bnode in node.ChildNodes)
                    {
                        Function func = LoadFunction(bnode);
                        sp.Functions.Add(func);
                        Point pt = new Point();
                        if (bnode.Attributes["x"] != null && bnode.Attributes["y"] != null)
                        {
                            pt = new Point(double.Parse(bnode.Attributes["x"].Value),
                                           double.Parse(bnode.Attributes["y"].Value));
                        }
                        sp.Positions.Add(func, pt);
                    }
                }
                else if (name == "Positions")
                {
                }
                else
                {
                    PropertyInfo property = pMap[name];
                    Type         pType    = property.PropertyType;
                    if (pType.IsAssignableFrom(typeof(List <string>)))
                    {
                        List <string> list = new List <string>();
                        foreach (XmlNode snode in node.ChildNodes)
                        {
                            list.Add(snode.Attributes["value"].Value);
                        }
                        property.SetValue(sp, list);
                    }
                    else if (pType.IsAssignableFrom(typeof(ResourcesList)))
                    {
                        ResourcesList list = new ResourcesList();
                        foreach (XmlNode snode in node.ChildNodes)
                        {
                            list.Add(LoadResource(snode));
                        }
                        property.SetValue(sp, list);
                    }
                    else
                    {
                        string value = node.Attributes["value"].Value;
                        object obj   = ConvertTo(value, pType);
                        if (obj != null)
                        {
                            property.SetValue(sp, obj);
                        }
                    }
                }
            }
            return(sp);
        }
示例#6
0
 public IfStatement()
 {
     Consequent = new BlockStatement();
     Alternate  = new BlockStatement();
 }
示例#7
0
 public static BlockStatement CloneBlockStatement(BlockStatement bs)
 {
     return(bs.Clone());
 }
示例#8
0
        private static Class LoadClass(XmlNode root)
        {
            if (root.Name != "Class")
            {
                throw new FormatException("Wrong data format");
            }
            if (root.Attributes["type"] == null)
            {
                throw new FormatException("Wrong data format");
            }
            string type = root.Attributes["type"].Value;

            Type  t  = Type.GetType(type);
            Class sp = Activator.CreateInstance(t) as Class;

            PropertyInfo[] pinfo = sp.GetType().GetProperties();
            Dictionary <string, PropertyInfo> pMap = new Dictionary <string, PropertyInfo>();

            foreach (PropertyInfo p in pinfo)
            {
                pMap.Add(p.Name, p);
            }
            foreach (XmlNode node in root.ChildNodes)
            {
                string name = node.Name;
                if (name == "Variables")
                {
                    foreach (XmlNode eNode in node.ChildNodes)
                    {
                        Variable v = LoadVariable(eNode);
                        sp.Variables.Add(v);
                    }
                }
                else if (name == "Expressions")
                {
                    foreach (XmlNode eNode in node.ChildNodes)
                    {
                        Expression exp = LoadExpression(eNode);
                        sp.Expressions.Add(exp);
                        System.Windows.Point pt = new System.Windows.Point();
                        if (eNode.Attributes["x"] != null && eNode.Attributes["y"] != null)
                        {
                            pt = new System.Windows.Point(double.Parse(eNode.Attributes["x"].Value),
                                                          double.Parse(eNode.Attributes["y"].Value));
                        }
                        sp.Positions.Add(exp, pt);
                    }
                }
                else if (name == "BlockStatements")
                {
                    foreach (XmlNode bnode in node.ChildNodes)
                    {
                        BlockStatement bs = LoadBlockStatement(bnode);
                        if (bs.Body.Count <= 0)
                        {
                            continue;
                        }
                        sp.BlockStatements.Add(bs);
                        System.Windows.Point pt = new System.Windows.Point();
                        if (bnode.Attributes["x"] != null && bnode.Attributes["y"] != null)
                        {
                            pt = new System.Windows.Point(double.Parse(bnode.Attributes["x"].Value),
                                                          double.Parse(bnode.Attributes["y"].Value));
                        }
                        sp.Positions.Add(bs, pt);
                    }
                }
                else if (name == "Handlers")
                {
                    foreach (XmlNode bnode in node.ChildNodes)
                    {
                        Function func = LoadFunction(bnode);
                        sp.Handlers.Add(func as ScratchNet.EventHandler);
                        System.Windows.Point pt = new System.Windows.Point();
                        if (bnode.Attributes["x"] != null && bnode.Attributes["y"] != null)
                        {
                            pt = new System.Windows.Point(double.Parse(bnode.Attributes["x"].Value),
                                                          double.Parse(bnode.Attributes["y"].Value));
                        }
                        sp.Positions.Add(func, pt);
                    }
                }
                else if (name == "Functions")
                {
                    foreach (XmlNode bnode in node.ChildNodes)
                    {
                        Function func = LoadFunction(bnode);
                        sp.Functions.Add(func);
                        System.Windows.Point pt = new System.Windows.Point();
                        if (bnode.Attributes["x"] != null && bnode.Attributes["y"] != null)
                        {
                            pt = new System.Windows.Point(double.Parse(bnode.Attributes["x"].Value),
                                                          double.Parse(bnode.Attributes["y"].Value));
                        }
                        sp.Positions.Add(func, pt);
                    }
                }
                else if (name == "Positions")
                {
                }
                else
                {
                    PropertyInfo property = pMap[name];
                    Type         pType    = property.PropertyType;
                    if (pType.IsAssignableFrom(typeof(List <string>)))
                    {
                        List <string> list = new List <string>();
                        foreach (XmlNode snode in node.ChildNodes)
                        {
                            list.Add(snode.Attributes["value"].Value);
                        }
                        property.SetValue(sp, list);
                    }
                    else
                    {
                        string value = node.Attributes["value"].Value;
                        object obj   = ConvertTo(value, pType);
                        if (obj != null)
                        {
                            property.SetValue(sp, obj);
                        }
                    }
                }
            }
            return(sp);
        }
示例#9
0
 public WhileStatement()
 {
     Body = new BlockStatement();
 }