Beispiel #1
0
 private void OpenFile_Click(object sender, EventArgs e)
 {
     //OpenFileDialog.InitialDirectory = "c:\\";
     OpenFileDialog.FileName         = "";
     OpenFileDialog.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
     OpenFileDialog.FilterIndex      = 2;
     OpenFileDialog.RestoreDirectory = true;
     //var dialog = OpenFileDialog.ShowDialog();
     //Stream myStream;
     if (OpenFileDialog.ShowDialog() == DialogResult.OK)
     {
         string fileName = OpenFileDialog.FileName;
         //string[] FileLines = File.ReadAllLines(fileName);
         ByteArrFile bar = new ByteArrFile("textmap");
         bar.bytes = File.ReadAllBytes(fileName);
         List <string> fl = UDMF_TextmapEx.ReadFileToNodes(bar);
         //fl.AddRange(FileLines);
         OurMap = UDMF_TextmapEx.ReadFile(fl);
         Console.WriteLine("Passed");
     }
 }
        public static UDMFConverted ReadFile(List <string> file)
        {
            /*foreach(string m in file)
             * {
             *  Debug.Log(m);
             * }
             * return new UDMFConverted();*/
            if (file.Count > 0)
            {
                UDMFConverted dConv = new UDMFConverted();

                List <VertexDef> vertices = new List <VertexDef>();
                List <Sector>    sectors  = new List <Sector>();
                List <SideDef>   sideDefs = new List <SideDef>();
                List <Linedef>   lineDefs = new List <Linedef>();
                List <Thing>     things   = new List <Thing>();
                //			CRd current= CRd.core;
                for (int ln = 0; ln < file.Count; ln++)
                {
                    //int ePos=ln;
                    if (Regex.IsMatch(file[ln], @"thing.*\n{", RegexOptions.IgnoreCase))
                    {
                        //Debug.Log("thing:"+file[ln]);
                        Thing tn = new Thing();
                        tn.FormFromList(file[ln].Split(new char[] { '\n' }, StringSplitOptions.None));
                        things.Add(tn);
                    }
                    else if (Regex.IsMatch(file[ln], @"vertex.*\n{", RegexOptions.IgnoreCase))
                    {
                        //Debug.Log("vertex:"+file[ln]);
                        VertexDef vect = new VertexDef();
                        vect.FormFromList(file[ln].Split(new char[] { '\n' }, StringSplitOptions.None));
                        //Vector2 vect = StrUtils.FormVector2FromList(file[ln].Split(new char[] { '\n' }, StringSplitOptions.None));
                        vertices.Add(vect);
                    }
                    else if (Regex.IsMatch(file[ln], @"linedef.*\n{", RegexOptions.IgnoreCase))
                    {
                        //Debug.Log("linedef:"+file[ln]);
                        Linedef ld = new Linedef();
                        ld.FormFromList(file[ln].Split(new char[] { '\n' }, StringSplitOptions.None));
                        lineDefs.Add(ld);
                    }
                    else if (Regex.IsMatch(file[ln], @"sidedef.*\n{", RegexOptions.IgnoreCase))
                    {
                        //Debug.Log("sidedef:"+file[ln]);
                        SideDef sd = new SideDef();
                        sd.FormFromList(file[ln].Split(new char[] { '\n' }, StringSplitOptions.None));
                        sideDefs.Add(sd);
                    }
                    else if (Regex.IsMatch(file[ln], @"sector.*\n{", RegexOptions.IgnoreCase))
                    {
                        //Debug.Log("sector:"+file[ln]);
                        Sector sec = new Sector();
                        sec.FormFromList(file[ln].Split(new char[] { '\n' }, StringSplitOptions.None));
                        sectors.Add(sec);
                    }


                    //if(ePos!=ln) ln=ePos;
                }


                dConv.things   = things;
                dConv.vertices = vertices;
                dConv.sectors  = sectors;
                dConv.sideDefs = sideDefs;
                dConv.lineDefs = lineDefs;



                return(dConv);
            }

            return(null);
        }