Mercurial > repos > IBDev-IBBoard.WarFoundry.API
diff api/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 183:36adabb1c3ea
Re #198: Add slots with counts to units
* Remove old Min/MaxNumber/Percentage for equipment and replace with limits
* Refactor equipment selections and remove "numeric for ratio" as the limits handle the upper/lower limit differences
* Stop equipment selections taking an amount of 0 for out of range amounts
* Add "IsValid" property for selections
* Removed use of "-1" as an 'infinity' limit - now use 100% as a more correct value
* Change "unlimitedSize" limit in schema to "unitSizeLimit"
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 26 Oct 2009 20:55:04 +0000 |
parents | 22429737cd77 |
children | 2d0c4248a915 |
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Sat Oct 24 18:59:04 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Mon Oct 26 20:55:04 2009 +0000 @@ -166,14 +166,20 @@ private static void LoadEquipmentSlotForUnitType (UnitType type, XmlElement equipSlot) { string slotName = equipSlot.GetAttribute ("name"); - XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(equipSlot, "race:maxLimit/*[1]"); - AbstractLimit limit = GetLimitFromElement(limitElem); + AbstractLimit limit = GetMaxLimit (equipSlot); if (limit!=null) { type.AddEquipmentSlot (slotName, limit); } } + + private static AbstractLimit GetMaxLimit (XmlElement equipSlot) + { + XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(equipSlot, "race:maxLimit/*[1]"); + return GetLimitFromElement(limitElem); + } + private static AbstractLimit GetLimitFromElement(XmlElement limitElem) { @@ -192,8 +198,8 @@ case "absoluteLimit": limit = new AbsoluteNumericLimit(XmlTools.GetIntValueFromAttribute(limitElem, "limit")); break; - case "unlimitedLimit": - limit = new UnlimitedLimit(); + case "unitSizeLimit": + limit = new NumericSizeConstrainedLimit(); break; default: //TODO: Warn of missing handler for when we've extended the limit list @@ -253,10 +259,9 @@ throw new InvalidFileException("Attribute 'equipmentSlot' of unit equipment item " + id + " for " + type.Name + " was not a valid slot name"); } } - + unitEquipItem.RoundNumberUp = equip.GetAttribute("roundDirection").Equals("up"); - try { unitEquipItem.IsRequired = bool.Parse(equip.GetAttribute("required")); @@ -268,42 +273,6 @@ try { - unitEquipItem.MaxNumber = int.Parse(equip.GetAttribute("maxNum")); - } - catch (FormatException e) - { - throw new InvalidFileException("Attribute 'maxNum' of unit equipment item " + id + " for " + type.Name + " was not a valid integer", e); - } - - try - { - unitEquipItem.MinNumber = int.Parse(equip.GetAttribute("minNum")); - } - catch (FormatException e) - { - throw new InvalidFileException("Attribute 'minNum' of unit equipment item " + id + " for " + type.Name + " was not a valid integer", e); - } - - try - { - unitEquipItem.MaxPercentage = double.Parse(equip.GetAttribute("maxPercentage")); - } - catch (FormatException e) - { - throw new InvalidFileException("Attribute 'maxPercentage' of unit equipment item " + id + " for " + type.Name + " was not a valid decimal number", e); - } - - try - { - unitEquipItem.MinPercentage = double.Parse(equip.GetAttribute("minPercentage")); - } - catch (FormatException e) - { - throw new InvalidFileException("Attribute 'minPercentage' of unit equipment item " + id + " for " + type.Name + " was not a valid decimal number", e); - } - - try - { unitEquipItem.CostMultiplier = double.Parse(equip.GetAttribute("costMultiplier")); } catch (FormatException e)