comparison api/Objects/SystemStats.cs @ 67:e6200220ece3

Re #50 - Complete core loading of WarFoundry XML files * Clean up stat loading for game systems and unit types * Delete rogue character that stopped code compiling
author IBBoard <dev@ibboard.co.uk>
date Sat, 25 Apr 2009 14:59:23 +0000
parents 306558904c2a
children 3ea0ab04352b
comparison
equal deleted inserted replaced
66:d100ca4bd0c1 67:e6200220ece3
10 /// <summary> 10 /// <summary>
11 /// 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. 11 /// 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.
12 /// </summary> 12 /// </summary>
13 public class SystemStats 13 public class SystemStats
14 { 14 {
15 private Dictionary<string, StatSlot> stats; 15 private Dictionary<string, StatSlot> statsByName;
16 private List<StatSlot> stats;
16 private string id; 17 private string id;
17 18
18 public SystemStats(string statsID, StatSlot[] statSlots) 19 public SystemStats(string statsID)
19 { 20 {
20 id = statsID; 21 id = statsID;
21 stats = new Dictionary<string, StatSlot>(); 22 statsByName = new Dictionary<string, StatSlot>();
22 23 stats = new List<StatSlot>();
23 foreach (StatSlot slot in statSlots)
24 {
25 slot.SystemStats = this;
26 stats[slot.Name] = slot;
27 }
28 } 24 }
25
26 public void AddStatSlot(string slotName)
27 {
28 StatSlot slot = new StatSlot(slotName);
29 slot.SystemStats = this;
30 statsByName[slot.Name] = slot;
31 stats.Add(slot);
32 }
29 33
30 public StatSlot[] StatSlots 34 public StatSlot[] StatSlots
31 { 35 {
32 get 36 get
33 { 37 {
34 StatSlot[] slots = new StatSlot[stats.Count]; 38 return stats.ToArray();
35 stats.Values.CopyTo(slots, 0);
36 return slots;
37 } 39 }
38 } 40 }
39 41
40 public StatSlot this[string key] 42 public StatSlot this[string statName]
41 { 43 {
42 get 44 get
43 { 45 {
44 StatSlot slot = null; 46 return DictionaryUtils.GetValue(statsByName, statName);
45 stats.TryGetValue(key, out slot);
46 return slot;
47 } 47 }
48 }
49
50 public int GetStatSlotPosition(StatSlot slot)
51 {
52 return stats.IndexOf(slot);
48 } 53 }
49 54
50 public int SlotCount 55 public int SlotCount
51 { 56 {
52 get { return stats.Count; } 57 get { return stats.Count; }