/// <summary> /// pass the xstruct node, return a gff3 struct /// </summary> /// <param name="in_xstruct"></param> /// <param name="parentStruct"></param> private static void ParseStruct(XElement in_xstruct, gff3struct parentStruct) { string structID = in_xstruct.Attribute("id").Value; foreach (var node in in_xstruct.Elements()) { // if node is a list if (ReadType(node) == "list") { //get variables var label = ReadLabel(node); var type = ReadType(node); var children = new List <gff3struct>(); var xchildren = node.Elements(); //nodes with name struct id=0, id=1 etc... foreach (var childnode in xchildren) { var schild = new gff3struct(ReadID(childnode)); ParseStruct(childnode, schild); //passes the struct children.Add(schild); } //create object and add to parent struct var obj = new CGff3List(type, label, children); parentStruct.Data.Add(obj); } // if node is a common type else { if (ReadType(node) == "locstring") { var label = ReadLabel(node); var type = ReadType(node); var children = new List <CGff3String>(); //strref var xchildren = node.Elements(); foreach (var childnode in xchildren) { CGff3String xstring = ReadString(childnode); children.Add(xstring); } var obj = new CGff3Locstring(type, label, children); parentStruct.Data.Add(obj); } // add common type to paremt struct else { parentStruct.Data.Add(ReadGeneric(node)); } } } }
/// <summary> /// Prints custom data to xml element /// </summary> /// <param name="data"></param> /// <param name="parent"></param> /// <param name="idx"></param> /// <param name="type"></param> /// <returns></returns> private bool AnnotateXML(gff3struct data, XElement parent, int idx, string type, bool isSection, ref XElement output) { //Document Settings var Doc = parent.Document; XElement Actors = Doc.Descendants("Settings").First()?.Element("Actors"); XElement Player = Doc.Descendants("Settings").First()?.Element("Player"); List <XAttribute> attributes = new List <XAttribute>(); //attributes.Add(new XAttribute("Idx", idx)); output.Add(new XAttribute("ref", $"{type}_{idx}")); //TEXT CGff3Locstring locstring = (CGff3Locstring)data.GetListObjectByName <CGff3String>("Text"); string Text = ""; if (locstring != null) { CGff3String englishText = locstring.Value.FirstOrDefault(x => x.Language == "6"); if (englishText != null) { Text = englishText.Value; } } attributes.Add(new XAttribute("Text", Text)); //SPEAKER string Speaker = data.GetCommonObjectByName("Speaker").Value.ToString(); if (Speaker == "__player__") { Speaker = "geralt"; } if (Speaker == "__owner__") { Speaker = "npc"; } //write speakers to settings if (Actors == null) { throw new Gff3Exception("No Actors in Database"); //should never go offbut keep it for testing } List <string> ActorList = Actors.Elements().Select(x => x.Value.ToString()).ToList(); //Add actors to actorlist if (!ActorList.Contains(Speaker)) { Actors.Add(new XElement("Actor", Speaker)); } if (Speaker == "geralt" && Player.Value != null) { Player.Value = Speaker; } attributes.Add(new XAttribute("Speaker", Speaker)); // Adding soundfile var string Sound = data.GetCommonObjectByName("Sound").Value.ToString(); attributes.Add(new XAttribute("Sound", Sound)); //OTHER var dsdata = AttributeData(data, ref attributes); //QUESTS //ADD output.Add(attributes.ToArray()); //add section data if (isSection) { //remove special charactersand to lower string sectionname = Text.Split(' ').First(); Regex rgx = new Regex("[^a-zA-Z0-9]"); sectionname = $"section_{rgx.Replace(sectionname, "").ToLower()}_{idx}"; //add to sections list AddToSectionsNoDuplicates(Doc, sectionname, $"{type}_{idx}"); output.Add(new XAttribute("section", sectionname)); } bool isQuestParent = !String.IsNullOrEmpty(dsdata.questfact); if (isQuestParent) { //add to quest list AddToSectionsNoDuplicates(Doc, $"script_setfact_{dsdata.questfact}", $"quest_{idx}"); //add quest xml tags var scriptelement = new XElement("SCRIPT", new XAttribute("function", "AddFact_S"), new XElement("parameter", new XAttribute("factName", $"{dsdata.questfact}"), new XAttribute("value", $"1"), new XAttribute("validFor", $"0") )); var questelement = new XElement("QUEST", new XAttribute("Name", dsdata.questfact), new XAttribute("section", $"script_setfact_{dsdata.questfact}"), new XAttribute("ref", $"quest_{idx}"), scriptelement ); // reshuffle nodes output.Add(questelement); parent.Add(output); output = output.Element("QUEST"); } else { parent.Add(output); } return(isQuestParent); }