annotate api/Factories/Xml/WarFoundryXmlFactory.cs @ 0:520818033bb6

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 150a5669cd7b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // WarFoundryXmlFactory.cs
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // Copyright (C) 2007 IBBoard
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 //
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 // This library is free software; you can redistribute it and/or
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 // modify it under the terms of the GNU Lesser General Public
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 // License version 2.1 of the License as published by the Free
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 // Software Foundation.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 //
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 // This library is distributed in the hope that it will be useful,
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 // Lesser General Public License for more details.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 //
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 // You should have received a copy of the GNU Lesser General Public
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 // License along with this library; if not, write to the Free Software
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 //
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 //
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 using System;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 using System.IO;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 using System.Xml;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 using System.Xml.Schema;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 using System.Collections.Generic;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 using System.Text;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 using IBBoard;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 using IBBoard.IO;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 using IBBoard.Lang;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 using IBBoard.Logging;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 using IBBoard.Xml;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 using IBBoard.WarFoundry.API.Requirements;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 using IBBoard.WarFoundry.API.Objects;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 using ICSharpCode.SharpZipLib.Zip;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 namespace IBBoard.WarFoundry.API.Factories.Xml
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 /// Summary description for WarFoundryXmlFactory.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 public class WarFoundryXmlFactory : AbstractNativeWarFoundryFactory
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 private Dictionary<IWarFoundryObject, XmlDocument> extraData = new Dictionary<IWarFoundryObject, XmlDocument>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 private XmlResolver xmlResolver;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 public static AbstractNativeWarFoundryFactory CreateFactory()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 return new WarFoundryXmlFactory();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 protected WarFoundryXmlFactory() : base()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 xmlResolver = new IBBXmlResolver(Constants.ExecutablePath);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 protected override bool CheckCanFindArmyFileContent(ZipFile file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 return file.FindEntry("data.armyx", true) > -1;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 protected override bool CheckCanFindSystemFileContent(ZipFile file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 return file.FindEntry("data.systemx", true) > -1;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 protected override bool CheckCanFindRaceFileContent(ZipFile file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 return file.FindEntry("data.racex", true) > -1;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 protected XmlElement GetRootElementFromStream(Stream stream, WarFoundryXmlElementName elementName)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 XmlDocument doc = CreateXmlDocumentFromStream(stream);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 XmlElement elem = (XmlElement)doc.LastChild;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 if (!elem.Name.Equals(elementName.Value))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 throw new InvalidFileException(String.Format("Root element of XML was not valid. Expected {0} but got {1}", elementName.Value, elem.Name));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 return elem;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 protected override Stream GetArmyDataStream(ZipFile file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 return file.GetInputStream(file.FindEntry("data.armyx", true));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 protected override Army CreateArmyFromStream (ZipFile file, Stream dataStream)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.ARMY_ELEMENT);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 return CreateArmyFromElement(file, elem);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 private Army CreateArmyFromElement(ZipFile file, XmlElement elem)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 string name = elem.GetAttribute("name");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 string systemID = elem.GetAttribute("gameSystem");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 GameSystem system = WarFoundryLoader.GetDefault().GetGameSystem(systemID);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 string raceID = elem.GetAttribute("race");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 Race race = WarFoundryLoader.GetDefault().GetRace(system, raceID);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 string pointsString = elem.GetAttribute("maxPoints");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 int points = 0;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107 points = int.Parse(pointsString);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 throw new FormatException("Attribute 'maxPoints' of army '"+name+"' was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 Army army = new Army(race, name, points, file);//, this);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 extraData[army] = elem.OwnerDocument;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116 return army;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 protected override Stream GetGameSystemDataStream (ZipFile file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
121 return file.GetInputStream(file.FindEntry("data.systemx", true));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
122 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
123
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124 protected override GameSystem CreateGameSystemFromStream (ZipFile file, Stream dataStream)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126 XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.SYSTEM_ELEMENT);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
127 LogNotifier.Debug(GetType(), "Create GameSystem");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
128 return CreateSystemFromElement(file, elem);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
130
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 private GameSystem CreateSystemFromElement(ZipFile file, XmlElement elem)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
133 string id = elem.GetAttribute("id");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
134 string name = elem.GetAttribute("name");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
135 GameSystem system = new StagedLoadingGameSystem(id, name, this);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136 //system.SourceZipFile = file.;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 extraData[system] = elem.OwnerDocument;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
138 return system;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
140
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
141 protected override Stream GetRaceDataStream (ZipFile file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
142 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
143 return file.GetInputStream(file.FindEntry("data.racex", true));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
144 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
145
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
146 protected override Race CreateRaceFromStream (ZipFile file, Stream dataStream)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
148 XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.RACE_ELEMENT);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
149 LogNotifier.Debug(GetType(), "Create Race");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
150 return CreateRaceFromElement(file, elem);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
151 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
152
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
153 private Race CreateRaceFromElement(ZipFile file, XmlElement elem)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
154 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
155 string id = elem.GetAttribute("id");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
156 string subid = elem.GetAttribute("subid");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
157 string systemID = elem.GetAttribute("system");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158 string name = elem.GetAttribute("name");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
159 Race race = new StagedLoadingRace(id, subid, name, systemID, this);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
160 //race.SourceZipFile = file; //TODO reference source file
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
161 extraData[race] = elem.OwnerDocument;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
162 return race;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
163 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
164
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
165 /*public WarFoundryObject CreateObjectFromStream(ZipFile file, Stream stream)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
167 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
168 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
169 WarFoundryObject obj = LoadFileObjectFromElement(file, elem);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 if (obj != null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
172 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
173 extraData[obj] = doc;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
174 return obj;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
176 else
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
178 throw new InvalidFileException(String.Format(Translation.GetTranslation("ErrorInvalidXmlFile", "XML file '{0}' was not a loadable XML file. Please ensure it is a valid and supported WarFoundry XML file."), file.Name));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
179 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
180 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
181 catch (XmlSchemaException ex)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
182 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
183 throw new InvalidFileException(String.Format(Translation.GetTranslation("ErrorInvalidXmlFile", "Failed to parse invalid XML data file in {0}. Error at line {1} position {2}: {3}"), file.Name, ex.LineNumber, ex.LinePosition, ex.Message.Substring(0, ex.Message.IndexOf(".")+1)), ex);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
184 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
185 catch (InvalidFileException ex)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
186 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
187 throw new InvalidFileException(String.Format(Translation.GetTranslation("ErrorInvalidNamedXmlFile", "XML data file in '{0}' was not a valid XML file. It should contain three child nodes - XML definition, DocType and root node."), file.Name), ex);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
188 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
189 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
190
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
191 private WarFoundryObject LoadFileObjectFromElement(ZipFile file, XmlElement elem)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
192 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
193 WarFoundryObject obj = null;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
194
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
195 if (elem.Name.Equals(WarFoundryXmlElementName.SYSTEM_ELEMENT.Value))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
196 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
197 logger.Debug("Create GameSystem");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
198 obj = CreateSystemFromElement(file, elem);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
199 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
200 else if (elem.Name.Equals(WarFoundryXmlElementName.RACE_ELEMENT.Value))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
201 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
202 logger.Debug("Create Race");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
203 obj = CreateRaceFromElement(file, elem);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
204 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
205
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
206 return obj;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
207 }*/
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
208
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
209 public override void CompleteLoading(IWarFoundryStagedLoadObject obj)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
210 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
211 LogNotifier.DebugFormat(GetType(), "Complete loading of {0} with ID {1}", obj.GetType().Name, obj.ID);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
212
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
213 if (!obj.IsFullyLoaded)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
214 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
215 XmlDocument extra = extraData[obj];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
216
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
217 if (obj is GameSystem)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
218 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
219 GameSystem system = (GameSystem)obj;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
220 XmlNode elem = extra.LastChild;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
221
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
222 XmlNode catsElem = elem.FirstChild;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
223 Category[] cats;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
224 List<Category> catList = new List<Category>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
225 WarFoundryObject tempObj;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
226
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
227 foreach (XmlElement cat in catsElem.ChildNodes)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
228 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
229 tempObj = CreateObjectFromElement(cat);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
230
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
231 if (tempObj is Category)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
232 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
233 catList.Add((Category)tempObj);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
234 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
235 else
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
236 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
237 LogNotifier.WarnFormat(GetType(), "Object for string {0} was not of type Category", cat.OuterXml);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
238 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
239 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
240
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
241 cats = catList.ToArray();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
242 LogNotifier.DebugFormat(GetType(), "Found {0} categories", cats.Length);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
243
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
244 XmlElement statsElem = (XmlElement)catsElem.NextSibling;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
245 Dictionary<string, SystemStats> sysStats = CreateSystemStatsSetFromElement(statsElem);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
246 string defaultStatsID = statsElem.GetAttribute("defaultStats");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
247
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
248 LogNotifier.DebugFormat(GetType(), "Complete loading of {0}", system.Name);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
249 system.Categories = cats;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
250 system.SystemStats = new SystemStatsSet(sysStats);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
251 system.StandardSystemStatsID = defaultStatsID;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
252 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
253 else if (obj is Race)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
254 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
255 Race race = (Race)obj;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
256 XmlNode elem = extra.LastChild;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
257 XmlNode colNode = elem.FirstChild;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
258
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
259 Dictionary<string, UnitType> unitTypes = new Dictionary<string, UnitType>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
260
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
261 foreach (XmlElement node in colNode.ChildNodes)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
262 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
263 UnitType type = CreateUnitTypeFromElement(node, race, race.GameSystem);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
264 unitTypes.Add(type.ID, type);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
265 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
266
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
267 colNode = colNode.NextSibling;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
268 List<Category> catOverrides = new List<Category>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
269
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
270 if (colNode!=null && colNode.Name == WarFoundryXmlElementName.CATEGORIES_ELEMENT.Value)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
271 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
272 foreach (XmlElement node in colNode.ChildNodes)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
273 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
274 catOverrides.Add(CreateCategoryFromElement(node));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
275 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
276
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
277 colNode = colNode.NextSibling;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
278 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
279
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
280 Dictionary<string, EquipmentItem> raceEquipment = new Dictionary<string, EquipmentItem>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
281
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
282 if (colNode!=null && colNode.Name == WarFoundryXmlElementName.RACE_EQUIPMENT_ITEMS_ELEMENT.Value)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
283 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
284 foreach (XmlElement node in colNode.ChildNodes)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
285 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
286 EquipmentItem item = CreateEquipmentItemFromElement(node, race);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
287 raceEquipment.Add(item.ID, item);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
288 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
289 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
290
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
291 Dictionary<string, Ability> raceAbilities = new Dictionary<string, Ability>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
292 //TODO: Load abilities
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
293
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
294 LogNotifier.DebugFormat(GetType(), "Complete loading of {0}", race.Name);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
295 race.Categories = catOverrides.ToArray();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
296 race.SetUnitTypes(unitTypes);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
297 race.SetEquipmentItems(raceEquipment);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
298 race.SetAbilities(raceAbilities);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
299 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
300 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
301 else
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
302 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
303 LogNotifier.Debug(GetType(), "Object is already fully loaded");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
304 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
305 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
306
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
307 protected XmlDocument CreateXmlDocumentFromStream(Stream stream)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
308 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
309 XmlDocument doc = new XmlDocument();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
310 XmlReaderSettings settings = new XmlReaderSettings();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
311 settings.XmlResolver = xmlResolver;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
312 settings.ValidationType = ValidationType.DTD;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
313 settings.ProhibitDtd = false;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
314 settings.ValidationEventHandler+= new ValidationEventHandler(ValidationEventMethod);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
315 XmlReader reader = XmlReader.Create(stream, settings);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
316
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
317 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
318 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
319 doc.Load(reader);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
320 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
321 //Don't catch XMLSchemaExceptions - let them get thrown out
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
322 finally
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
323 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
324 reader.Close();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
325 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
326
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
327 if (doc.ChildNodes.Count!=3)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
328 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
329 throw new InvalidFileException(Translation.GetTranslation("ErrorInvalidXmlFile", "XML file was not a valid XML file. It should contain three child nodes - XML definition, DocType and root node."));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
330 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
331
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
332 return doc;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
333 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
334
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
335 protected XmlDocument CreateXmlDocumentFromString(string xmlString)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
336 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
337 XmlReaderSettings settings = new XmlReaderSettings();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
338 settings.XmlResolver = xmlResolver;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
339 settings.ValidationType = ValidationType.DTD;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
340 settings.ProhibitDtd = false;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
341 settings.ValidationEventHandler+= new ValidationEventHandler(ValidationEventMethod);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
342 XmlReader reader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(xmlString)), settings);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
343 XmlDocument doc = new XmlDocument();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
344
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
345 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
346 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
347 doc.Load(reader);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
348 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
349 catch(XmlSchemaException ex)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
350 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
351 throw new InvalidFileException(Translation.GetTranslation("ErrorInvalidXmlString", "Failed to parse invalid XML string"), ex);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
352 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
353 finally
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
354 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
355 //We might not need to make sure the memory stream is closed, but do it just in case
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
356 reader.Close();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
357 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
358
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
359 if (doc.ChildNodes.Count!=3)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
360 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
361 throw new InvalidFileException(String.Format(Translation.GetTranslation("ErrorInvalidXmlFile", "XML string was not a valid XML file. It should contain three child nodes - XML definition, DocType and root node.")));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
362 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
363
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
364 return doc;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
365 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
366
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
367 private WarFoundryObject CreateObjectFromElement(XmlElement elem)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
368 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
369 WarFoundryObject obj = null;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
370 LogNotifier.DebugFormat(GetType(), "Create object for <{0}>", elem.Name);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
371
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
372 if (elem.Name.Equals(WarFoundryXmlElementName.CATEGORY_ELEMENT.Value))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
373 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
374 LogNotifier.Debug(GetType(), "Create Category");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
375 obj = CreateCategoryFromElement(elem);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
376 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
377 else
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
378 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
379 LogNotifier.Debug(GetType(), "No match");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
380 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
381
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
382 return obj;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
383 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
384
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
385 private Category CreateCategoryFromElement(XmlElement elem)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
386 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
387 string id = elem.GetAttribute("id");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
388 string name = elem.GetAttribute("name");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
389 int minPc, maxPc, minPts, maxPts, minChoices, maxChoices, baseValue, incValue, incAmount;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
390
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
391 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
392 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
393 minPc = int.Parse(elem.GetAttribute("minPercentage"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
394 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
395 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
396 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
397 throw new FormatException("Attribute 'minPercentage' of category "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
398 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
399
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
400 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
401 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
402 maxPc = int.Parse(elem.GetAttribute("maxPercentage"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
403 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
404 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
405 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
406 throw new FormatException("Attribute 'maxPercentage' of category "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
407 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
408
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
409 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
410 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
411 minPts = int.Parse(elem.GetAttribute("minPoints"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
412 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
413 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
414 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
415 throw new FormatException("Attribute 'minPoints' of category "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
416 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
417
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
418 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
419 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
420 maxPts = int.Parse(elem.GetAttribute("maxPoints"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
421 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
422 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
423 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
424 throw new FormatException("Attribute 'maxPoints' of category "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
425 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
426
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
427 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
428 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
429 minChoices = int.Parse(elem.GetAttribute("minChoices"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
430 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
431 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
432 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
433 throw new FormatException("Attribute 'minChoices' of category "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
434 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
435
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
436 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
437 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
438 maxChoices = int.Parse(elem.GetAttribute("maxChoices"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
439 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
440 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
441 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
442 throw new FormatException("Attribute 'maxChoices' of category "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
443 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
444
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
445 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
446 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
447 baseValue = int.Parse(elem.GetAttribute("baseValue"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
448
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
449 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
450 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
451 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
452 throw new FormatException("Attribute 'baseValue' of category "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
453 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
454
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
455 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
456 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
457 incValue = int.Parse(elem.GetAttribute("incValue"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
458 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
459 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
460 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
461 throw new FormatException("Attribute 'incValue' of category "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
462 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
463
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
464 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
465 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
466 incAmount = int.Parse(elem.GetAttribute("incAmount"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
467 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
468 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
469 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
470 throw new FormatException("Attribute 'incAmount' of category "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
471 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
472
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
473 return new Category(id, name, minPts, maxPts, minPc, maxPc, minChoices, maxChoices, baseValue, incValue, incAmount);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
474 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
475
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
476 private UnitType CreateUnitTypeFromElement(XmlElement elem, Race parentRace, GameSystem system)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
477 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
478 string id = elem.GetAttribute("id");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
479 string name = elem.GetAttribute("typeName");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
480 string mainCatID = elem.GetAttribute("cat");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
481 int minNum, maxNum, minSize, maxSize, baseSize;//TODO: Add base size
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
482 float points, unitPoints;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
483 Stats stats;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
484 List<UnitRequirement> unitRequirements = new List<UnitRequirement>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
485 bool found = false;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
486 List<string> catIDs = new List<string>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
487 string catID;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
488
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
489 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
490 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
491 minNum = int.Parse(elem.GetAttribute("minNum"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
492 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
493 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
494 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
495 throw new FormatException("Attribute 'minNum' of unit "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
496 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
497
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
498 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
499 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
500 maxNum = int.Parse(elem.GetAttribute("maxNum"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
501 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
502 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
503 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
504 throw new FormatException("Attribute 'maxNum' of unit "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
505 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
506
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
507 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
508 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
509 minSize = int.Parse(elem.GetAttribute("minSize"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
510 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
511 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
512 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
513 throw new FormatException("Attribute 'minSize' of unit "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
514 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
515
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
516 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
517 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
518 maxSize = int.Parse(elem.GetAttribute("maxSize"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
519 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
520 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
521 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
522 throw new FormatException("Attribute 'maxSize' of unit "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
523 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
524
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
525 if (minSize > maxSize && maxSize!=-1)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
526 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
527 minSize = maxSize;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
528 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
529
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
530 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
531 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
532 points = int.Parse(elem.GetAttribute("points"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
533 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
534 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
535 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
536 throw new FormatException("Attribute 'points' of unit "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
537 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
538
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
539 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
540 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
541 unitPoints = int.Parse(elem.GetAttribute("unitPoints"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
542 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
543 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
544 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
545 throw new FormatException("Attribute 'trooperPoints' of unit "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
546 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
547
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
548 XmlNode node = elem.FirstChild;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
549
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
550 foreach(XmlElement cat in node.ChildNodes)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
551 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
552 catID = cat.GetAttribute("catID");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
553 catIDs.Add(catID);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
554
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
555 if (catID == mainCatID)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
556 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
557 found = true;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
558 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
559 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
560
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
561 if (!found)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
562 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
563 throw new InvalidFileException("The main cat "+mainCatID+" was not found in the list of categories for unit "+id);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
564 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
565
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
566 node = node.NextSibling;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
567 stats = ParseUnitStats((XmlElement)node, system);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
568 //TODO: Add unit requirements
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
569 UnitType type = new UnitType(id, name, mainCatID, catIDs.ToArray(), minNum, maxNum, minSize, maxSize, unitPoints, points, stats, unitRequirements.ToArray(), parentRace);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
570
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
571 return type;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
572 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
573
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
574 private Stats ParseUnitStats(XmlElement elem, GameSystem system)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
575 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
576 List<Stat> statsList = new List<Stat>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
577 String statsID = elem.GetAttribute("statSet");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
578 SystemStats statsSet;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
579
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
580 if (statsID == "")
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
581 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
582 statsSet = system.StandardSystemStats;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
583 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
584 else
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
585 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
586 statsSet = system.SystemStats[statsID];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
587 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
588
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
589 Stats stats = new Stats(statsSet);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
590
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
591 foreach (XmlElement stat in elem.ChildNodes)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
592 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
593 String statID = stat.GetAttribute("name");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
594 StatSlot slot = statsSet[statID];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
595
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
596 if (slot!=null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
597 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
598 statsList.Add(new Stat(slot, stat.InnerText));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
599 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
600 else
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
601 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
602 throw new InvalidFileException("The stat "+statID+" was not found in stats set "+statsID);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
603 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
604 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
605
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
606 stats.SetStats(statsList);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
607
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
608 return stats;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
609 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
610
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
611 private Dictionary<string, SystemStats> CreateSystemStatsSetFromElement(XmlElement elem)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
612 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
613 Dictionary<string, SystemStats> dict = new Dictionary<string,SystemStats>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
614
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
615 foreach (XmlElement stats in elem.ChildNodes)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
616 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
617 SystemStats sysStats = CreateSystemStatsFromElement(stats);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
618 dict.Add(sysStats.ID, sysStats);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
619 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
620
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
621 return dict;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
622 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
623
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
624 private SystemStats CreateSystemStatsFromElement(XmlElement elem)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
625 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
626 List<StatSlot> slots = new List<StatSlot>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
627 string id = elem.GetAttribute("id");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
628
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
629 foreach (XmlElement slot in elem.ChildNodes)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
630 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
631 StatSlot statSlot = new StatSlot(slot.GetAttribute("name"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
632 slots.Add(statSlot);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
633 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
634
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
635 return new SystemStats(id, slots.ToArray());
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
636 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
637
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
638 private EquipmentItem CreateEquipmentItemFromElement(XmlElement elem, Race race)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
639 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
640 string id = elem.GetAttribute("id");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
641 string name = elem.GetAttribute("name");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
642 float cost = 0, min = 0, max = 0;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
643 ArmourType armourType;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
644
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
645 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
646 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
647 cost = float.Parse(elem.GetAttribute("cost"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
648 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
649 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
650 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
651 throw new FormatException("Attribute 'cost' of equipment item "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
652 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
653
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
654 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
655 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
656 min = float.Parse(elem.GetAttribute("min"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
657 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
658 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
659 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
660 throw new FormatException("Attribute 'min' of equipment item "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
661 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
662
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
663 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
664 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
665 max = float.Parse(elem.GetAttribute("max"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
666 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
667 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
668 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
669 throw new FormatException("Attribute 'max' of equipment item "+id+" was not a valid number");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
670 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
671
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
672 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
673 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
674 armourType = (ArmourType)Enum.Parse(typeof(ArmourType), elem.GetAttribute("armourType"));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
675 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
676 catch(FormatException)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
677 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
678 throw new InvalidFileException("Attribute 'armourType' of equipment "+id+" was not a valid value from the enumeration");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
679 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
680
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
681 if (elem.ChildNodes.Count>0)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
682 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
683 //It has stats!
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
684 //TODO: Parse equipment stats
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
685 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
686
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
687 return new EquipmentItem(id, name, cost, min, max, armourType, race);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
688 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
689
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
690 private void ValidationEventMethod(object sender, ValidationEventArgs e)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
691 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
692 //TODO: Fire a validation failure event
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
693 LogNotifier.WarnFormat(GetType(), "Validation Error: {0}", e.Message);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
694 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
695 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
696 }