Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs @ 322:3e9b0603afad
Re #338: WarFoundry.API - Save System Data
* Alter visibility in GameSystem saver to allow for re-use of code
* Add encoding to XML
* Make use of GameSystem saver within FileSaver
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 09 Mar 2011 20:32:08 +0000 |
parents | 40a2df1f629a |
children | e0580a009e75 |
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 (WarFoundryXmlGameSystemSaver.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 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 public class WarFoundryXmlGameSystemSaver : IWarFoundryGameSystemSaver |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 public const string GAMESYSTEM_FILE_EXTENSION = ".system"; |
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 public bool Save(GameSystem toSave, string savePath) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 bool success = false; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 ZipFile file = null; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 if (!savePath.EndsWith(GAMESYSTEM_FILE_EXTENSION)) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 savePath = savePath + GAMESYSTEM_FILE_EXTENSION; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 try |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 file = ZipFile.Create(savePath); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 file.BeginUpdate(); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 file.Add(new StringZipEntrySource(CreateXmlString(toSave)), "data.systemx"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 file.CommitUpdate(); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 success = true; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 finally |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 if (file != null) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 file.Close(); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 } |
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 success; |
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 |
322
3e9b0603afad
Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents:
316
diff
changeset
|
53 public string CreateXmlString(WarFoundryObject toSave) |
316
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 string xmlString = ""; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 if (toSave is GameSystem) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
59 xmlString = CreateGameSystemXmlString((GameSystem)toSave); |
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 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
62 return xmlString; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 } |
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 private string CreateGameSystemXmlString(GameSystem toSave) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
66 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
67 XmlDocument doc = new XmlDocument(); |
322
3e9b0603afad
Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents:
316
diff
changeset
|
68 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
|
69 doc.AppendChild(declaration); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
70 XmlSchema schema = new XmlSchema(); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
71 schema.Namespaces.Add("", "http://ibboard.co.uk/warfoundry/system"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
72 schema.Namespaces.Add("cats", "http://ibboard.co.uk/warfoundry/cats"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
73 doc.Schemas.Add(schema); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
74 XmlElement root = doc.CreateElement("system"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
75 root.SetAttribute("xmlns", "http://ibboard.co.uk/warfoundry/system"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
76 root.SetAttribute("xmlns:cats", "http://ibboard.co.uk/warfoundry/cats"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
77 doc.AppendChild(root); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
78 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
|
79 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
|
80 root.SetAttribute("defaultArmySize", toSave.SystemArmyDefaultSize.ToString()); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
81 root.SetAttribute("warn", toSave.WarnOnError.ToString().ToLowerInvariant()); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
82 root.SetAttribute("allowAllies", toSave.AllowAllies.ToString().ToLowerInvariant()); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
83 XmlElement cats = doc.CreateElement("categories"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
84 root.AppendChild(cats); |
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 foreach (Category cat in toSave.Categories) |
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 cats.AppendChild(CreateCategoryElement(cat, doc)); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
89 } |
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 XmlElement sysStatsList = doc.CreateElement("sysStatsList"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
92 sysStatsList.SetAttribute("defaultStats", XmlTools.GetAsciiXmlIdForString(toSave.StandardSystemStatsID)); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
93 root.AppendChild(sysStatsList); |
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 foreach(SystemStats stats in toSave.SystemStats) |
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 sysStatsList.AppendChild(CreateSystemStatsElement(stats, doc)); |
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 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
100 return doc.OuterXml; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
101 } |
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 private XmlElement CreateCategoryElement(Category cat, XmlDocument doc) |
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 XmlElement catElem = doc.CreateElement("cats:cat"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
106 catElem.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(cat.ID)); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
107 catElem.SetAttribute("name", (cat.HasDefaultName() ? "" : cat.Name)); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
108 if (cat.MinimumPoints > 0) |
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 catElem.SetAttribute("minPoints", cat.MaximumPercentage.ToString()); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
111 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
112 if (cat.MaximumPoints < 100) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
113 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
114 catElem.SetAttribute("maxPoints", cat.MaximumPercentage.ToString()); |
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 if(cat.MinimumPercentage > 0) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
117 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
118 catElem.SetAttribute("minPercentage", cat.MaximumPercentage.ToString()); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
119 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
120 if(cat.MaximumPercentage < 100) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
121 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
122 catElem.SetAttribute("maxPercentage", cat.MaximumPercentage.ToString()); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
123 } |
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 return catElem; |
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 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
128 private XmlElement CreateSystemStatsElement(SystemStats stats, XmlDocument doc) |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
129 { |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
130 XmlElement statsElem = doc.CreateElement("sysStats"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
131 statsElem.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(stats.ID)); |
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 foreach(StatSlot stat in stats.StatSlots) |
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 statsElem.AppendChild(CreateSystemStatElement(stat, doc)); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
136 } |
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 return statsElem; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
139 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
140 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
141 private XmlElement CreateSystemStatElement(StatSlot stat, XmlDocument doc) |
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 XmlElement statElem = doc.CreateElement("sysStat"); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
144 statElem.SetAttribute("name", stat.Name); |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
145 |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
146 return statElem; |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
147 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
148 } |
40a2df1f629a
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
149 } |