Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/Race.cs @ 13:ad8eaed12e66
Re #9 - Load in smaller methods
* Fix earlier commit that caused exceptions about already being in dictionary for first object by caching before adding
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 22 Jan 2009 20:26:08 +0000 |
parents | 5a1df00b0359 |
children | 0770e5cbba7c |
rev | line source |
---|---|
0 | 1 // Race.cs |
2 // | |
3 // Copyright (C) 2008 IBBoard | |
4 // | |
5 // This library is free software; you can redistribute it and/or | |
6 // modify it under the terms of the GNU Lesser General Public | |
7 // License as published by the Free Software Foundation; either | |
8 // version 2.1 of the License, or (at your option) any later version. | |
9 // | |
10 // This library is distributed in the hope that it will be useful, | |
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 // Lesser General Public License for more details. | |
14 // | |
15 // You should have received a copy of the GNU Lesser General Public | |
16 // License along with this library; if not, write to the Free Software | |
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 // | |
19 // | |
20 | |
21 using System; | |
22 using System.Collections.Generic; | |
23 using System.IO; | |
24 using System.Xml; | |
25 using IBBoard.IO; | |
26 using IBBoard.WarFoundry.API.Factories; | |
27 | |
28 namespace IBBoard.WarFoundry.API.Objects | |
29 { | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
30 public class Race : WarFoundryStagedLoadingObject |
0 | 31 { |
32 public static string SYSTEM_DEFAULT_RACE_ID = "GameDefault"; | |
33 | |
34 private string subID; | |
35 private string systemID; | |
36 private GameSystem system; | |
37 private Dictionary<Category, Dictionary<string, UnitType>> unitTypesByCat; | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
38 private Dictionary<string, UnitType> unitTypes = new Dictionary<string,UnitType>(); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
39 private Dictionary<string, EquipmentItem> equipment = new Dictionary<string,EquipmentItem>(); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
40 private Dictionary<string, Ability> abilities = new Dictionary<string,Ability>(); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
41 private Dictionary<string, Category> categories = new Dictionary<string,Category>(); |
0 | 42 |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
43 public Race(string raceID, string raceName, string gameSystemID, IWarFoundryFactory creatingFactory) : this(raceID, "", raceName, gameSystemID, creatingFactory) |
0 | 44 { |
45 } | |
46 | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
47 public Race(string raceID, string raceSubID, string raceName, string gameSystemID, IWarFoundryFactory creatingFactory) : base(raceID + (raceSubID!="" ? "_"+raceSubID : ""), raceName, creatingFactory) |
0 | 48 { |
49 subID = (raceSubID == null ? "" : raceSubID); | |
50 systemID = gameSystemID; | |
51 } | |
52 | |
53 public string SubID | |
54 { | |
55 get { return subID; } | |
56 set { subID = (value == null ? "" : value.Trim()); } | |
57 } | |
58 | |
59 public GameSystem GameSystem | |
60 { | |
61 get | |
62 { | |
63 if (system == null) | |
64 { | |
65 system = WarFoundryLoader.GetDefault().GetGameSystem(systemID); | |
66 } | |
67 | |
68 return system; | |
69 } | |
70 set | |
71 { | |
72 if (value == null) | |
73 { | |
74 throw new ArgumentException("Game system for a race cannot be null"); | |
75 } | |
76 | |
77 system = value; | |
78 } | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
79 } |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
80 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
81 public void AddCategory(Category cat) |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
82 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
83 categories[cat.ID] = cat; |
0 | 84 } |
85 | |
86 /// <summary> | |
87 /// Gets a category from its ID. Attempts to get the category from the race's overrides, or else it falls back to getting the Game System's category with that ID. | |
88 /// </summary> | |
89 /// <param name="id"> | |
90 /// The ID of the category to get | |
91 /// </param> | |
92 /// <returns> | |
93 /// The <code>Category</code> with the specified ID, or null if one doesn't exist. | |
94 /// </returns> | |
95 public Category GetCategory(string id) | |
96 { | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
97 EnsureFullyLoaded(); |
0 | 98 Category cat = null; |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
99 categories.TryGetValue(id, out cat); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
100 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
101 if (cat == null) |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
102 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
103 cat = GameSystem.GetCategory(id); |
0 | 104 } |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
105 |
0 | 106 return cat; |
107 } | |
108 | |
109 public Category[] Categories | |
110 { | |
111 get | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
112 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
113 EnsureFullyLoaded(); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
114 Category[] cats; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
115 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
116 if (!HasCategoryOverrides()) |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
117 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
118 cats = GameSystem.Categories; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
119 } |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
120 else |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
121 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
122 cats = DictionaryToArrayConverter.Convert<string, Category>(categories); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
123 } |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
124 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
125 return cats; |
0 | 126 } |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
127 } |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
128 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
129 public bool HasCategoryOverrides() |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
130 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
131 return categories.Count > 0; |
0 | 132 } |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
133 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
134 public void AddEquipmentItem(EquipmentItem item) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
135 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
136 //TODO: Throw DuplicateItemException |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
137 equipment.Add(item.ID, item); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
138 } |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
139 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
140 [Obsolete("Use AddEquipmentItem method instead")] |
0 | 141 public void SetEquipmentItems(Dictionary<string, EquipmentItem> items) |
142 { | |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
143 foreach (EquipmentItem item in items.Values) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
144 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
145 AddEquipmentItem(item); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
146 } |
0 | 147 } |
148 | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
149 public EquipmentItem GetEquipmentItem(string id) |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
150 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
151 EnsureFullyLoaded(); |
0 | 152 return (EquipmentItem)equipment[id]; |
153 } | |
154 | |
155 public List<EquipmentItem> GetEquipmentList() | |
156 { | |
157 List<EquipmentItem> items = new List<EquipmentItem>(); | |
158 | |
159 foreach (EquipmentItem item in equipment.Values) | |
160 { | |
161 items.Add(item); | |
162 } | |
163 | |
164 return items; | |
165 } | |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
166 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
167 public void AddUnitType(UnitType type) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
168 { |
13 | 169 CacheUnitType(type); |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
170 unitTypes.Add(type.ID, type); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
171 } |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
172 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
173 [Obsolete("Use AddUnitType method instead")] |
0 | 174 public void SetUnitTypes(Dictionary<string, UnitType> types) |
175 { | |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
176 foreach (UnitType type in types.Values) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
177 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
178 AddUnitType(type); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
179 } |
0 | 180 } |
181 | |
182 public UnitType[] GetUnitTypes(Category cat) | |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
183 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
184 BuildUnitTypesByCategoryCache(); |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
185 Dictionary<string, UnitType> unitTypesDictionary; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
186 unitTypesByCat.TryGetValue(cat, out unitTypesDictionary); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
187 UnitType[] unitTypesArray; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
188 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
189 if (unitTypesDictionary == null) |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
190 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
191 unitTypesArray = new UnitType[0]; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
192 } |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
193 else |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
194 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
195 unitTypesArray = DictionaryToArrayConverter.Convert<string, UnitType>(unitTypesDictionary); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
196 } |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
197 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
198 return unitTypesArray; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
199 } |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
200 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
201 private void CacheUnitType(UnitType unit) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
202 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
203 BuildUnitTypesByCategoryCache(); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
204 Dictionary<string,UnitType> catUnitTypes; |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
205 unitTypesByCat.TryGetValue(unit.MainCategory, out catUnitTypes); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
206 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
207 if (catUnitTypes == null) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
208 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
209 throw new InvalidFileException(String.Format("Unit type {0} with name {1} is a unit of an undefined category", unit.ID, unit.Name)); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
210 } |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
211 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
212 catUnitTypes.Add(unit.ID, unit); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
213 } |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
214 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
215 private void BuildUnitTypesByCategoryCache() |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
216 { |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
217 if (unitTypesByCat == null) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
218 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
219 DoBuildUnitTypesByCategoryCache(); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
220 } |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
221 } |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
222 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
223 private void DoBuildUnitTypesByCategoryCache() |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
224 { |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
225 unitTypesByCat = new Dictionary<Category,Dictionary<string,UnitType>>(); |
0 | 226 |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
227 foreach (Category category in Categories) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
228 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
229 unitTypesByCat.Add(category, new Dictionary<string, UnitType>()); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
230 } |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
231 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
232 foreach (UnitType unit in unitTypes.Values) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
233 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
234 CacheUnitType(unit); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
235 } |
0 | 236 } |
237 | |
238 public UnitType GetUnitType(string id) | |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
239 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
240 UnitType type = null; |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
241 unitTypes.TryGetValue(id, out type); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
242 return type; |
0 | 243 } |
244 | |
245 public List<Ability> GetAbilityList() | |
246 { | |
247 List<Ability> items = new List<Ability>(); | |
248 | |
249 foreach (Ability ability in abilities.Values) | |
250 { | |
251 items.Add(ability); | |
252 } | |
253 | |
254 return items; | |
255 } | |
256 | |
257 public void SetAbilities(Dictionary<string, Ability> newAbilities) | |
258 { | |
259 abilities = newAbilities; | |
260 } | |
261 | |
262 public Ability GetAbility(string id) | |
263 { | |
264 Ability ability = null; | |
265 abilities.TryGetValue(id, out ability); | |
266 return ability; | |
267 } | |
268 | |
269 protected virtual Dictionary<string, UnitType> RaceUnitTypes | |
270 { | |
271 get { return RaceRawUnitTypes; } | |
272 set { RaceRawUnitTypes = value; } | |
273 } | |
274 | |
275 protected virtual Dictionary<string, EquipmentItem> RaceEquipment | |
276 { | |
277 get { return RaceRawEquipment; } | |
278 set { RaceRawEquipment = value; } | |
279 } | |
280 | |
281 protected virtual Dictionary<string, Ability> RaceAbilities | |
282 { | |
283 get { return RaceRawAbilities; } | |
284 set { RaceRawAbilities = value; } | |
285 } | |
286 | |
287 protected Dictionary<string, UnitType> RaceRawUnitTypes | |
288 { | |
289 get { return unitTypes; } | |
290 set { unitTypes = value; } | |
291 } | |
292 | |
293 protected Dictionary<string, EquipmentItem> RaceRawEquipment | |
294 { | |
295 get { return equipment; } | |
296 set { equipment = value; } | |
297 } | |
298 | |
299 protected Dictionary<string, Ability> RaceRawAbilities | |
300 { | |
301 get { return abilities; } | |
302 set { abilities = value; } | |
303 } | |
304 } | |
305 } |