Mercurial > repos > IBBoard.WarFoundry.API
diff api/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 167:9ba56a8e5096
Re #198: Add slots with counts to units
* Add initial API methods
* Add value loading
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 06 Oct 2009 14:59:54 +0000 |
parents | eb9a6d91a6db |
children | 3045a168714a |
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Tue Oct 06 14:47:06 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Tue Oct 06 14:59:54 2009 +0000 @@ -111,7 +111,8 @@ { string name = elem.GetAttribute("typeName"); UnitType type = new UnitType(id, name, parentRace); - LoadCoreValuesForUnitType(elem, type); + LoadCoreValuesForUnitType(elem, type); + LoadEquipmentSlotsForUnitType(elem, type); LoadEquipmentForUnitType(elem, type); LoadAbilitiesForUnitType(elem, type); LoadContainedUnitsForUnitType(elem, type); @@ -150,7 +151,17 @@ type.MainCategory = cat; XmlElement statsElement = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:stats"); Stats unitStats = ParseUnitStats(statsElement, type.GameSystem); - type.SetUnitStats(unitStats); + type.SetUnitStats(unitStats); + } + + private void LoadEquipmentSlotsForUnitType(XmlElement elem, UnitType type) + { + foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:equipmentSlots/race:equipmentSlot")) + { + string slotName = equip.GetAttribute("name"); + int slotLimit = XmlTools.GetIntValueFromAttribute(equip, "limit"); + type.AddEquipmentSlot(slotName, slotLimit); + } } private void LoadEquipmentForUnitType(XmlElement elem, UnitType type) @@ -187,7 +198,22 @@ mutexGroups = new string[0]; } - UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem, type, mutexGroups); + UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem, type, mutexGroups); + + string equipSlot = equip.GetAttribute("equipmentSlot"); + + if (equipSlot != "") + { + if (type.HasEquipmentSlot(equipSlot)) + { + unitEquipItem.SlotName = equipSlot; + } + else + { + 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");