Example #1
0
        public override void WriteFile(List <Entity> entities, string path)
        {
            LoadKeyTypes();

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<?xml version=\"1.0\"?>");
            sb.AppendLine("<classes>");

            foreach (Entity ent in entities)
            {
                //write opening tag
                string model = "";
                if (!String.IsNullOrEmpty(ent.Model))
                {
                    model = " model=\"" + ent.Model + "\"";
                }

                if (ent.Mins == null)
                {
                    sb.AppendLine(String.Format("\n<group name=\"{0}\" color=\"{1}\"{2}>", ent.Name, TripletToString(ent.Color), model));
                }
                else
                {
                    sb.AppendLine(
                        String.Format(
                            "\n<point name=\"{0}\" color=\"{1}\" box=\"{2} {3}\"{4}>",
                            ent.Name,
                            TripletToString(ent.Color),
                            TripletToString(ent.Mins),
                            TripletToString(ent.Maxs),
                            model
                            )
                        );
                }

                //write description
                if (!String.IsNullOrEmpty(ent.Description))
                {
                    sb.AppendLine(EncodeXml(ent.Description));
                }

                //write keys
                if (ent.KeyGroupCount > 0)
                {
                    for (int i = 0; i < ent.KeyGroupCount; i++)
                    {
                        KeyGroup keyGroup = ent.GetKeyGroup(i);
                        sb.AppendLine("-------- " + keyGroup.Name + " --------");

                        for (int n = 0; n < keyGroup.KeyCount; n++)
                        {
                            Key    key     = keyGroup.GetKey(n);
                            string keyType = GetKeyType(key.Name);

                            if (!String.IsNullOrEmpty(keyType))
                            {
                                sb.AppendLine(String.Format("<{0} key=\"{1}\" name=\"{1}\">{2}</{0}>", keyType, key.Name, EncodeXml(key.Description)));
                            }
                        }
                    }
                }

                //write spawnflags
                if (ent.SpawnflagCount > 0)
                {
                    sb.AppendLine("-------- SPAWNFLAGS --------");
                    for (int i = 0; i < ent.SpawnflagCount; i++)
                    {
                        Spawnflag sf = ent.GetSpawnflag(i);
                        sb.AppendLine(String.Format("<flag key=\"{0}\" name=\"{0}\" bit=\"{1}\">{2}</flag>", sf.Name, sf.Bit, EncodeXml(sf.Description)));
                    }
                }

                if (!String.IsNullOrEmpty(ent.Notes))
                {
                    sb.AppendLine("-------- NOTES --------");
                    sb.AppendLine(EncodeXml(ent.Notes));
                }

                if (ent.Mins == null)
                {
                    sb.AppendLine("</group>");
                }
                else
                {
                    sb.AppendLine("</point>");
                }
            }

            sb.AppendLine("</classes>");

            Console.WriteLine("Writing output to \"" + path + "\"");
            StreamWriter sw = new StreamWriter(path);

            sw.Write(sb.ToString());
            sw.Close();
            Console.WriteLine("Done.");
        }