changeset 106:9bf5eff0992a

Re #53: Add XML saver * Pad out some initial construction of XML for contained units
author IBBoard <dev@ibboard.co.uk>
date Mon, 17 Aug 2009 19:58:54 +0000
parents f5aec697b8ea
children c4ee96a91018
files api/Factories/Xml/WarFoundryXmlSaver.cs
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlSaver.cs	Mon Aug 17 19:08:44 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlSaver.cs	Mon Aug 17 19:58:54 2009 +0000
@@ -91,6 +91,23 @@
 			root.SetAttribute("system", toSave.GameSystem.ID);
 			root.SetAttribute("race", toSave.Race.ID);
 			root.SetAttribute("maxPoints", toSave.MaxPoints.ToString());
+			XmlElement units = doc.CreateElement("units");
+			root.AppendChild(units);
+			
+			foreach (Unit unit in toSave.GetUnits())
+			{
+				XmlElement unitElem = doc.CreateElement("unit");
+				unitElem.SetAttribute("id", unit.ID);
+				unitElem.SetAttribute("unitName", unit.Name);
+				unitElem.SetAttribute("unitType", unit.UnitType.ID);
+				unitElem.SetAttribute("size", unit.Size.ToString());
+				
+				if (!unit.Race.Equals(toSave.Race))
+				{
+					unitElem.SetAttribute("race", unit.Race.ID);
+				}
+			}
+			
 			return doc.OuterXml;
 		}
 	}