示例#1
0
 static HudElement ParseHudElement(string s)
 {
     HudElement he = new HudElement();
     RefLib.Seek(ref s);
     string ss = s;
     ss = RefLib.GetLine(ref ss);
     if(ss.IndexOf('[') == -1)
         he.Name = RefLib.Condense(ss);
     else
     {
         if(s.First() == '[')
         {
             string result = "";                    
             for(int i = 0; i < s.Length; i++)
             {
                 result += ss[i];
                 if(ss[i] == ']')
                     break;
                 throw new Exception("Reached end of file before reaching end of platform tag");
             }
             s = s.Remove(0,ss.Length);
             he.Platform = ss;
             RefLib.Seek(ref s);
         }
     }
     s = s.Remove(ss.Length);
     RefLib.Seek(ref s);
     if(s.First() == '{')
     {
         while(s.First() != '}')
         {
             string temp = s;
             temp = RefLib.GetLines(2,ref temp);
             if(temp.IndexOf('{') != -1)
             {
                 SubElement sb = ParseSubElement(ref s);
                 if(!sb.IsNull)
                 {
                     he.Add(sb);
                     continue;
                 }
                 else throw new Exception("Parse sub element returned null. Don't try to parse if there isn't one");
             }
             RefLib.Seek(ref s);
             KeyValue kv = new KeyValue();
             string x = GetKeyValuePair(s);
             kv = ParseKeyValue(x);
             if(x != "")                    
                 s.Remove(0,x.Length);
             if(!kv.IsNull)
             {
                 he.Add(kv);
             }
             else break;                    
         }
     }
     return he;
 }
示例#2
0
        static HudFile ParseHudFile(string path)
        {
            HudFile hf = new HudFile();
            string s;            

            if(File.Exists(path))
            {
                StreamReader sr = new StreamReader(path);
                s = sr.ReadToEnd();
                RefLib.CleanUp(ref s,RefLib.cleanupModes.Comments);
                sr.Close();                
            }
            else throw new Exception("Can't parse file, it doesn't exist.");

            RefLib.Seek(ref s);
            string ss = s;
            ss = RefLib.GetLine(ref ss);
            hf.FullName = ReadName(ss);
            s = s.Remove(0,ss.Length);
            

            RefLib.Seek(ref s);
            if(s.First() == '{')
            {
                s = s.Remove(0,1);                
                while(true)
                {
                    HudElement he = new HudElement();
                    RefLib.Seek(ref s);                    
                    ss = ReadName(s);
                    if(ss != "")
                    {
                        he.Name = ss;
                        s = s.Remove(0,ss.Length);
                        RefLib.Seek(ref s);
                    }
                    ss = s;
                    ss = RefLib.GetLine(ref ss);
                    if(ss.First() == '[')
                    {                        
                        if(ss.IndexOf(']') != -1)
                        {
                            he.Platform = Read(s,readModes.PlatformTag);
                        }
                        else throw new Exception("Expected platform tag (ex. [$WIN32]) in element " + he.Name + ". In file " + hf.FullName + " got: " + ss);
                        s = s.Remove(0,ss.Length);
                        RefLib.Seek(ref s);
                    }

                    if(s.First() == '{')
                    {
                        s = s.Remove(0,1);
                        while(true)
                        {
                            RefLib.Seek(ref s);
                            ss = s;
                            ss = RefLib.GetLines(2,ref ss);
                            if(ss.IndexOf('{') != -1)
                            {
                                SubElement sb = ParseSubElement(ref s);
                                if(!sb.IsNull)
                                {
                                    he.Add(sb);
                                    s = s.Remove(0,s.IndexOf('}')+1);
                                }
                                continue;                                
                            }

                            if(s.First() != '}')
                            {
                                ss = s;
                                ss = GetKeyValuePair(ss);
                                s = s.Remove(0,ss.Length);
                                KeyValue kv = ParseKeyValue(ss);

                                if(!kv.IsNull)
                                {
                                    he.Add(kv);
                                    continue;
                                }
                            }
                            break;
                        }
                        if(!he.IsNull)
                        {
                            hf.Add(he);
                            RefLib.Seek(ref s);
                            if(s.First() == '}')
                            {
                                s = s.Remove(0,1);
                                RefLib.Seek(ref s);
                            }
                        }
                        else break;
                    }
                    else if(s.First() == '}')
                    {
                        s = s.Remove(0,1);
                        RefLib.Seek(ref s);
                        if(s != "")
                            throw new Exception("Error while parsing file " + hf.FullName + ". String should be empty by now but isn't");
                        else break;
                    }
                }
            }
            return hf;
        }
示例#3
0
 public void Add(HudElement element)
 {
     m_ElementList.Add(element);
 }