# HG changeset patch # User IBBoard # Date 1240671563 0 # Node ID e6200220ece3783ba022e012bc7b0bf050e8e060 # Parent d100ca4bd0c1ae3dda8bc395809d0b25ed8e01a0 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 diff -r d100ca4bd0c1 -r e6200220ece3 api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs --- 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 slots = new List(); - 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; + } + } } diff -r d100ca4bd0c1 -r e6200220ece3 api/Factories/Xml/WarFoundryXmlRaceFactory.cs --- 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 statsList = new List(); 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; } diff -r d100ca4bd0c1 -r e6200220ece3 api/Objects/Stats.cs --- 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 @@ /// public class Stats { - private Stat[] stats; - private List statOrder; + private List stats; private SystemStats sysStats; public Stats(SystemStats systemStats) { sysStats = systemStats; + stats = new List(sysStats.SlotCount); } public Stat[] StatsArray { - get { return (Stat[])stats.Clone(); } + get { return stats.ToArray(); } } - - protected internal void SetStats(List statList) + + public void SetStatValue(string statName, string statValue) { - stats = statList.ToArray(); - statOrder = new List(); - - 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; } } } } diff -r d100ca4bd0c1 -r e6200220ece3 api/Objects/SystemStats.cs --- 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 @@ /// public class SystemStats { - private Dictionary stats; + private Dictionary statsByName; + private List stats; private string id; - public SystemStats(string statsID, StatSlot[] statSlots) + public SystemStats(string statsID) { id = statsID; - stats = new Dictionary(); - - foreach (StatSlot slot in statSlots) - { - slot.SystemStats = this; - stats[slot.Name] = slot; - } - } + statsByName = new Dictionary(); + stats = new List(); + } + + 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 { diff -r d100ca4bd0c1 -r e6200220ece3 api/Objects/UnitType.cs --- 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 list = nDictionaryUtils.GetValue(equipmentExclusionGroups, group); + List list = DictionaryUtils.GetValue(equipmentExclusionGroups, group); if (list == null) {