Mercurial > repos > snowblizz-super-API-ideas
annotate api/Savers/Xml/WarFoundryXmlArmySaver.cs @ 325:e0580a009e75
Re #324: Add saving of Race and System data to files
* Remove extra interfaces, as their replacements would be implementation specific and the break-down is now only a clean coding issue
* Strip out extra code from Army and GameSystem saver
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 12 Mar 2011 20:32:08 +0000 |
parents | 8a64b36d36b8 |
children |
rev | line source |
---|---|
316
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (WarFoundryXmlSaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 2009 IBBoard. |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System.Collections.Generic; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using System.IO; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 using System.Xml; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 using System.Xml.Schema; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 using IBBoard.Lang; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 using IBBoard.Xml; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 using IBBoard.WarFoundry.API.Factories.Xml.Zip; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 using IBBoard.WarFoundry.API.Objects; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 using IBBoard.WarFoundry.API.Savers; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 using IBBoard.WarFoundry.API.Util; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 using ICSharpCode.SharpZipLib.Zip; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 namespace IBBoard.WarFoundry.API.Savers.Xml |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 { |
325
e0580a009e75
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
323
diff
changeset
|
20 public class WarFoundryXmlArmySaver |
316
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 { |
325
e0580a009e75
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
323
diff
changeset
|
22 public string CreateXmlString(Army toSave) |
316
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 XmlDocument doc = new XmlDocument(); |
323
8a64b36d36b8
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
316
diff
changeset
|
25 XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); |
316
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 doc.AppendChild(declaration); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 XmlSchema schema = new XmlSchema(); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 schema.Namespaces.Add("", "http://ibboard.co.uk/warfoundry/army"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 schema.Namespaces.Add("core", "http://ibboard.co.uk/warfoundry/core"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 doc.Schemas.Add(schema); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 XmlElement root = doc.CreateElement("army"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 root.SetAttribute("xmlns", "http://ibboard.co.uk/warfoundry/army"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 root.SetAttribute("xmlns:core", "http://ibboard.co.uk/warfoundry/core"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 doc.AppendChild(root); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 root.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(toSave.ID)); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 root.SetAttribute("name", toSave.Name); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 //Don't convert system and race to ID format as they could be stored in non-XML file formats |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 //If they are in XML files then they'll already be valid |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 root.SetAttribute("system", toSave.GameSystem.ID); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 root.SetAttribute("race", toSave.Race.ID); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 root.SetAttribute("maxPoints", toSave.MaxPoints.ToString()); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 XmlElement units = doc.CreateElement("units"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 root.AppendChild(units); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 foreach (Unit unit in toSave.GetUnits()) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 units.AppendChild(CreateUnitElement(unit, doc)); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 return doc.OuterXml; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 private XmlElement CreateUnitElement(Unit unit, XmlDocument doc) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 XmlElement unitElem = doc.CreateElement("unit"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 unitElem.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(unit.ID)); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 unitElem.SetAttribute("unitName", (unit.HasDefaultName() ? "" : unit.Name)); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 unitElem.SetAttribute("unitType", unit.UnitType.ID); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
59 unitElem.SetAttribute("size", unit.Size.ToString()); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
60 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
61 if (!unit.Race.Equals(unit.Army.Race)) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
62 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 unitElem.SetAttribute("race", unit.Race.ID); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
64 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
65 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
66 Category unitCategory = unit.Category.Category; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
67 if (!unit.UnitType.MainCategory.Equals(unitCategory)) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
68 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
69 unitElem.SetAttribute("category", unitCategory.ID); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
70 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
71 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
72 XmlElement equipmentElem = CreateEquipmentItemsElement(unit, doc); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
73 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
74 if (equipmentElem != null) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
75 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
76 unitElem.AppendChild(equipmentElem); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
77 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
78 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
79 XmlElement containedElem = CreateContainedUnitsElement(unit, doc); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
80 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
81 if (containedElem != null) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
82 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
83 unitElem.AppendChild(containedElem); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
84 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
85 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
86 return unitElem; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
87 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
88 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
89 private XmlElement CreateEquipmentItemsElement(Unit unit, XmlDocument doc) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
90 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
91 UnitEquipmentItem[] equipItems = unit.GetEquipment(); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
92 int equipItemCount = equipItems.Length; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
93 XmlElement equipmentElem = null; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
94 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
95 if (equipItemCount > 0) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
96 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
97 equipmentElem = doc.CreateElement("equipment"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
98 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
99 for (int i = 0; i < equipItemCount; i++) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
100 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
101 equipmentElem.AppendChild(CreateEquipmentElement(equipItems[i], unit, doc)); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
102 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
103 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
104 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
105 return equipmentElem; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
106 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
107 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
108 private XmlElement CreateEquipmentElement(UnitEquipmentItem item, Unit unit, XmlDocument doc) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
109 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
110 XmlElement equipmentItemElem = doc.CreateElement("equipItem"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
111 equipmentItemElem.SetAttribute("id", item.ID); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
112 equipmentItemElem.SetAttribute("amount", UnitEquipmentUtil.GetEquipmentAmount(unit, item).ToString()); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
113 equipmentItemElem.SetAttribute("amountType", UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, item) ? "ratio" : "fixed"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
114 return equipmentItemElem; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
115 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
116 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
117 private XmlElement CreateContainedUnitsElement(Unit unit, XmlDocument doc) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
118 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
119 Unit[] containedUnits = unit.ContainedUnits; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
120 int containedCount = containedUnits.Length; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
121 XmlElement containedElem = null; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
122 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
123 if (containedCount > 0) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
124 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
125 containedElem = doc.CreateElement("contained"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
126 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
127 for (int i = 0; i < containedCount; i++) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
128 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
129 containedElem.AppendChild(CreateContainedUnitElement(containedUnits[i], doc)); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
130 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
131 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
132 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
133 return containedElem; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
134 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
135 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
136 private XmlElement CreateContainedUnitElement(Unit unit, XmlDocument doc) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
137 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
138 XmlElement containedUnitElem = doc.CreateElement("containedUnit"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
139 containedUnitElem.SetAttribute("containedID", XmlTools.GetAsciiXmlIdForString(unit.ID)); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
140 return containedUnitElem; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
141 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
142 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
143 } |