Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate 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 |
rev | line source |
---|---|
116
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (WarFoundryXmlArmyParser.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System; |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System.Xml; |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using IBBoard.Xml; |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 using ICSharpCode.SharpZipLib.Zip; |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 using IBBoard.WarFoundry.API.Objects; |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 namespace IBBoard.WarFoundry.API.Factories.Xml |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 { |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 public class WarFoundryXmlArmyParser |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 { |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 private ZipFile file; |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 private XmlElement elem; |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 private Army army; |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 public WarFoundryXmlArmyParser(ZipFile file, XmlElement elem) |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 { |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 this.file = file; |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 this.elem = elem; |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 } |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 public Army GetArmy() |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 { |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 if (army == null) |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 { |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 ParseArmy(); |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 } |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 return army; |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 } |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 private void ParseArmy() |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 { |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 string name = elem.GetAttribute("name"); |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 string systemID = elem.GetAttribute("system"); |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 GameSystem system = WarFoundryLoader.GetDefault().GetGameSystem(systemID); |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 if (system == null) |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 { |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 throw new RequiredDataMissingException(file.Name, "gameSystem", systemID); |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 } |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 string raceID = elem.GetAttribute("race"); |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 Race race = WarFoundryLoader.GetDefault().GetRace(system, raceID); |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 if (race == null) |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 { |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 throw new RequiredDataMissingException(file.Name, "race", raceID); |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 } |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 int points = XmlTools.GetIntValueFromAttribute(elem, "maxPoints"); |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 army = new Army(race, name, points, file); |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 //TODO: Complete loading of army |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 } |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 } |
2010a7e8bf9a
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
59 } |