Mercurial > repos > snowblizz-super-API-ideas
changeset 69:91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
* Make "Notes" a String value, as per schema
* Load contained units
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 25 Apr 2009 19:26:12 +0000 |
parents | 10d14a7051d5 |
children | 780f3926abad |
files | api/Factories/Xml/WarFoundryXmlRaceFactory.cs api/Objects/UnitType.cs |
diffstat | 2 files changed, 20 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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<string> equipmentKeyOrder = new List<string>(); private Dictionary<string, Ability> requiredAbilities = new Dictionary<string, Ability>(); private Dictionary<string, Ability> optionalAbilities = new Dictionary<string, Ability>(); - private List<String> notes = new List<string>(); + private String notes = ""; private List<UnitType> containedTypes = new List<UnitType>(); private Dictionary<string, string> extraData = new Dictionary<string, string>(); @@ -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);