changeset 296:ed5e6d92ecd9

Re #323: WarFoundry.API - SystemStats cannot remove stat Remove code didn't fully remove stat, this has been fixed and tested
author Tsudico
date Sat, 18 Dec 2010 22:34:32 +0000
parents f8f441f2fcfe
children 349e521785c1
files api/Objects/SystemStats.cs
diffstat 1 files changed, 70 insertions(+), 72 deletions(-) [+]
line diff
     1.1 --- a/api/Objects/SystemStats.cs	Sat Dec 18 20:53:52 2010 +0000
     1.2 +++ b/api/Objects/SystemStats.cs	Sat Dec 18 22:34:32 2010 +0000
     1.3 @@ -1,73 +1,71 @@
     1.4 -// This file (SystemStats.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
     1.5 -//
     1.6 -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
     1.7 -
     1.8 -using System;
     1.9 -using System.Collections.Generic;
    1.10 -
    1.11 -namespace IBBoard.WarFoundry.API.Objects
    1.12 -{
    1.13 -	/// <summary>
    1.14 -	/// SystemStats defines the available statistics/attributes that entity types can use (either a unit or an equipment item that has a stats line). Statistic/attribute values will be defined by a <see cref="Stats"/> object.
    1.15 -	/// </summary>
    1.16 -	public class SystemStats
    1.17 -	{
    1.18 -		private Dictionary<string, StatSlot> statsByName;
    1.19 -		private List<StatSlot> stats;
    1.20 -		private string id;
    1.21 -
    1.22 -		public SystemStats(string statsID)
    1.23 -		{
    1.24 -			id = statsID;
    1.25 -			statsByName = new Dictionary<string, StatSlot>();
    1.26 -			stats = new List<StatSlot>();
    1.27 -		}
    1.28 -
    1.29 -		public void AddStatSlot(string slotName)
    1.30 -		{
    1.31 -			StatSlot slot = new StatSlot(slotName);
    1.32 -			slot.SystemStats = this;
    1.33 -			statsByName[slot.Name.ToLower()] = slot;
    1.34 -			stats.Add(slot);
    1.35 -		}		
    1.36 -
    1.37 -		public StatSlot[] StatSlots
    1.38 -		{
    1.39 -			get
    1.40 -			{
    1.41 -				return stats.ToArray();
    1.42 -			}
    1.43 -		}
    1.44 -		
    1.45 -		public StatSlot this[string statName]
    1.46 -		{
    1.47 -			get 
    1.48 -			{
    1.49 -				return DictionaryUtils.GetValue(statsByName, statName.ToLower());
    1.50 -			}
    1.51 -		}
    1.52 -
    1.53 -		public int GetStatSlotPosition(StatSlot slot)
    1.54 -		{
    1.55 -			return stats.IndexOf(slot);
    1.56 -		}
    1.57 -		
    1.58 -		public void RemoveStatSlot(string name)
    1.59 -		{
    1.60 +// This file (SystemStats.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
    1.61 +//
    1.62 +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
    1.63 +
    1.64 +using System;
    1.65 +using System.Collections.Generic;
    1.66 +
    1.67 +namespace IBBoard.WarFoundry.API.Objects
    1.68 +{
    1.69 +	/// <summary>
    1.70 +	/// SystemStats defines the available statistics/attributes that entity types can use (either a unit or an equipment item that has a stats line). Statistic/attribute values will be defined by a <see cref="Stats"/> object.
    1.71 +	/// </summary>
    1.72 +	public class SystemStats
    1.73 +	{
    1.74 +		private Dictionary<string, StatSlot> statsByName;
    1.75 +		private List<StatSlot> stats;
    1.76 +		private string id;
    1.77 +
    1.78 +		public SystemStats(string statsID)
    1.79 +		{
    1.80 +			id = statsID;
    1.81 +			statsByName = new Dictionary<string, StatSlot>();
    1.82 +			stats = new List<StatSlot>();
    1.83 +		}
    1.84 +
    1.85 +		public void AddStatSlot(string slotName)
    1.86 +		{
    1.87 +			StatSlot slot = new StatSlot(slotName);
    1.88 +			slot.SystemStats = this;
    1.89 +			statsByName[slot.Name.ToLower()] = slot;
    1.90 +			stats.Add(slot);
    1.91 +		}		
    1.92 +
    1.93 +		public StatSlot[] StatSlots
    1.94 +		{
    1.95 +			get
    1.96 +			{
    1.97 +				return stats.ToArray();
    1.98 +			}
    1.99 +		}
   1.100 +		
   1.101 +		public StatSlot this[string statName]
   1.102 +		{
   1.103 +			get 
   1.104 +			{
   1.105 +				return DictionaryUtils.GetValue(statsByName, statName.ToLower());
   1.106 +			}
   1.107 +		}
   1.108 +
   1.109 +		public int GetStatSlotPosition(StatSlot slot)
   1.110 +		{
   1.111 +			return stats.IndexOf(slot);
   1.112 +		}
   1.113 +		
   1.114 +		public void RemoveStatSlot(string name)
   1.115 +		{
   1.116  			statsByName.Remove(name);
   1.117 -			StatSlot slot = new StatSlot(name);
   1.118 -			slot.SystemStats = this;
   1.119 -			stats.Remove(slot);
   1.120 -		}
   1.121 -		
   1.122 -        public int SlotCount
   1.123 -        {
   1.124 -            get { return stats.Count; }
   1.125 -        }
   1.126 -		
   1.127 -		public string ID
   1.128 -		{
   1.129 -			get { return id; }
   1.130 -		}
   1.131 -	}
   1.132 -}
   1.133 +			stats.Remove(this[name]);
   1.134 +		}
   1.135 +		
   1.136 +        public int SlotCount
   1.137 +        {
   1.138 +            get { return stats.Count; }
   1.139 +        }
   1.140 +		
   1.141 +		public string ID
   1.142 +		{
   1.143 +			get { return id; }
   1.144 +		}
   1.145 +	}
   1.146 +}