# HG changeset patch # User IBBoard # Date 1309636708 0 # Node ID e50682387d6361ab5013a4d6fd4fe740511d61ac # Parent d9bf78a8f5174fb45bd654b58518b56495a36e98 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 diff -r d9bf78a8f517 -r e50682387d63 API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs --- 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)); } diff -r d9bf78a8f517 -r e50682387d63 API/Factories/Xml/AbstractStagedLoadedSubFactory.cs --- 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; - } - } -} diff -r d9bf78a8f517 -r e50682387d63 API/Factories/Xml/CategoryLoader.cs --- /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; + } + } +} + diff -r d9bf78a8f517 -r e50682387d63 API/Factories/Xml/WarFoundryXmlGameSystemFactory.cs --- 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 @@ /// /// A sub-factory specifically for loading GameSystems from WarFoundry XML files /// - public class WarFoundryXmlGameSystemFactory : AbstractStagedLoadedSubFactory + public class WarFoundryXmlGameSystemFactory { - private Dictionary extraData = new Dictionary(); + private Dictionary extraData = new Dictionary(); + 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)); } } diff -r d9bf78a8f517 -r e50682387d63 API/Factories/Xml/WarFoundryXmlRaceFactory.cs --- 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 @@ /// /// A sub-factory for loading WarFoundry Race XML files /// - public class WarFoundryXmlRaceFactory : AbstractStagedLoadedSubFactory + public class WarFoundryXmlRaceFactory { private Dictionary extraData = new Dictionary(); - 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; } diff -r d9bf78a8f517 -r e50682387d63 IBBoard.WarFoundry.API.csproj --- 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 @@ - @@ -181,6 +180,7 @@ +