Mercurial > repos > IBBoard.WarFoundry.API
changeset 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 | d100ca4bd0c1 |
children | 10d14a7051d5 |
files | api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs api/Factories/Xml/WarFoundryXmlRaceFactory.cs api/Objects/Stats.cs api/Objects/SystemStats.cs api/Objects/UnitType.cs |
diffstat | 5 files changed, 50 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs Sat Apr 11 14:53:45 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs Sat Apr 25 14:59:23 2009 +0000 @@ -86,15 +86,14 @@ private SystemStats CreateSystemStatsFromElement(XmlElement elem) { - List<StatSlot> slots = new List<StatSlot>(); - string id = elem.GetAttribute("id"); + SystemStats sysStats = new SystemStats(elem.GetAttribute("id")); foreach (XmlElement slot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "system:sysStat")) { - StatSlot statSlot = new StatSlot(slot.GetAttribute("name")); - slots.Add(statSlot); + sysStats.AddStatSlot(slot.GetAttribute("name")); } - - return new SystemStats(id, slots.ToArray()); - } } + + return sysStats; + } + } }
--- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Sat Apr 11 14:53:45 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Sat Apr 25 14:59:23 2009 +0000 @@ -116,7 +116,6 @@ private Stats ParseUnitStats(XmlElement elem, GameSystem system) { - List<Stat> statsList = new List<Stat>(); String statsID = elem.GetAttribute("statSet"); SystemStats statsSet; @@ -133,21 +132,10 @@ foreach (XmlElement stat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:stat")) { - String statID = stat.GetAttribute("name"); - StatSlot slot = statsSet[statID]; - - if (slot!=null) - { - statsList.Add(new Stat(slot, stat.InnerText)); - } - else - { - throw new InvalidFileException("The stat "+statID+" was not found in stats set "+statsID); - } + String statName = stat.GetAttribute("name"); + stats.SetStatValue(statName, stat.InnerText); } - stats.SetStats(statsList); - return stats; }
--- 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; } } } }
--- a/api/Objects/SystemStats.cs Sat Apr 11 14:53:45 2009 +0000 +++ b/api/Objects/SystemStats.cs Sat Apr 25 14:59:23 2009 +0000 @@ -12,40 +12,45 @@ /// </summary> public class SystemStats { - private Dictionary<string, StatSlot> stats; + private Dictionary<string, StatSlot> statsByName; + private List<StatSlot> stats; private string id; - public SystemStats(string statsID, StatSlot[] statSlots) + public SystemStats(string statsID) { id = statsID; - stats = new Dictionary<string, StatSlot>(); - - foreach (StatSlot slot in statSlots) - { - slot.SystemStats = this; - stats[slot.Name] = slot; - } - } + statsByName = new Dictionary<string, StatSlot>(); + stats = new List<StatSlot>(); + } + + public void AddStatSlot(string slotName) + { + StatSlot slot = new StatSlot(slotName); + slot.SystemStats = this; + statsByName[slot.Name] = slot; + stats.Add(slot); + } public StatSlot[] StatSlots { get { - StatSlot[] slots = new StatSlot[stats.Count]; - stats.Values.CopyTo(slots, 0); - return slots; + return stats.ToArray(); } } - public StatSlot this[string key] + public StatSlot this[string statName] { get { - StatSlot slot = null; - stats.TryGetValue(key, out slot); - return slot; + return DictionaryUtils.GetValue(statsByName, statName); } } + + public int GetStatSlotPosition(StatSlot slot) + { + return stats.IndexOf(slot); + } public int SlotCount {
--- a/api/Objects/UnitType.cs Sat Apr 11 14:53:45 2009 +0000 +++ b/api/Objects/UnitType.cs Sat Apr 25 14:59:23 2009 +0000 @@ -271,7 +271,7 @@ public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroup(string group) { - List<UnitEquipmentItem> list = nDictionaryUtils.GetValue(equipmentExclusionGroups, group); + List<UnitEquipmentItem> list = DictionaryUtils.GetValue(equipmentExclusionGroups, group); if (list == null) {