Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs @ 82:3ea0ab04352b
* Fix line terminators
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 27 Jun 2009 18:59:49 +0000 |
parents | e6200220ece3 |
children | 2f3cafb69799 |
rev | line source |
---|---|
52 | 1 // This file (WarFoundryXmlGameSystemFactory.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 under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. | |
4 // | |
5 | |
6 using System; | |
7 using System.Collections.Generic; | |
8 using System.Xml; | |
9 using ICSharpCode.SharpZipLib.Zip; | |
10 using IBBoard.Logging; | |
11 using IBBoard.Xml; | |
12 using IBBoard.WarFoundry.API.Objects; | |
13 | |
14 namespace IBBoard.WarFoundry.API.Factories.Xml | |
15 { | |
16 /// <summary> | |
17 /// A sub-factory specifically for loading GameSystems from WarFoundry XML files | |
18 /// </summary> | |
19 public class WarFoundryXmlGameSystemFactory : AbstractStagedLoadedSubFactory | |
20 { | |
21 private Dictionary<GameSystem, XmlDocument> extraData = new Dictionary<GameSystem, XmlDocument>(); | |
22 | |
23 public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory) : base(factory) | |
24 { | |
25 } | |
26 | |
27 private void StoreExtraData(GameSystem wfObject, XmlElement elem) | |
28 { | |
29 extraData[wfObject] = elem.OwnerDocument; | |
30 } | |
31 | |
32 private XmlDocument GetExtraData(GameSystem obj) | |
33 { | |
34 XmlDocument extra = null; | |
35 extraData.TryGetValue(obj, out extra); | |
36 return extra; | |
37 } | |
38 | |
39 public GameSystem CreateSystemFromElement(ZipFile file, XmlElement elem) | |
40 { | |
41 string id = elem.GetAttribute("id"); | |
42 string name = elem.GetAttribute("name"); | |
43 GameSystem system = new GameSystem(id, name, mainFactory); | |
44 StoreExtraData(system, elem); | |
45 return system; | |
46 } | |
47 | |
48 public void CompleteLoading(GameSystem system) | |
49 { | |
50 if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(system)) | |
51 { | |
52 return; | |
53 } | |
54 | |
55 system.SetAsLoading(); | |
56 XmlDocument extraData = GetExtraData(system); | |
57 LoadCategoriesForSystem(system, extraData); | |
58 XmlElement statsElem = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system/system:sysStatsList"); | |
59 string defaultStatsID = statsElem.GetAttribute("defaultStats"); | |
60 LoadSystemStatsForSystem(system, extraData); | |
61 system.StandardSystemStatsID = defaultStatsID; | |
62 XmlElement systemElement = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system"); | |
63 system.WarnOnError = XmlTools.GetBoolValueFromAttribute(systemElement, "warn"); | |
64 system.AllowAllies = XmlTools.GetBoolValueFromAttribute(systemElement, "allowAllies"); | |
65 LogNotifier.DebugFormat(GetType(), "Completed loading of GameSystem with ID {0}", system.ID); | |
66 LogNotifier.DebugFormat(GetType(), "GameSystem with ID {0} default stats: {1}", system.ID, system.StandardSystemStatsID); | |
67 system.SetAsFullyLoaded(); | |
68 } | |
69 | |
70 private void LoadCategoriesForSystem(GameSystem system, XmlNode elem) | |
71 { | |
72 foreach (XmlElement cat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:categories/cat:cat")) | |
73 { | |
74 system.AddCategory(CreateCategoryFromElement(cat)); | |
75 } | |
76 } | |
77 | |
78 private void LoadSystemStatsForSystem(GameSystem system, XmlNode elem) | |
79 { | |
80 foreach (XmlElement stats in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:sysStatsList/system:sysStats")) | |
81 { | |
82 SystemStats sysStats = CreateSystemStatsFromElement(stats); | |
83 system.AddSystemStats(sysStats); | |
84 } | |
85 } | |
86 | |
87 private SystemStats CreateSystemStatsFromElement(XmlElement elem) | |
88 { | |
67
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
89 SystemStats sysStats = new SystemStats(elem.GetAttribute("id")); |
52 | 90 |
53 | 91 foreach (XmlElement slot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "system:sysStat")) |
52 | 92 { |
67
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
93 sysStats.AddStatSlot(slot.GetAttribute("name")); |
52 | 94 } |
67
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
95 |
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
96 return sysStats; |
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
97 } |
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
98 } |
52 | 99 } |