Mercurial > repos > IBBoard.WarFoundry.API
changeset 81:032b174fc17a
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
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 27 May 2009 19:43:09 +0000 |
parents | aa66dd18cdae |
children | 3ea0ab04352b |
files | api/Factories/Xml/WarFoundryXmlRaceFactory.cs api/Objects/Stats.cs api/Objects/Unit.cs api/Objects/UnitType.cs |
diffstat | 4 files changed, 47 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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 {
--- 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); } } }
--- 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 @@ } /// <value> - /// The <see cref=" Stats"/> for the unit in a format that is valid for the game system. + /// The set of <see cref="Stat"/>s for the unit in a format that is valid for the game system. /// </value> - public Stats UnitStats + public Stat[] UnitStatsArray { get { - return stats; + return stats.StatsArray; } - set - { - if (value!=null) - { - stats = value; - } - } + } + + //// <value> + /// The set of <see cref="Stat"/>s for the unit including an additional column that contains the unit type name + /// </value> + 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)