comparison api/Factories/Xml/WarFoundryXmlFactory.cs @ 34:b28be912adab

Re #32 - Migrate to schema * Remove use of Categories (now just has a single category) * Fix infinite loop of trying to load files by adding a "is loading" flag * Fix invalid setting of MinSize to MaxNumber when we're testing if MinSize > MaxSize
author IBBoard <dev@ibboard.co.uk>
date Sun, 15 Mar 2009 16:07:52 +0000
parents 6b9d37f14a14
children 465a215a21a2
comparison
equal deleted inserted replaced
33:4308424b4145 34:b28be912adab
4 4
5 using System; 5 using System;
6 using System.IO; 6 using System.IO;
7 using System.Xml; 7 using System.Xml;
8 using System.Xml.Schema; 8 using System.Xml.Schema;
9 using System.Xml.XPath;
9 using System.Collections.Generic; 10 using System.Collections.Generic;
10 using System.Text; 11 using System.Text;
11 using IBBoard; 12 using IBBoard;
12 using IBBoard.IO; 13 using IBBoard.IO;
13 using IBBoard.Lang; 14 using IBBoard.Lang;
185 { 186 {
186 LogNotifier.DebugFormat(GetType(), "Object of type GameSystem with ID {0} is already fully loaded", system.ID); 187 LogNotifier.DebugFormat(GetType(), "Object of type GameSystem with ID {0} is already fully loaded", system.ID);
187 return; 188 return;
188 } 189 }
189 190
191 if (system.IsLoading)
192 {
193 LogNotifier.WarnFormat(GetType(), "Object of type GameSystem with ID {0} is already being loaded", system.ID);
194 return;
195 }
196
197 system.SetAsLoading();
198
190 XmlNode elem = GetExtraData(system); 199 XmlNode elem = GetExtraData(system);
191 XmlNode catsElem = elem.FirstChild; 200 XmlNode catsElem = elem.FirstChild;
192 LoadCategoriesForSystem(system, elem); 201 LoadCategoriesForSystem(system, elem);
193 202
194 XmlElement statsElem = (XmlElement)catsElem.NextSibling; 203 XmlElement statsElem = (XmlElement)catsElem.NextSibling;
224 if (race.IsFullyLoaded) 233 if (race.IsFullyLoaded)
225 { 234 {
226 LogNotifier.DebugFormat(GetType(), "Object of type Race with ID {0} is already fully loaded", race.ID); 235 LogNotifier.DebugFormat(GetType(), "Object of type Race with ID {0} is already fully loaded", race.ID);
227 return; 236 return;
228 } 237 }
238
239 if (race.IsLoading)
240 {
241 LogNotifier.WarnFormat(GetType(), "Object of type Race with ID {0} is already being loaded", race.ID);
242 return;
243 }
244
245 race.SetAsLoading();
229 246
230 XmlNode elem = GetExtraData(race); 247 XmlNode elem = GetExtraData(race);
231 XmlNode colNode = elem.FirstChild; 248 XmlNode colNode = elem.FirstChild;
232 249
233 foreach (XmlElement node in colNode.ChildNodes) 250 foreach (XmlElement node in colNode.ChildNodes)
385 type.MinSize = GetIntValueFromAttribute(elem, "minSize"); 402 type.MinSize = GetIntValueFromAttribute(elem, "minSize");
386 type.MaxSize = GetIntValueFromAttribute(elem, "maxSize"); 403 type.MaxSize = GetIntValueFromAttribute(elem, "maxSize");
387 //TODO: Add base size 404 //TODO: Add base size
388 type.CostPerTrooper = GetIntValueFromAttribute(elem, "points"); 405 type.CostPerTrooper = GetIntValueFromAttribute(elem, "points");
389 type.BaseUnitCost = GetIntValueFromAttribute(elem, "unitPoints"); 406 type.BaseUnitCost = GetIntValueFromAttribute(elem, "unitPoints");
390
391 XmlNode node = elem.FirstChild;
392
393 foreach(XmlElement cat in node.ChildNodes)
394 {
395 string catID = cat.GetAttribute("catID");
396 type.AddCategory(parentRace.GetCategory(catID));
397 }
398
399 string mainCatID = elem.GetAttribute("cat"); 407 string mainCatID = elem.GetAttribute("cat");
400 type.MainCategory = parentRace.GetCategory(mainCatID); 408 type.MainCategory = parentRace.GetCategory(mainCatID);
401 node = node.NextSibling; 409 XmlNodeList nodes = elem.SelectNodes("stats");
410 XmlNode node = nodes.Item(0);
402 type.UnitStats = ParseUnitStats((XmlElement)node, system); 411 type.UnitStats = ParseUnitStats((XmlElement)node, system);
403 //TODO: Add unit requirements 412 //TODO: Add unit requirements
404 413 LogNotifier.Debug(GetType(), "Loaded "+type.Name);
405 return type; 414 return type;
406 } 415 }
407 416
408 private Stats ParseUnitStats(XmlElement elem, GameSystem system) 417 private Stats ParseUnitStats(XmlElement elem, GameSystem system)
409 { 418 {