changeset 118:d39de20f2ba1

Re #54: Add army loading support * Fix exceptions when loading army with units: * Remove obsolete methods * Add EnsureLoaded call to various getters to make sure that all required values are always loaded
author IBBoard <dev@ibboard.co.uk>
date Sun, 23 Aug 2009 10:28:03 +0000
parents 093ee2da0f6e
children 0cdc0b07fe11
files api/Objects/Race.cs
diffstat 1 files changed, 8 insertions(+), 34 deletions(-) [+]
line diff
     1.1 --- a/api/Objects/Race.cs	Sat Aug 22 20:02:29 2009 +0000
     1.2 +++ b/api/Objects/Race.cs	Sun Aug 23 10:28:03 2009 +0000
     1.3 @@ -32,16 +32,6 @@
     1.4  			subID = (raceSubID == null ? "" : raceSubID);
     1.5  			system = gameSystem;
     1.6  		}
     1.7 -		
     1.8 -		[Obsolete("Use constructor with GameSystem argument instead")]
     1.9 -		public Race(string raceID, string raceName, string gameSystemID, IWarFoundryFactory creatingFactory) : this(raceID, "", raceName, WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID), creatingFactory)
    1.10 -		{
    1.11 -		}
    1.12 -		
    1.13 -		[Obsolete("Use constructor with GameSystem argument instead")]
    1.14 -		public Race(string raceID, string raceSubID, string raceName, string gameSystemID, IWarFoundryFactory creatingFactory) : this(raceID, raceSubID, raceName, WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID), creatingFactory)
    1.15 -		{
    1.16 -		}
    1.17  
    1.18  		public string SubID
    1.19  		{
    1.20 @@ -113,6 +103,7 @@
    1.21  
    1.22  		public bool HasCategoryOverrides()
    1.23  		{
    1.24 +			EnsureFullyLoaded();
    1.25  			return categories.Count > 0;
    1.26  		}
    1.27  
    1.28 @@ -122,15 +113,6 @@
    1.29  			equipment.Add(item.ID, item);
    1.30  		}
    1.31  
    1.32 -		[Obsolete("Use AddEquipmentItem method instead")]
    1.33 -		public void SetEquipmentItems(Dictionary<string, EquipmentItem> items)
    1.34 -		{
    1.35 -			foreach (EquipmentItem item in items.Values)
    1.36 -			{
    1.37 -				AddEquipmentItem(item);
    1.38 -			}
    1.39 -		}
    1.40 -
    1.41  		public EquipmentItem GetEquipmentItem(string id)
    1.42  		{
    1.43  			EnsureFullyLoaded();
    1.44 @@ -139,6 +121,7 @@
    1.45  		
    1.46  		public List<EquipmentItem> GetEquipmentList()
    1.47  		{
    1.48 +			EnsureFullyLoaded();
    1.49  			List<EquipmentItem> items = new List<EquipmentItem>();
    1.50  			
    1.51  			foreach (EquipmentItem item in equipment.Values)
    1.52 @@ -155,17 +138,9 @@
    1.53  			unitTypes.Add(type.ID, type);
    1.54  		}
    1.55  
    1.56 -		[Obsolete("Use AddUnitType method instead")]
    1.57 -		public void SetUnitTypes(Dictionary<string, UnitType> types)
    1.58 -		{
    1.59 -			foreach (UnitType type in types.Values)
    1.60 -			{
    1.61 -				AddUnitType(type);
    1.62 -			}
    1.63 -		}
    1.64 -
    1.65  		public UnitType[] GetUnitTypes(Category cat)
    1.66  		{		
    1.67 +			EnsureFullyLoaded();
    1.68  			BuildUnitTypesByCategoryCache();
    1.69  			Dictionary<string, UnitType> unitTypesDictionary;
    1.70  			unitTypesByCat.TryGetValue(cat, out unitTypesDictionary);
    1.71 @@ -222,13 +197,13 @@
    1.72  
    1.73  		public UnitType GetUnitType(string id)
    1.74  		{
    1.75 -			UnitType type = null;
    1.76 -			unitTypes.TryGetValue(id, out type);
    1.77 -			return type;
    1.78 +			EnsureFullyLoaded();
    1.79 +			return DictionaryUtils.GetValue(unitTypes, id);
    1.80  		}
    1.81  		
    1.82  		public List<Ability> GetAbilityList()
    1.83  		{
    1.84 +			EnsureFullyLoaded();
    1.85  			List<Ability> items = new List<Ability>();
    1.86  			items.AddRange(abilities.Values);			
    1.87  			return items;
    1.88 @@ -251,9 +226,8 @@
    1.89  				
    1.90  		public Ability GetAbility(string id)
    1.91  		{
    1.92 -			Ability ability = null;
    1.93 -			abilities.TryGetValue(id, out ability);
    1.94 -			return ability;
    1.95 +			EnsureFullyLoaded();
    1.96 +			return DictionaryUtils.GetValue(abilities, id);
    1.97  		}
    1.98  		
    1.99  		protected virtual Dictionary<string, UnitType> RaceUnitTypes