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 diff
     1.1 --- a/api/Factories/Xml/WarFoundryXmlFactory.cs	Sun Mar 15 15:10:02 2009 +0000
     1.2 +++ b/api/Factories/Xml/WarFoundryXmlFactory.cs	Sun Mar 15 16:07:52 2009 +0000
     1.3 @@ -6,6 +6,7 @@
     1.4  using System.IO;
     1.5  using System.Xml;
     1.6  using System.Xml.Schema;
     1.7 +using System.Xml.XPath;
     1.8  using System.Collections.Generic;
     1.9  using System.Text;
    1.10  using IBBoard;
    1.11 @@ -187,6 +188,14 @@
    1.12  				return;
    1.13  			}
    1.14  			
    1.15 +			if (system.IsLoading)
    1.16 +			{
    1.17 +				LogNotifier.WarnFormat(GetType(), "Object of type GameSystem with ID {0} is already being loaded", system.ID);
    1.18 +				return;
    1.19 +			}
    1.20 +			
    1.21 +			system.SetAsLoading();
    1.22 +			
    1.23  			XmlNode elem = GetExtraData(system);			
    1.24  			XmlNode catsElem = elem.FirstChild;
    1.25  			LoadCategoriesForSystem(system, elem);
    1.26 @@ -227,6 +236,14 @@
    1.27  				return;
    1.28  			}
    1.29  			
    1.30 +			if (race.IsLoading)
    1.31 +			{
    1.32 +				LogNotifier.WarnFormat(GetType(), "Object of type Race with ID {0} is already being loaded", race.ID);
    1.33 +				return;
    1.34 +			}
    1.35 +			
    1.36 +			race.SetAsLoading();
    1.37 +			
    1.38  			XmlNode elem = GetExtraData(race);
    1.39  			XmlNode colNode = elem.FirstChild;
    1.40  						
    1.41 @@ -387,21 +404,13 @@
    1.42  			//TODO: Add base size
    1.43  			type.CostPerTrooper = GetIntValueFromAttribute(elem, "points");
    1.44  			type.BaseUnitCost = GetIntValueFromAttribute(elem, "unitPoints");
    1.45 -			
    1.46 -			XmlNode node = elem.FirstChild;
    1.47 -			
    1.48 -			foreach(XmlElement cat in node.ChildNodes)
    1.49 -			{
    1.50 -				string catID = cat.GetAttribute("catID");
    1.51 -				type.AddCategory(parentRace.GetCategory(catID));
    1.52 -			}
    1.53 -
    1.54  			string mainCatID = elem.GetAttribute("cat");
    1.55  			type.MainCategory = parentRace.GetCategory(mainCatID);						
    1.56 -			node = node.NextSibling;			
    1.57 +			XmlNodeList nodes = elem.SelectNodes("stats");
    1.58 +			XmlNode node = nodes.Item(0);
    1.59  			type.UnitStats = ParseUnitStats((XmlElement)node, system);
    1.60  			//TODO: Add unit requirements
    1.61 -			
    1.62 +			LogNotifier.Debug(GetType(), "Loaded "+type.Name);
    1.63  			return type;
    1.64  		}
    1.65  		
     2.1 --- a/api/Objects/UnitType.cs	Sun Mar 15 15:10:02 2009 +0000
     2.2 +++ b/api/Objects/UnitType.cs	Sun Mar 15 16:07:52 2009 +0000
     2.3 @@ -16,8 +16,7 @@
     2.4  	/// </summary>
     2.5  	public class UnitType : WarFoundryObject
     2.6  	{
     2.7 -		protected Category mainCat;
     2.8 -		protected List<Category> categories = new List<Category>();
     2.9 +		protected Category mainCat;
    2.10  		protected Race race;
    2.11  		protected int min, max, baseSize = 0;
    2.12  		protected int minSize, maxSize;
    2.13 @@ -39,13 +38,7 @@
    2.14  		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)
    2.15  		{
    2.16  			race = parentRace;
    2.17 -			mainCat = race.GetCategory(mainCategoryID);
    2.18 -
    2.19 -			foreach (string catID in allCategoryIDs)
    2.20 -			{
    2.21 -				categories.Add(race.GetCategory(catID));
    2.22 -			}
    2.23 -			
    2.24 +			mainCat = race.GetCategory(mainCategoryID);			
    2.25  			MinNumber = minNum;			
    2.26  			MaxNumber = maxNum;
    2.27  			MinSize = minimumSize;			
    2.28 @@ -73,30 +66,7 @@
    2.29  			}
    2.30  			set
    2.31  			{
    2.32 -				if (value!=null && categories.Contains(value))
    2.33 -				{
    2.34 -					mainCat = value;
    2.35 -				}
    2.36 -				else
    2.37 -				{
    2.38 -					throw new ArgumentException("MainCategory must exist in list of Categories");
    2.39 -				}	
    2.40 -			}
    2.41 -		}
    2.42 -		
    2.43 -		public virtual Category[] Categories
    2.44 -		{
    2.45 -			get 
    2.46 -			{				
    2.47 -				return categories.ToArray();
    2.48 -			}
    2.49 -		}
    2.50 -
    2.51 -		public void AddCategory(Category cat)
    2.52 -		{
    2.53 -			if (!categories.Contains(cat))
    2.54 -			{
    2.55 -				categories.Add(cat);
    2.56 +				mainCat = value;
    2.57  			}
    2.58  		}
    2.59  
    2.60 @@ -158,7 +128,7 @@
    2.61  		{
    2.62  			if (MinSize > MaxSize && MaxSize!=-1)
    2.63  			{
    2.64 -				MinSize = MaxNumber;
    2.65 +				MinSize = MaxSize;
    2.66  				LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum size greater than their maximum size.", Name, ID);
    2.67  			}
    2.68  		}
     3.1 --- a/api/Objects/WarFoundryStagedLoadingObject.cs	Sun Mar 15 15:10:02 2009 +0000
     3.2 +++ b/api/Objects/WarFoundryStagedLoadingObject.cs	Sun Mar 15 16:07:52 2009 +0000
     3.3 @@ -11,6 +11,7 @@
     3.4  	public class WarFoundryStagedLoadingObject : WarFoundryObject, IWarFoundryStagedLoadObject
     3.5  	{
     3.6  		private bool isFullyLoaded;
     3.7 +		private bool isLoading;
     3.8  		private IWarFoundryFactory creatingFactory;
     3.9  		private FileInfo sourceFile;
    3.10  		
    3.11 @@ -36,7 +37,7 @@
    3.12  		
    3.13  		public void EnsureFullyLoaded ()
    3.14  		{
    3.15 -			if (!IsFullyLoaded)
    3.16 +			if (!IsFullyLoaded && !IsLoading)
    3.17  			{
    3.18  				if (Factory == null)
    3.19  				{
    3.20 @@ -57,9 +58,19 @@
    3.21  			get { return isFullyLoaded; }
    3.22  		}
    3.23  		
    3.24 +		public bool IsLoading
    3.25 +		{
    3.26 +			get { return isLoading; }
    3.27 +		}
    3.28 +		
    3.29  		public void SetAsFullyLoaded()
    3.30  		{
    3.31  			isFullyLoaded = true;
    3.32  		}
    3.33 +		
    3.34 +		public void SetAsLoading()
    3.35 +		{
    3.36 +			isLoading = true;
    3.37 +		}
    3.38  	}
    3.39  }