Ejemplo n.º 1
0
        // Parses a .map file to our radiant map object.
        public static RadiantMap Parse(string path)
        {
            string[]      content    = File.ReadAllLines(path);
            bool          started    = false;
            bool          inBrush    = false;
            bool          inPatch    = false;
            List <string> brushLines = null;

            RadiantMap map = new RadiantMap();

            for (int i = 0; i < content.Length; ++i)
            {
                // Skip empty lines.
                if (content[i].Length < 1)
                {
                    continue;
                }

                if (started)
                {
                    if (content[i].Contains("{"))
                    {
                        if (!inBrush)
                        {
                            inBrush    = true;
                            brushLines = new List <string>();
                            brushLines.Add(content[i]);
                        }
                        else if (!inPatch)
                        {
                            inPatch = true;
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else if (content[i].Contains("}"))
                    {
                        if (inPatch)
                        {
                            map.Add(Patch.CreateFromCode(brushLines.ToArray()));
                            inPatch = false;
                        }
                        else if (inBrush)
                        {
                            map.Add(Brush.CreateFromCode(brushLines.ToArray()));
                            inBrush    = false;
                            brushLines = new List <string>();
                        }
                        else
                        {
                            break;
                        }
                    }
                    else if (inBrush)
                    {
                        brushLines.Add(content[i]);
                    }
                }
                else
                {
                    if (content[i][0] == '{')
                    {
                        started = true;
                    }
                }
            }

            return(map);
        }
Ejemplo n.º 2
0
 // Adds a patch to the radiant map.
 public void Add(Patch patch)
 {
     _patches.Add(patch);
 }