Mercurial > repos > snowblizz-super-API-ideas
changeset 195:11bad32cfa06
* Implement new equipment limit loading
* Check for potential null when getting limit object for element
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 30 Oct 2009 20:31:00 +0000 |
parents | 1412a42190a1 |
children | 4bbf5624ced6 |
files | api/Factories/Xml/WarFoundryXmlRaceFactory.cs |
diffstat | 1 files changed, 45 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Fri Oct 30 20:23:03 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Fri Oct 30 20:31:00 2009 +0000 @@ -179,31 +179,33 @@ XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(equipSlot, "race:maxLimit/*[1]"); return GetLimitFromElement(limitElem); } - private static AbstractLimit GetLimitFromElement(XmlElement limitElem) { - AbstractLimit limit = null; - - switch(limitElem.LocalName) - { - case "percentageLimit": - double limitPercent = XmlTools.GetDoubleValueFromAttribute (limitElem, "limit"); - bool roundUp = limitElem.GetAttribute("round").Equals("up"); - limit = new SimpleRoundedPercentageLimit(limitPercent, roundUp); - break; - case "sizeConstrainedLimit": - limit = new NumericSizeConstrainedLimit(XmlTools.GetIntValueFromAttribute(limitElem, "limit")); - break; - case "absoluteLimit": - limit = new AbsoluteNumericLimit(XmlTools.GetIntValueFromAttribute(limitElem, "limit")); - break; - case "unitSizeLimit": - limit = new NumericSizeConstrainedLimit(); - break; - default: - //TODO: Warn of missing handler for when we've extended the limit list - break; + AbstractLimit limit = null; + + if (limitElem != null) + { + switch (limitElem.LocalName) + { + case "percentageLimit": + double limitPercent = XmlTools.GetDoubleValueFromAttribute(limitElem, "limit"); + bool roundUp = limitElem.GetAttribute("round").Equals("up"); + limit = new SimpleRoundedPercentageLimit(limitPercent, roundUp); + break; + case "sizeConstrainedLimit": + limit = new NumericSizeConstrainedLimit(XmlTools.GetIntValueFromAttribute(limitElem, "limit")); + break; + case "absoluteLimit": + limit = new AbsoluteNumericLimit(XmlTools.GetIntValueFromAttribute(limitElem, "limit")); + break; + case "unitSizeLimit": + limit = new NumericSizeConstrainedLimit(); + break; + default: + //TODO: Warn of missing handler for when we've extended the limit list + break; + } } return limit; @@ -258,6 +260,20 @@ { throw new InvalidFileException("Attribute 'equipmentSlot' of unit equipment item " + id + " for " + type.Name + " was not a valid slot name"); } + } + + AbstractLimit limit = GetMaxLimit(equip); + + if (limit != null) + { + unitEquipItem.MaxLimit = limit; + } + + limit = GetMinLimit(equip); + + if (limit != null) + { + unitEquipItem.MinLimit = limit; } unitEquipItem.RoundNumberUp = equip.GetAttribute("roundDirection").Equals("up"); @@ -293,8 +309,13 @@ { throw new InvalidFileException("Equipment item with ID '" + id + "' was required by " + type.Name + " but was not found"); } - } - + } + } + + private static AbstractLimit GetMinLimit(XmlElement elem) + { + XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:minLimit/*[1]"); + return GetLimitFromElement(limitElem); } private void LoadAbilitiesForUnitType(XmlElement elem, UnitType type)