public static tmTreeNode ParseProfile(Engine engine)
        {
            ScriptEngine se = engine.GetScriptEngine(0) as ScriptEngine;

            LuaInterface.Lua      lua   = se.GetScriptHandle() as LuaInterface.Lua;
            LuaInterface.LuaTable table = lua["items"] as LuaInterface.LuaTable;
            if (table == null)
            {
                throw new System.Exception("Invalid profile,could't found the global variabl \"items\"");
            }

            tmTreeNode tree = new tmTreeNode("Root");   //root

            ParseLuaTable(tree, table);

            return(tree);
        }
        public static tmTreeNode LoadProfile(string file)
        {
            tmTreeNode tree = new tmTreeNode("Root");   //root

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.Load(file);
            System.Xml.XmlNodeList nodeList = doc.GetElementsByTagName("items");
            if (nodeList.Count == 0)
            {
                throw new System.Exception("Invalid profile,couldn't find \"items\" element.");
            }
            System.Xml.XmlElement element = nodeList[0] as System.Xml.XmlElement;
            if (element == null)
            {
                throw new System.Exception("Invalid profile,item is not a element.");
            }
            nodeList = element.GetElementsByTagName("item");
            foreach (System.Xml.XmlNode n in nodeList)
            {
                element = n as System.Xml.XmlElement;
                TestItem aItem = new TestItem();
                foreach (System.Xml.XmlAttribute a in element.Attributes)
                {
                    aItem[a.Name] = a.InnerText;
                }
                tmTreeNode keyNode = new tmTreeNode(aItem);
                tree.AddChildNode(keyNode);   //add group item

                //List child item
                System.Xml.XmlNodeList childList = element.GetElementsByTagName("subitem");
                foreach (System.Xml.XmlNode c in childList)
                {
                    element = c as System.Xml.XmlElement;
                    TestItem child = new TestItem();
                    foreach (System.Xml.XmlAttribute a in element.Attributes)
                    {
                        child[a.Name] = a.InnerText;
                    }
                    keyNode.AddChildNode(new tmTreeNode(child));
                }
            }
            return(tree);
        }
        static void ParseLuaTable(tmTreeNode tree, LuaInterface.LuaTable table)
        {
            try
            {
                foreach (object index in table.Keys)
                {
                    LuaInterface.LuaTable luaItem = table[index] as LuaInterface.LuaTable;
                    if (null == luaItem)
                    {
                        continue;
                    }
                    TestItem aItem = new TestItem();
                    //Console.WriteLine("LuaInterface.LuaTable<{0}> <{1}>", index as string,luaItem.ToString());
                    foreach (object key in luaItem.Keys)
                    {
                        if (null == luaItem[key])
                        {
                            continue;
                        }
                        //error occur here.
                        //Console.WriteLine("LuaInterface.luaItem[{0}],[{1}]", key as string, luaItem[key].ToString());
                        aItem[key.ToString()] = luaItem[key].ToString();
                    }
                    tmTreeNode node = new tmTreeNode(aItem);

                    tree.AddChildNode(node);

                    LuaInterface.LuaTable sub = luaItem["sub"] as LuaInterface.LuaTable;

                    if (null != sub)
                    {
                        ParseLuaTable(node, sub);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message + "In ParseLuaTable");
            }
        }
Beispiel #4
0
 public void AddChildNode(tmTreeNode node)
 {
     m_ChildNodes.Add(node);
 }