/// <summary> /// Convert the game DAT file into XML with accompanying comments /// </summary> public void SaveAsCommentedXML() { XElement gameData = new XElement("GameData"); gameData.Add( new XElement("Header" , new XElement("FileName", GameName) , new XElement("Unknown", Header.Unknown) , new XElement("MaxCarry", Header.MaxCarry) , new XElement("StartRoom", Header.StartRoom) , new XElement("TotalTreasures", Header.TotalTreasures) , new XElement("WordLength", Header.WordLength) , new XElement("LightDuration", Header.LightDuration) , new XElement("TreasureRoom", Header.TreasureRoom) ) ); // gameData.Add(new XElement("Actions" , new XAttribute("Count", Actions.Count()) , Actions.Select((val, ind) => MakeAction(val, ind, false))) ); //add words gameData.Add( new XElement("Words" , new XElement("Verbs", new XAttribute("Count", Verbs.Count()) , Verbs.Select((val, ind) => new { index = ind, value = val }) .Where(v => !v.value.StartsWith("*")) .Select(v => new XElement("Verb", new object[] { new XAttribute("value", v.value), new XAttribute("index", v.index) , from al in Verbs.Skip(v.index + 1).TakeWhile(al => al.StartsWith("*")) select new XElement("Alias", al) } )) ) , new XElement("Nouns", new XAttribute("Count", Nouns.Count()) , Nouns.Select((val, ind) => new { index = ind, value = val }) .Where(v => !v.value.StartsWith("*") & v.value.Length > 0) .Select(v => new XElement("Noun", new object[] { new XAttribute("value", v.value), new XAttribute("index", v.index) , from al in Nouns.Skip(v.index + 1).TakeWhile(al => al.StartsWith("*")) select new XElement("Alias", al) } )) ) ) ); //add rooms string[] directionsLong = { "North", "South", "East", "West", "Up", "Down" }; gameData.Add( new XElement("Rooms" , new XAttribute("Count", Rooms.Count()) , Rooms.Select((val, ind) => new XElement("Room", new object[] { new XAttribute("index", ind) , new XElement("Description", val.RawDescription) , val.Exits.Select((v, i) => new XElement(directionsLong[i], v)) }))) ); //messaes gameData.Add( new XElement("Messages" , new XAttribute("Count", Messages.Count()) , Messages.Select((val, ind) => new XElement("Message", new object[] { new XAttribute("index", ind) , val }))) ); gameData.Add( new XElement("Items" , new XAttribute("Count", Items.Count()) , Items.Select((val, ind) => new XElement("Item", new object[] { new XAttribute("index", ind) , new XElement("Description", val.Description) , new XElement("RoomID", val.Location) , val.Word != null ? new XElement("Word", val.Word) : null })))); gameData.Add( new XElement("Footer" , new XElement("Version", Footer.Version) , new XElement("AdventureNumber", Footer.AdventureNumber) , new XElement("Unknown", Footer.Unknown) ) ); gameData.Save(GameName + ".xml"); }