comparison api/Objects/Race.cs @ 258:3b395ab8784d

Re #270: Add multiple categories to API * Make Race cache new units against each category
author IBBoard <dev@ibboard.co.uk>
date Wed, 19 May 2010 19:23:29 +0000
parents a54da5a8b5bb
children cd657faa0c05 8981fc45fe17
comparison
equal deleted inserted replaced
257:435eb28b4549 258:3b395ab8784d
160 } 160 }
161 161
162 private void CacheUnitType(UnitType unit) 162 private void CacheUnitType(UnitType unit)
163 { 163 {
164 BuildUnitTypesByCategoryCache(); 164 BuildUnitTypesByCategoryCache();
165 Dictionary<string,UnitType> catUnitTypes; 165
166 unitTypesByCat.TryGetValue(unit.MainCategory, out catUnitTypes); 166 foreach (Category cat in unit.Categories)
167 167 {
168 if (catUnitTypes == null) 168 Dictionary<string, UnitType> catUnitTypes = DictionaryUtils.GetValue(unitTypesByCat, cat);
169 { 169
170 throw new InvalidFileException(String.Format("Unit type {0} with name {1} is a unit of an undefined category", unit.ID, unit.Name)); 170 if (catUnitTypes == null)
171 } 171 {
172 172 throw new InvalidFileException(String.Format("Unit type {0} with name {1} is a unit of an undefined category ({2})", unit.ID, unit.Name, cat.ID));
173 catUnitTypes.Add(unit.ID, unit); 173 }
174
175 catUnitTypes.Add(unit.ID, unit);
176 }
174 } 177 }
175 178
176 private void BuildUnitTypesByCategoryCache() 179 private void BuildUnitTypesByCategoryCache()
177 { 180 {
178 if (unitTypesByCat == null) 181 if (unitTypesByCat == null)