Mercurial > repos > snowblizz-super-API-ideas
changeset 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 | 4308424b4145 |
children | 9cac51553fd1 |
files | api/Factories/Xml/WarFoundryXmlFactory.cs api/Objects/UnitType.cs api/Objects/WarFoundryStagedLoadingObject.cs |
diffstat | 3 files changed, 36 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlFactory.cs Sun Mar 15 15:10:02 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlFactory.cs Sun Mar 15 16:07:52 2009 +0000 @@ -6,6 +6,7 @@ using System.IO; using System.Xml; using System.Xml.Schema; +using System.Xml.XPath; using System.Collections.Generic; using System.Text; using IBBoard; @@ -187,6 +188,14 @@ return; } + if (system.IsLoading) + { + LogNotifier.WarnFormat(GetType(), "Object of type GameSystem with ID {0} is already being loaded", system.ID); + return; + } + + system.SetAsLoading(); + XmlNode elem = GetExtraData(system); XmlNode catsElem = elem.FirstChild; LoadCategoriesForSystem(system, elem); @@ -227,6 +236,14 @@ return; } + if (race.IsLoading) + { + LogNotifier.WarnFormat(GetType(), "Object of type Race with ID {0} is already being loaded", race.ID); + return; + } + + race.SetAsLoading(); + XmlNode elem = GetExtraData(race); XmlNode colNode = elem.FirstChild; @@ -387,21 +404,13 @@ //TODO: Add base size type.CostPerTrooper = GetIntValueFromAttribute(elem, "points"); type.BaseUnitCost = GetIntValueFromAttribute(elem, "unitPoints"); - - XmlNode node = elem.FirstChild; - - foreach(XmlElement cat in node.ChildNodes) - { - string catID = cat.GetAttribute("catID"); - type.AddCategory(parentRace.GetCategory(catID)); - } - string mainCatID = elem.GetAttribute("cat"); type.MainCategory = parentRace.GetCategory(mainCatID); - node = node.NextSibling; + XmlNodeList nodes = elem.SelectNodes("stats"); + XmlNode node = nodes.Item(0); type.UnitStats = ParseUnitStats((XmlElement)node, system); //TODO: Add unit requirements - + LogNotifier.Debug(GetType(), "Loaded "+type.Name); return type; }
--- a/api/Objects/UnitType.cs Sun Mar 15 15:10:02 2009 +0000 +++ b/api/Objects/UnitType.cs Sun Mar 15 16:07:52 2009 +0000 @@ -16,8 +16,7 @@ /// </summary> public class UnitType : WarFoundryObject { - protected Category mainCat; - protected List<Category> categories = new List<Category>(); + protected Category mainCat; protected Race race; protected int min, max, baseSize = 0; protected int minSize, maxSize; @@ -39,13 +38,7 @@ public UnitType(string id, string typeName, string mainCategoryID, string[] allCategoryIDs, int minNum, int maxNum, int minimumSize, int maximumSize, double unitCost, double trooperCost, Stats unitStats, UnitRequirement[] unitRequirements, Race parentRace) : base(id, typeName) { race = parentRace; - mainCat = race.GetCategory(mainCategoryID); - - foreach (string catID in allCategoryIDs) - { - categories.Add(race.GetCategory(catID)); - } - + mainCat = race.GetCategory(mainCategoryID); MinNumber = minNum; MaxNumber = maxNum; MinSize = minimumSize; @@ -73,30 +66,7 @@ } set { - if (value!=null && categories.Contains(value)) - { - mainCat = value; - } - else - { - throw new ArgumentException("MainCategory must exist in list of Categories"); - } - } - } - - public virtual Category[] Categories - { - get - { - return categories.ToArray(); - } - } - - public void AddCategory(Category cat) - { - if (!categories.Contains(cat)) - { - categories.Add(cat); + mainCat = value; } } @@ -158,7 +128,7 @@ { if (MinSize > MaxSize && MaxSize!=-1) { - MinSize = MaxNumber; + MinSize = MaxSize; LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum size greater than their maximum size.", Name, ID); } }
--- a/api/Objects/WarFoundryStagedLoadingObject.cs Sun Mar 15 15:10:02 2009 +0000 +++ b/api/Objects/WarFoundryStagedLoadingObject.cs Sun Mar 15 16:07:52 2009 +0000 @@ -11,6 +11,7 @@ public class WarFoundryStagedLoadingObject : WarFoundryObject, IWarFoundryStagedLoadObject { private bool isFullyLoaded; + private bool isLoading; private IWarFoundryFactory creatingFactory; private FileInfo sourceFile; @@ -36,7 +37,7 @@ public void EnsureFullyLoaded () { - if (!IsFullyLoaded) + if (!IsFullyLoaded && !IsLoading) { if (Factory == null) { @@ -57,9 +58,19 @@ get { return isFullyLoaded; } } + public bool IsLoading + { + get { return isLoading; } + } + public void SetAsFullyLoaded() { isFullyLoaded = true; } + + public void SetAsLoading() + { + isLoading = true; + } } }