Mercurial > repos > IBBoard.WarFoundry.API
comparison api/Factories/Xml/WarFoundryXmlArmyParser.cs @ 116:2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
* Separate out army parsing to a separate class to make unit loading easier
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 22 Aug 2009 19:42:04 +0000 |
parents | |
children | 093ee2da0f6e |
comparison
equal
deleted
inserted
replaced
115:d0c60b3204c1 | 116:2010a7e8bf9a |
---|---|
1 // This file (WarFoundryXmlArmyParser.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard | |
2 // | |
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. | |
4 | |
5 using System; | |
6 using System.Xml; | |
7 using IBBoard.Xml; | |
8 using ICSharpCode.SharpZipLib.Zip; | |
9 using IBBoard.WarFoundry.API.Objects; | |
10 | |
11 namespace IBBoard.WarFoundry.API.Factories.Xml | |
12 { | |
13 public class WarFoundryXmlArmyParser | |
14 { | |
15 private ZipFile file; | |
16 private XmlElement elem; | |
17 private Army army; | |
18 | |
19 public WarFoundryXmlArmyParser(ZipFile file, XmlElement elem) | |
20 { | |
21 this.file = file; | |
22 this.elem = elem; | |
23 } | |
24 | |
25 public Army GetArmy() | |
26 { | |
27 if (army == null) | |
28 { | |
29 ParseArmy(); | |
30 } | |
31 | |
32 return army; | |
33 } | |
34 | |
35 private void ParseArmy() | |
36 { | |
37 string name = elem.GetAttribute("name"); | |
38 string systemID = elem.GetAttribute("system"); | |
39 GameSystem system = WarFoundryLoader.GetDefault().GetGameSystem(systemID); | |
40 | |
41 if (system == null) | |
42 { | |
43 throw new RequiredDataMissingException(file.Name, "gameSystem", systemID); | |
44 } | |
45 | |
46 string raceID = elem.GetAttribute("race"); | |
47 Race race = WarFoundryLoader.GetDefault().GetRace(system, raceID); | |
48 | |
49 if (race == null) | |
50 { | |
51 throw new RequiredDataMissingException(file.Name, "race", raceID); | |
52 } | |
53 | |
54 int points = XmlTools.GetIntValueFromAttribute(elem, "maxPoints"); | |
55 army = new Army(race, name, points, file); | |
56 //TODO: Complete loading of army | |
57 } | |
58 } | |
59 } |