Mercurial > repos > IBDev-IBBoard.WarFoundry.API
diff api/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 176:22429737cd77
Re #198: Add slots with counts to units
* Migrate to using new Limit objects from ibboard:ticket:24
* Parse new objects
* Move more data type definitions in to Core schema for re-use
* Make UnitType just return limit objects
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 22 Oct 2009 19:51:42 +0000 |
parents | 996816199b72 |
children | 36adabb1c3ea |
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Wed Oct 21 19:01:13 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Thu Oct 22 19:51:42 2009 +0000 @@ -8,6 +8,7 @@ using System.Xml; using IBBoard.Xml; using IBBoard.IO; +using IBBoard.Limits; using IBBoard.CustomMath; using ICSharpCode.SharpZipLib.Zip; using IBBoard.WarFoundry.API.Objects; @@ -156,13 +157,52 @@ private void LoadEquipmentSlotsForUnitType(XmlElement elem, UnitType type) { - foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:equipmentSlots/race:equipmentSlot")) + foreach (XmlElement equipSlot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:equipmentSlots/race:equipmentSlot")) { - string slotName = equip.GetAttribute("name"); - int slotLimit = XmlTools.GetIntValueFromAttribute(equip, "limit"); - type.AddEquipmentSlot(slotName, slotLimit); + LoadEquipmentSlotForUnitType (type, equipSlot); + } + } + + 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); + + if (limit!=null) + { + type.AddEquipmentSlot (slotName, limit); } } + + private static AbstractLimit GetLimitFromElement(XmlElement limitElem) + { + AbstractLimit limit = null; + + switch(limitElem.Name) + { + 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 "unlimitedLimit": + limit = new UnlimitedLimit(); + break; + default: + //TODO: Warn of missing handler for when we've extended the limit list + break; + } + + return limit; + } + private void LoadEquipmentForUnitType(XmlElement elem, UnitType type) {