Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gff3"></param>
        /// <returns></returns>
        public void GenerateXML()
        {
            #region XML Structure
            var Doc  = new XDocument();
            var root = new XElement("root");
            Doc.AddFirst(root);
            Doc.Root.Add(
                new XElement("Settings"),
                new XElement("Dialogscripts"));
            XElement Dialogscripts = Doc.Descendants("Dialogscripts").First();
            XElement Settings      = Doc.Descendants("Settings").First();
            Settings.Add(new XElement("Actors"));
            Settings.Add(new XElement("Player"));
            Settings.Add(new XElement("SectionsList"));
            #endregion


            // Speaker settings
            List <gff3struct> SpeakerList = ((CGff3ListObject <gff3struct>)GFF.GetGenericObjectByName("SpeakerList"))?.Value;
            List <string>     Actors      = SpeakerList.Select(x => x.GetCommonObjectByName("Speaker")?.Value.ToString())?.ToList();
            foreach (var actor in Actors)
            {
                Settings.Element("Actors").Add(new XElement("Actor", actor));
            }

            //Dialogscripts
            CGff3ListObject <gff3struct> StartingList = (CGff3ListObject <gff3struct>)GFF.GetGenericObjectByName("StartingList");
            for (int i = 0; i < StartingList.Value.Count; i++)
            {
                //add generic start sections to section list
                // FIXME pause?
                var startelement = new XElement("PAUSE",
                                                new XAttribute("section", $"section_start_{i}"),
                                                new XAttribute("ref", $"start_{i}")
                                                );
                Dialogscripts.Add(startelement);
                Settings.Element("SectionsList").Add(new XElement("Section", $"start_{i}", new XAttribute("Name", $"section_start_{i}")));


                //
                gff3struct         item = (gff3struct)StartingList.Value[i];
                CGff3GenericObject obj  = item.GetCommonObjectByName("Index");
                int idx = int.Parse(obj.Value.ToString());

                // Write Tree
                WriteTree(GFF, startelement, idx, "entry", true);
            }

            //Modify Speaker Section
            string        player = Settings.Element("Player").Value;
            List <string> actors = Settings.Element("Actors").Descendants()?.Select(x => x.Value).ToList();
            if (String.IsNullOrEmpty(player))
            {
                Settings.Element("Player").Value = actors.First();
            }


            XDOC = Doc;
        }