# HG changeset patch # User IBBoard # Date 1240687572 0 # Node ID 91cf8efbea0b1ded6e47c37f16959d211a6f2192 # Parent 10d14a7051d57d93ae699cceb0f1b856593b20cf Re #50 - Complete core loading of WarFoundry XML files * Make "Notes" a String value, as per schema * Load contained units diff -r 10d14a7051d5 -r 91cf8efbea0b api/Factories/Xml/WarFoundryXmlRaceFactory.cs --- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Sat Apr 25 19:18:11 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Sat Apr 25 19:26:12 2009 +0000 @@ -90,18 +90,6 @@ return cat; } - private UnitType GetUnitType(Race race, string id) - { - UnitType type = race.GetUnitType(id); - - if (type == null) - { - type = CreateUnitTypeFromElement(GetExtraData(race).GetElementById(id), race); - } - - return type; - } - private UnitType GetUnitTypeFromDocument(XmlDocument doc, string id, Race parentRace) { return CreateUnitTypeFromElement(WarFoundryXmlFactoryUtils.SelectSingleElement(doc, "/race:race/race:units/race:unit[id="+id+"]"), parentRace); @@ -115,6 +103,7 @@ if (type==null) { type = CreateUnitTypeFromElement(elem, id, parentRace); + parentRace.AddUnitType(type); } return type; @@ -173,6 +162,20 @@ private void LoadContainedUnitsForUnitType(XmlElement elem, UnitType type) { + foreach (XmlElement containedUnitType in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:contains/race:containedUnit")) + { + string id = containedUnitType.GetAttribute("containedID"); + UnitType containedType = GetUnitTypeFromDocument(elem.OwnerDocument, id, type.Race); + + if (containedType!=null) + { + type.AddContainedUnitType(containedType); + } + else + { + // TODO: Warn on invalid data, but don't exception + } + } } private void LoadRequirementsForUnitType(XmlElement elem, UnitType type) diff -r 10d14a7051d5 -r 91cf8efbea0b api/Objects/UnitType.cs --- a/api/Objects/UnitType.cs Sat Apr 25 19:18:11 2009 +0000 +++ b/api/Objects/UnitType.cs Sat Apr 25 19:26:12 2009 +0000 @@ -28,7 +28,7 @@ private List equipmentKeyOrder = new List(); private Dictionary requiredAbilities = new Dictionary(); private Dictionary optionalAbilities = new Dictionary(); - private List notes = new List(); + private String notes = ""; private List containedTypes = new List(); private Dictionary extraData = new Dictionary(); @@ -377,16 +377,12 @@ return failures; } - public string[] Notes + public string Notes { - get { return notes.ToArray(); } + get { return notes; } + set { notes = value; } } - - public void AddNote(string note) - { - notes.Add(note); - } - + public bool CanContainUnit(Unit unit) { return CanContainUnitType(unit.UnitType);