Mercurial > repos > IBBoard.WarFoundry.API
diff api/Objects/Stats.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 | 10d14a7051d5 |
line wrap: on
line diff
--- a/api/Objects/Stats.cs Sat Apr 11 14:53:45 2009 +0000 +++ b/api/Objects/Stats.cs Sat Apr 25 14:59:23 2009 +0000 @@ -13,37 +13,42 @@ /// </summary> public class Stats { - private Stat[] stats; - private List<string> statOrder; + private List<Stat> stats; private SystemStats sysStats; public Stats(SystemStats systemStats) { sysStats = systemStats; + stats = new List<Stat>(sysStats.SlotCount); } public Stat[] StatsArray { - get { return (Stat[])stats.Clone(); } + get { return stats.ToArray(); } } - - protected internal void SetStats(List<Stat> statList) + + public void SetStatValue(string statName, string statValue) { - stats = statList.ToArray(); - statOrder = new List<string>(); - - foreach (Stat stat in statList) + StatSlot slot = sysStats[statName]; + + if (slot!=null) { - statOrder.Add(stat.ParentSlot.Name); - } + int pos = sysStats.GetStatSlotPosition(slot); + + if (pos > -1) + { + stats[pos] = new Stat(slot, statValue); + } + } } public Stat this[string id] { get { + StatSlot slot = sysStats[id]; + int pos = sysStats.GetStatSlotPosition(slot); Stat stat = null; - int pos = statOrder.IndexOf(id); try { @@ -62,7 +67,7 @@ { get { - if (pos < stats.Length && pos >= 0) + if (pos < stats.Count && pos >= 0) { return stats[pos]; } @@ -75,7 +80,7 @@ public int StatCount { - get { return stats.Length; } + get { return stats.Count; } } } }