Mercurial > repos > snowblizz-super-API-ideas
changeset 376:e50682387d63
Re #353: Handle unloaded units being referenced outside factory
* Remove inheritance prior to creation of more generalised sub-factory inheritance
* Create helper class that contains the only common code from old inheritance to keep duplication down
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 02 Jul 2011 19:58:28 +0000 |
parents | d9bf78a8f517 |
children | c3b0b28bad48 |
files | API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs API/Factories/Xml/AbstractStagedLoadedSubFactory.cs API/Factories/Xml/CategoryLoader.cs API/Factories/Xml/WarFoundryXmlGameSystemFactory.cs API/Factories/Xml/WarFoundryXmlRaceFactory.cs IBBoard.WarFoundry.API.csproj |
diffstat | 6 files changed, 41 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs Sat Jul 02 15:10:17 2011 +0000 +++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs Sat Jul 02 19:58:28 2011 +0000 @@ -43,7 +43,7 @@ { req.AddUnitTypeRequirement(unitType, Int32.Parse(amount)); } - catch (FormatException ex) + catch (FormatException) { throw new InvalidRequirementException(String.Format("Invalid amount '{0}' for unit type '{1}' for 'Requires at least N units' requirement", amount, unitID)); }
--- a/API/Factories/Xml/AbstractStagedLoadedSubFactory.cs Sat Jul 02 15:10:17 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -// This file (AbstractStagedLoadedSubFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard -// -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. - -using System; -using System.Xml; -using IBBoard.Xml; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Factories.Xml -{ - public class AbstractStagedLoadedSubFactory - { - protected WarFoundryXmlFactory mainFactory; - - protected AbstractStagedLoadedSubFactory(WarFoundryXmlFactory factory) - { - mainFactory = factory; - } - - protected Category CreateCategoryFromElement(XmlElement elem) - { - string id = elem.GetAttribute("id"); - string name = elem.GetAttribute("name"); - Category cat = new Category(id, name); - cat.MaximumPercentage = XmlTools.GetIntValueFromAttribute(elem, "maxPercentage"); - cat.MinimumPercentage = XmlTools.GetIntValueFromAttribute(elem, "minPercentage"); - cat.MaximumPoints = XmlTools.GetIntValueFromAttribute(elem, "maxPoints"); - cat.MinimumPoints = XmlTools.GetIntValueFromAttribute(elem, "minPoints"); - return cat; - } - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Factories/Xml/CategoryLoader.cs Sat Jul 02 19:58:28 2011 +0000 @@ -0,0 +1,26 @@ +// This file (CategoryLoader.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. +using System; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.Xml; +using System.Xml; + +namespace IBBoard.WarFoundry.API.Factories.Xml +{ + public class CategoryLoader + { + public static Category CreateFromElement(XmlElement elem) + { + string id = elem.GetAttribute("id"); + string name = elem.GetAttribute("name"); + Category cat = new Category(id, name); + cat.MaximumPercentage = XmlTools.GetIntValueFromAttribute(elem, "maxPercentage"); + cat.MinimumPercentage = XmlTools.GetIntValueFromAttribute(elem, "minPercentage"); + cat.MaximumPoints = XmlTools.GetIntValueFromAttribute(elem, "maxPoints"); + cat.MinimumPoints = XmlTools.GetIntValueFromAttribute(elem, "minPoints"); + return cat; + } + } +} +
--- a/API/Factories/Xml/WarFoundryXmlGameSystemFactory.cs Sat Jul 02 15:10:17 2011 +0000 +++ b/API/Factories/Xml/WarFoundryXmlGameSystemFactory.cs Sat Jul 02 19:58:28 2011 +0000 @@ -15,12 +15,14 @@ /// <summary> /// A sub-factory specifically for loading GameSystems from WarFoundry XML files /// </summary> - public class WarFoundryXmlGameSystemFactory : AbstractStagedLoadedSubFactory + public class WarFoundryXmlGameSystemFactory { - private Dictionary<GameSystem, XmlDocument> extraData = new Dictionary<GameSystem, XmlDocument>(); + private Dictionary<GameSystem, XmlDocument> extraData = new Dictionary<GameSystem, XmlDocument>(); + private WarFoundryXmlFactory mainFactory; - public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory) : base(factory) - { + public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory) + { + this.mainFactory = factory; } private void StoreExtraData(GameSystem wfObject, XmlElement elem) @@ -74,7 +76,7 @@ { foreach (XmlElement cat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:categories/cat:cat")) { - system.AddCategory(CreateCategoryFromElement(cat)); + system.AddCategory(CategoryLoader.CreateFromElement(cat)); } }
--- a/API/Factories/Xml/WarFoundryXmlRaceFactory.cs Sat Jul 02 15:10:17 2011 +0000 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactory.cs Sat Jul 02 19:58:28 2011 +0000 @@ -20,14 +20,15 @@ /// <summary> /// A sub-factory for loading WarFoundry Race XML files /// </summary> - public class WarFoundryXmlRaceFactory : AbstractStagedLoadedSubFactory + public class WarFoundryXmlRaceFactory { private Dictionary<Race, XmlDocument> extraData = new Dictionary<Race, XmlDocument>(); - private WarFoundryXmlLimitParser limitParser = new WarFoundryXmlLimitParser(); + private WarFoundryXmlLimitParser limitParser = new WarFoundryXmlLimitParser(); + private WarFoundryXmlFactory mainFactory; - public WarFoundryXmlRaceFactory(WarFoundryXmlFactory factory) : base (factory) + public WarFoundryXmlRaceFactory(WarFoundryXmlFactory factory) { - //Do nothing special + this.mainFactory = factory; } private void StoreExtraData(Race wfObject, XmlElement elem) @@ -102,7 +103,7 @@ private Category CreateCategoryFromElement(XmlElement elem, Race parentRace) { - Category cat = CreateCategoryFromElement(elem); + Category cat = CategoryLoader.CreateFromElement(elem); parentRace.AddCategory(cat); return cat; }
--- a/IBBoard.WarFoundry.API.csproj Sat Jul 02 15:10:17 2011 +0000 +++ b/IBBoard.WarFoundry.API.csproj Sat Jul 02 19:58:28 2011 +0000 @@ -146,7 +146,6 @@ <Compile Include="API\Factories\Xml\WarFoundryXmlRaceFactory.cs" /> <Compile Include="API\Factories\Xml\WarFoundryXmlArmyFactory.cs" /> <Compile Include="API\Factories\Xml\WarFoundryXmlFactoryUtils.cs" /> - <Compile Include="API\Factories\Xml\AbstractStagedLoadedSubFactory.cs" /> <Compile Include="API\Objects\InvalidContainershipException.cs" /> <Compile Include="API\Objects\CompositeEquipmentItem.cs" /> <Compile Include="API\Objects\AbstractUnitEquipmentItemSelection.cs" /> @@ -181,6 +180,7 @@ <Compile Include="API\Objects\Requirement\AbstractRequirement.cs" /> <Compile Include="API\Factories\Requirement\UnitRequiresAtLeastNUnitsRequirementFactory.cs" /> <Compile Include="API\Factories\Requirement\InvalidRequirementException.cs" /> + <Compile Include="API\Factories\Xml\CategoryLoader.cs" /> </ItemGroup> <ItemGroup> <Reference Include="System.Xml" />