# HG changeset patch # User IBBoard # Date 1243453389 0 # Node ID 032b174fc17a09ebd911c1f763718e7f385b6449 # Parent aa66dd18cdaeb7bf07daed746ce068086ee59462 Re #10 - Refactoring for readability * Remove "trainwreck code" by making Unit and UnitType publish methods to get arrays of stats * Remove "trainwreck code" by making Unit, UnitType and Stats publish methods to get value of one stat * Make factory use new methods diff -r aa66dd18cdae -r 032b174fc17a api/Factories/Xml/WarFoundryXmlRaceFactory.cs --- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Tue May 19 19:00:48 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Wed May 27 19:43:09 2009 +0000 @@ -142,7 +142,8 @@ type.MainCategory = cat; XmlElement statsElement = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "/race:race/race:units/race:unit/race:stats"); - type.UnitStats = ParseUnitStats(statsElement, type.GameSystem); + Stats unitStats = ParseUnitStats(statsElement, type.GameSystem); + type.SetUnitStats(unitStats); } private void LoadEquipmentForUnitType(XmlElement elem, UnitType type) diff -r aa66dd18cdae -r 032b174fc17a api/Objects/Stats.cs --- a/api/Objects/Stats.cs Tue May 19 19:00:48 2009 +0000 +++ b/api/Objects/Stats.cs Wed May 27 19:43:09 2009 +0000 @@ -83,6 +83,11 @@ } } } + + public string GetStatValue(string id) + { + return this[id].SlotValueString; + } public int StatCount { diff -r aa66dd18cdae -r 032b174fc17a api/Objects/Unit.cs --- a/api/Objects/Unit.cs Tue May 19 19:00:48 2009 +0000 +++ b/api/Objects/Unit.cs Wed May 27 19:43:09 2009 +0000 @@ -393,9 +393,19 @@ } } - public Stats UnitStats + public Stat[] UnitStatsArray { - get { return UnitType.UnitStats; } + get { return UnitType.UnitStatsArray; } + } + + public Stat[] UnitStatsArrayWithName + { + get { return UnitType.UnitStatsArrayWithName; } + } + + public string GetStatValue(string statName) + { + return UnitType.GetStatValue(statName); } } } diff -r aa66dd18cdae -r 032b174fc17a api/Objects/UnitType.cs --- a/api/Objects/UnitType.cs Tue May 19 19:00:48 2009 +0000 +++ b/api/Objects/UnitType.cs Wed May 27 19:43:09 2009 +0000 @@ -48,7 +48,7 @@ MaxSize = maximumSize; BaseUnitCost = unitCost; CostPerTrooper = trooperCost; - UnitStats = unitStats; + SetUnitStats(unitStats); foreach (UnitRequirement requirement in requirements) { @@ -193,21 +193,38 @@ } /// - /// The for the unit in a format that is valid for the game system. + /// The set of s for the unit in a format that is valid for the game system. /// - public Stats UnitStats + public Stat[] UnitStatsArray { get { - return stats; + return stats.StatsArray; } - set - { - if (value!=null) - { - stats = value; - } - } + } + + //// + /// The set of s for the unit including an additional column that contains the unit type name + /// + public Stat[] UnitStatsArrayWithName + { + get + { + Stat[] extendedStats = new Stat[stats.StatCount+1]; + extendedStats[0] = new Stat(new StatSlot("Name"), Name); + stats.StatsArray.CopyTo(extendedStats, 1); + return extendedStats; + } + } + + public void SetUnitStats(Stats newStats) + { + stats = newStats; + } + + public string GetStatValue(string statName) + { + return stats.GetStatValue(statName); } public void AddEquipmentItem(UnitEquipmentItem item)