Mercurial > repos > snowblizz-super-API-ideas
changeset 316:40a2df1f629a
Re #324: Add saving of Race and System data to files
* Move saver classes out of Factories folder and into Savers folder/namespace
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 05 Mar 2011 11:52:09 +0000 |
parents | 6cb0fb78b9a6 |
children | 58cd0fa53976 |
files | IBBoard.WarFoundry.API.csproj api/Factories/Xml/WarFoundryXmlArmySaver.cs api/Factories/Xml/WarFoundryXmlGameSystemSaver.cs api/Savers/Xml/WarFoundryXmlArmySaver.cs api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs |
diffstat | 5 files changed, 342 insertions(+), 337 deletions(-) [+] |
line wrap: on
line diff
--- a/IBBoard.WarFoundry.API.csproj Mon Feb 28 21:09:20 2011 +0000 +++ b/IBBoard.WarFoundry.API.csproj Sat Mar 05 11:52:09 2011 +0000 @@ -62,7 +62,6 @@ <ItemGroup> <None Include="app.config" /> <None Include="COPYING" /> - <Compile Include="api\Factories\Xml\WarFoundryXmlGameSystemSaver.cs" /> <Compile Include="api\Objects\ICostedWarFoundryObject.cs" /> <Compile Include="api\Commands\CreateAndAddUnitCommand.cs" /> <Compile Include="api\Commands\RemoveUnitCommand.cs" /> @@ -186,7 +185,8 @@ <Compile Include="api\Savers\IWarFoundryArmySaver.cs" /> <Compile Include="api\Savers\IWarFoundryRaceSaver.cs" /> <Compile Include="api\Objects\WarFoundryLoadedObject.cs" /> - <Compile Include="api\Factories\Xml\WarFoundryXmlArmySaver.cs" /> + <Compile Include="api\Savers\Xml\WarFoundryXmlArmySaver.cs" /> + <Compile Include="api\Savers\Xml\WarFoundryXmlGameSystemSaver.cs" /> </ItemGroup> <ItemGroup> <Reference Include="System.Xml" /> @@ -243,4 +243,9 @@ </Properties> </MonoDevelop> </ProjectExtensions> + <ItemGroup> + <Folder Include="api\Factories\Xml\" /> + <Folder Include="api\Factories\Xml\" /> + <Folder Include="api\Savers\Xml\" /> + </ItemGroup> </Project> \ No newline at end of file
--- a/api/Factories/Xml/WarFoundryXmlArmySaver.cs Mon Feb 28 21:09:20 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,186 +0,0 @@ -// This file (WarFoundryXmlSaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 2009 IBBoard. -// -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Xml; -using System.Xml.Schema; -using IBBoard.Lang; -using IBBoard.Xml; -using IBBoard.WarFoundry.API.Factories.Xml.Zip; -using IBBoard.WarFoundry.API.Objects; -using IBBoard.WarFoundry.API.Savers; -using IBBoard.WarFoundry.API.Util; -using ICSharpCode.SharpZipLib.Zip; - -namespace IBBoard.WarFoundry.API.Factories.Xml -{ - public class WarFoundryXmlArmySaver : IWarFoundryArmySaver - { - public const string ARMY_FILE_EXTENSION = ".army"; - - public bool Save(Army toSave, string savePath) - { - bool success = false; - ZipFile file = null; - - if (!savePath.EndsWith(ARMY_FILE_EXTENSION)) - { - savePath = savePath + ARMY_FILE_EXTENSION; - } - - try - { - file = ZipFile.Create(savePath); - file.BeginUpdate(); - file.Add(new StringZipEntrySource(CreateXmlString(toSave)), "data.armyx"); - file.CommitUpdate(); - success = true; - } - finally - { - if (file != null) - { - file.Close(); - } - } - - return success; - } - - private string CreateXmlString(WarFoundryObject toSave) - { - string xmlString = ""; - - if (toSave is Army) - { - xmlString = CreateArmyXmlString((Army)toSave); - } - - return xmlString; - } - - private string CreateArmyXmlString(Army toSave) - { - XmlDocument doc = new XmlDocument(); - XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", null, null); - doc.AppendChild(declaration); - XmlSchema schema = new XmlSchema(); - schema.Namespaces.Add("", "http://ibboard.co.uk/warfoundry/army"); - schema.Namespaces.Add("core", "http://ibboard.co.uk/warfoundry/core"); - doc.Schemas.Add(schema); - XmlElement root = doc.CreateElement("army"); - root.SetAttribute("xmlns", "http://ibboard.co.uk/warfoundry/army"); - root.SetAttribute("xmlns:core", "http://ibboard.co.uk/warfoundry/core"); - doc.AppendChild(root); - root.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(toSave.ID)); - root.SetAttribute("name", toSave.Name); - //Don't convert system and race to ID format as they could be stored in non-XML file formats - //If they are in XML files then they'll already be valid - root.SetAttribute("system", toSave.GameSystem.ID); - root.SetAttribute("race", toSave.Race.ID); - root.SetAttribute("maxPoints", toSave.MaxPoints.ToString()); - XmlElement units = doc.CreateElement("units"); - root.AppendChild(units); - - foreach (Unit unit in toSave.GetUnits()) - { - units.AppendChild(CreateUnitElement(unit, doc)); - } - - return doc.OuterXml; - } - - private XmlElement CreateUnitElement(Unit unit, XmlDocument doc) - { - XmlElement unitElem = doc.CreateElement("unit"); - unitElem.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(unit.ID)); - unitElem.SetAttribute("unitName", (unit.HasDefaultName() ? "" : unit.Name)); - unitElem.SetAttribute("unitType", unit.UnitType.ID); - unitElem.SetAttribute("size", unit.Size.ToString()); - - if (!unit.Race.Equals(unit.Army.Race)) - { - unitElem.SetAttribute("race", unit.Race.ID); - } - - Category unitCategory = unit.Category.Category; - if (!unit.UnitType.MainCategory.Equals(unitCategory)) - { - unitElem.SetAttribute("category", unitCategory.ID); - } - - XmlElement equipmentElem = CreateEquipmentItemsElement(unit, doc); - - if (equipmentElem != null) - { - unitElem.AppendChild(equipmentElem); - } - - XmlElement containedElem = CreateContainedUnitsElement(unit, doc); - - if (containedElem != null) - { - unitElem.AppendChild(containedElem); - } - - return unitElem; - } - - private XmlElement CreateEquipmentItemsElement(Unit unit, XmlDocument doc) - { - UnitEquipmentItem[] equipItems = unit.GetEquipment(); - int equipItemCount = equipItems.Length; - XmlElement equipmentElem = null; - - if (equipItemCount > 0) - { - equipmentElem = doc.CreateElement("equipment"); - - for (int i = 0; i < equipItemCount; i++) - { - equipmentElem.AppendChild(CreateEquipmentElement(equipItems[i], unit, doc)); - } - } - - return equipmentElem; - } - - private XmlElement CreateEquipmentElement(UnitEquipmentItem item, Unit unit, XmlDocument doc) - { - XmlElement equipmentItemElem = doc.CreateElement("equipItem"); - equipmentItemElem.SetAttribute("id", item.ID); - equipmentItemElem.SetAttribute("amount", UnitEquipmentUtil.GetEquipmentAmount(unit, item).ToString()); - equipmentItemElem.SetAttribute("amountType", UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, item) ? "ratio" : "fixed"); - return equipmentItemElem; - } - - private XmlElement CreateContainedUnitsElement(Unit unit, XmlDocument doc) - { - Unit[] containedUnits = unit.ContainedUnits; - int containedCount = containedUnits.Length; - XmlElement containedElem = null; - - if (containedCount > 0) - { - containedElem = doc.CreateElement("contained"); - - for (int i = 0; i < containedCount; i++) - { - containedElem.AppendChild(CreateContainedUnitElement(containedUnits[i], doc)); - } - } - - return containedElem; - } - - private XmlElement CreateContainedUnitElement(Unit unit, XmlDocument doc) - { - XmlElement containedUnitElem = doc.CreateElement("containedUnit"); - containedUnitElem.SetAttribute("containedID", XmlTools.GetAsciiXmlIdForString(unit.ID)); - return containedUnitElem; - } - } -}
--- a/api/Factories/Xml/WarFoundryXmlGameSystemSaver.cs Mon Feb 28 21:09:20 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,149 +0,0 @@ -// This file (WarFoundryXmlGameSystemSaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 2009 IBBoard. -// -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Xml; -using System.Xml.Schema; -using IBBoard.Lang; -using IBBoard.Xml; -using IBBoard.WarFoundry.API.Factories.Xml.Zip; -using IBBoard.WarFoundry.API.Objects; -using IBBoard.WarFoundry.API.Savers; -using IBBoard.WarFoundry.API.Util; -using ICSharpCode.SharpZipLib.Zip; - -namespace IBBoard.WarFoundry.API.Factories.Xml -{ - public class WarFoundryXmlGameSystemSaver : IWarFoundryGameSystemSaver - { - public const string GAMESYSTEM_FILE_EXTENSION = ".system"; - - public bool Save(GameSystem toSave, string savePath) - { - bool success = false; - ZipFile file = null; - - if (!savePath.EndsWith(GAMESYSTEM_FILE_EXTENSION)) - { - savePath = savePath + GAMESYSTEM_FILE_EXTENSION; - } - - try - { - file = ZipFile.Create(savePath); - file.BeginUpdate(); - file.Add(new StringZipEntrySource(CreateXmlString(toSave)), "data.systemx"); - file.CommitUpdate(); - success = true; - } - finally - { - if (file != null) - { - file.Close(); - } - } - - return success; - } - - private string CreateXmlString(WarFoundryObject toSave) - { - string xmlString = ""; - - if (toSave is GameSystem) - { - xmlString = CreateGameSystemXmlString((GameSystem)toSave); - } - - return xmlString; - } - - private string CreateGameSystemXmlString(GameSystem toSave) - { - XmlDocument doc = new XmlDocument(); - XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", null, null); - doc.AppendChild(declaration); - XmlSchema schema = new XmlSchema(); - schema.Namespaces.Add("", "http://ibboard.co.uk/warfoundry/system"); - schema.Namespaces.Add("cats", "http://ibboard.co.uk/warfoundry/cats"); - doc.Schemas.Add(schema); - XmlElement root = doc.CreateElement("system"); - root.SetAttribute("xmlns", "http://ibboard.co.uk/warfoundry/system"); - root.SetAttribute("xmlns:cats", "http://ibboard.co.uk/warfoundry/cats"); - doc.AppendChild(root); - root.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(toSave.ID)); - root.SetAttribute("name", toSave.Name); - root.SetAttribute("defaultArmySize", toSave.SystemArmyDefaultSize.ToString()); - root.SetAttribute("warn", toSave.WarnOnError.ToString().ToLowerInvariant()); - root.SetAttribute("allowAllies", toSave.AllowAllies.ToString().ToLowerInvariant()); - XmlElement cats = doc.CreateElement("categories"); - root.AppendChild(cats); - - foreach (Category cat in toSave.Categories) - { - cats.AppendChild(CreateCategoryElement(cat, doc)); - } - - XmlElement sysStatsList = doc.CreateElement("sysStatsList"); - sysStatsList.SetAttribute("defaultStats", XmlTools.GetAsciiXmlIdForString(toSave.StandardSystemStatsID)); - root.AppendChild(sysStatsList); - - foreach(SystemStats stats in toSave.SystemStats) - { - sysStatsList.AppendChild(CreateSystemStatsElement(stats, doc)); - } - - return doc.OuterXml; - } - - private XmlElement CreateCategoryElement(Category cat, XmlDocument doc) - { - XmlElement catElem = doc.CreateElement("cats:cat"); - catElem.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(cat.ID)); - catElem.SetAttribute("name", (cat.HasDefaultName() ? "" : cat.Name)); - if (cat.MinimumPoints > 0) - { - catElem.SetAttribute("minPoints", cat.MaximumPercentage.ToString()); - } - if (cat.MaximumPoints < 100) - { - catElem.SetAttribute("maxPoints", cat.MaximumPercentage.ToString()); - } - if(cat.MinimumPercentage > 0) - { - catElem.SetAttribute("minPercentage", cat.MaximumPercentage.ToString()); - } - if(cat.MaximumPercentage < 100) - { - catElem.SetAttribute("maxPercentage", cat.MaximumPercentage.ToString()); - } - - return catElem; - } - - private XmlElement CreateSystemStatsElement(SystemStats stats, XmlDocument doc) - { - XmlElement statsElem = doc.CreateElement("sysStats"); - statsElem.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(stats.ID)); - - foreach(StatSlot stat in stats.StatSlots) - { - statsElem.AppendChild(CreateSystemStatElement(stat, doc)); - } - - return statsElem; - } - - private XmlElement CreateSystemStatElement(StatSlot stat, XmlDocument doc) - { - XmlElement statElem = doc.CreateElement("sysStat"); - statElem.SetAttribute("name", stat.Name); - - return statElem; - } - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api/Savers/Xml/WarFoundryXmlArmySaver.cs Sat Mar 05 11:52:09 2011 +0000 @@ -0,0 +1,186 @@ +// This file (WarFoundryXmlSaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 2009 IBBoard. +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml; +using System.Xml.Schema; +using IBBoard.Lang; +using IBBoard.Xml; +using IBBoard.WarFoundry.API.Factories.Xml.Zip; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.WarFoundry.API.Savers; +using IBBoard.WarFoundry.API.Util; +using ICSharpCode.SharpZipLib.Zip; + +namespace IBBoard.WarFoundry.API.Savers.Xml +{ + public class WarFoundryXmlArmySaver : IWarFoundryArmySaver + { + public const string ARMY_FILE_EXTENSION = ".army"; + + public bool Save(Army toSave, string savePath) + { + bool success = false; + ZipFile file = null; + + if (!savePath.EndsWith(ARMY_FILE_EXTENSION)) + { + savePath = savePath + ARMY_FILE_EXTENSION; + } + + try + { + file = ZipFile.Create(savePath); + file.BeginUpdate(); + file.Add(new StringZipEntrySource(CreateXmlString(toSave)), "data.armyx"); + file.CommitUpdate(); + success = true; + } + finally + { + if (file != null) + { + file.Close(); + } + } + + return success; + } + + private string CreateXmlString(WarFoundryObject toSave) + { + string xmlString = ""; + + if (toSave is Army) + { + xmlString = CreateArmyXmlString((Army)toSave); + } + + return xmlString; + } + + private string CreateArmyXmlString(Army toSave) + { + XmlDocument doc = new XmlDocument(); + XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", null, null); + doc.AppendChild(declaration); + XmlSchema schema = new XmlSchema(); + schema.Namespaces.Add("", "http://ibboard.co.uk/warfoundry/army"); + schema.Namespaces.Add("core", "http://ibboard.co.uk/warfoundry/core"); + doc.Schemas.Add(schema); + XmlElement root = doc.CreateElement("army"); + root.SetAttribute("xmlns", "http://ibboard.co.uk/warfoundry/army"); + root.SetAttribute("xmlns:core", "http://ibboard.co.uk/warfoundry/core"); + doc.AppendChild(root); + root.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(toSave.ID)); + root.SetAttribute("name", toSave.Name); + //Don't convert system and race to ID format as they could be stored in non-XML file formats + //If they are in XML files then they'll already be valid + root.SetAttribute("system", toSave.GameSystem.ID); + root.SetAttribute("race", toSave.Race.ID); + root.SetAttribute("maxPoints", toSave.MaxPoints.ToString()); + XmlElement units = doc.CreateElement("units"); + root.AppendChild(units); + + foreach (Unit unit in toSave.GetUnits()) + { + units.AppendChild(CreateUnitElement(unit, doc)); + } + + return doc.OuterXml; + } + + private XmlElement CreateUnitElement(Unit unit, XmlDocument doc) + { + XmlElement unitElem = doc.CreateElement("unit"); + unitElem.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(unit.ID)); + unitElem.SetAttribute("unitName", (unit.HasDefaultName() ? "" : unit.Name)); + unitElem.SetAttribute("unitType", unit.UnitType.ID); + unitElem.SetAttribute("size", unit.Size.ToString()); + + if (!unit.Race.Equals(unit.Army.Race)) + { + unitElem.SetAttribute("race", unit.Race.ID); + } + + Category unitCategory = unit.Category.Category; + if (!unit.UnitType.MainCategory.Equals(unitCategory)) + { + unitElem.SetAttribute("category", unitCategory.ID); + } + + XmlElement equipmentElem = CreateEquipmentItemsElement(unit, doc); + + if (equipmentElem != null) + { + unitElem.AppendChild(equipmentElem); + } + + XmlElement containedElem = CreateContainedUnitsElement(unit, doc); + + if (containedElem != null) + { + unitElem.AppendChild(containedElem); + } + + return unitElem; + } + + private XmlElement CreateEquipmentItemsElement(Unit unit, XmlDocument doc) + { + UnitEquipmentItem[] equipItems = unit.GetEquipment(); + int equipItemCount = equipItems.Length; + XmlElement equipmentElem = null; + + if (equipItemCount > 0) + { + equipmentElem = doc.CreateElement("equipment"); + + for (int i = 0; i < equipItemCount; i++) + { + equipmentElem.AppendChild(CreateEquipmentElement(equipItems[i], unit, doc)); + } + } + + return equipmentElem; + } + + private XmlElement CreateEquipmentElement(UnitEquipmentItem item, Unit unit, XmlDocument doc) + { + XmlElement equipmentItemElem = doc.CreateElement("equipItem"); + equipmentItemElem.SetAttribute("id", item.ID); + equipmentItemElem.SetAttribute("amount", UnitEquipmentUtil.GetEquipmentAmount(unit, item).ToString()); + equipmentItemElem.SetAttribute("amountType", UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, item) ? "ratio" : "fixed"); + return equipmentItemElem; + } + + private XmlElement CreateContainedUnitsElement(Unit unit, XmlDocument doc) + { + Unit[] containedUnits = unit.ContainedUnits; + int containedCount = containedUnits.Length; + XmlElement containedElem = null; + + if (containedCount > 0) + { + containedElem = doc.CreateElement("contained"); + + for (int i = 0; i < containedCount; i++) + { + containedElem.AppendChild(CreateContainedUnitElement(containedUnits[i], doc)); + } + } + + return containedElem; + } + + private XmlElement CreateContainedUnitElement(Unit unit, XmlDocument doc) + { + XmlElement containedUnitElem = doc.CreateElement("containedUnit"); + containedUnitElem.SetAttribute("containedID", XmlTools.GetAsciiXmlIdForString(unit.ID)); + return containedUnitElem; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs Sat Mar 05 11:52:09 2011 +0000 @@ -0,0 +1,149 @@ +// This file (WarFoundryXmlGameSystemSaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 2009 IBBoard. +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml; +using System.Xml.Schema; +using IBBoard.Lang; +using IBBoard.Xml; +using IBBoard.WarFoundry.API.Factories.Xml.Zip; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.WarFoundry.API.Savers; +using IBBoard.WarFoundry.API.Util; +using ICSharpCode.SharpZipLib.Zip; + +namespace IBBoard.WarFoundry.API.Savers.Xml +{ + public class WarFoundryXmlGameSystemSaver : IWarFoundryGameSystemSaver + { + public const string GAMESYSTEM_FILE_EXTENSION = ".system"; + + public bool Save(GameSystem toSave, string savePath) + { + bool success = false; + ZipFile file = null; + + if (!savePath.EndsWith(GAMESYSTEM_FILE_EXTENSION)) + { + savePath = savePath + GAMESYSTEM_FILE_EXTENSION; + } + + try + { + file = ZipFile.Create(savePath); + file.BeginUpdate(); + file.Add(new StringZipEntrySource(CreateXmlString(toSave)), "data.systemx"); + file.CommitUpdate(); + success = true; + } + finally + { + if (file != null) + { + file.Close(); + } + } + + return success; + } + + private string CreateXmlString(WarFoundryObject toSave) + { + string xmlString = ""; + + if (toSave is GameSystem) + { + xmlString = CreateGameSystemXmlString((GameSystem)toSave); + } + + return xmlString; + } + + private string CreateGameSystemXmlString(GameSystem toSave) + { + XmlDocument doc = new XmlDocument(); + XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", null, null); + doc.AppendChild(declaration); + XmlSchema schema = new XmlSchema(); + schema.Namespaces.Add("", "http://ibboard.co.uk/warfoundry/system"); + schema.Namespaces.Add("cats", "http://ibboard.co.uk/warfoundry/cats"); + doc.Schemas.Add(schema); + XmlElement root = doc.CreateElement("system"); + root.SetAttribute("xmlns", "http://ibboard.co.uk/warfoundry/system"); + root.SetAttribute("xmlns:cats", "http://ibboard.co.uk/warfoundry/cats"); + doc.AppendChild(root); + root.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(toSave.ID)); + root.SetAttribute("name", toSave.Name); + root.SetAttribute("defaultArmySize", toSave.SystemArmyDefaultSize.ToString()); + root.SetAttribute("warn", toSave.WarnOnError.ToString().ToLowerInvariant()); + root.SetAttribute("allowAllies", toSave.AllowAllies.ToString().ToLowerInvariant()); + XmlElement cats = doc.CreateElement("categories"); + root.AppendChild(cats); + + foreach (Category cat in toSave.Categories) + { + cats.AppendChild(CreateCategoryElement(cat, doc)); + } + + XmlElement sysStatsList = doc.CreateElement("sysStatsList"); + sysStatsList.SetAttribute("defaultStats", XmlTools.GetAsciiXmlIdForString(toSave.StandardSystemStatsID)); + root.AppendChild(sysStatsList); + + foreach(SystemStats stats in toSave.SystemStats) + { + sysStatsList.AppendChild(CreateSystemStatsElement(stats, doc)); + } + + return doc.OuterXml; + } + + private XmlElement CreateCategoryElement(Category cat, XmlDocument doc) + { + XmlElement catElem = doc.CreateElement("cats:cat"); + catElem.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(cat.ID)); + catElem.SetAttribute("name", (cat.HasDefaultName() ? "" : cat.Name)); + if (cat.MinimumPoints > 0) + { + catElem.SetAttribute("minPoints", cat.MaximumPercentage.ToString()); + } + if (cat.MaximumPoints < 100) + { + catElem.SetAttribute("maxPoints", cat.MaximumPercentage.ToString()); + } + if(cat.MinimumPercentage > 0) + { + catElem.SetAttribute("minPercentage", cat.MaximumPercentage.ToString()); + } + if(cat.MaximumPercentage < 100) + { + catElem.SetAttribute("maxPercentage", cat.MaximumPercentage.ToString()); + } + + return catElem; + } + + private XmlElement CreateSystemStatsElement(SystemStats stats, XmlDocument doc) + { + XmlElement statsElem = doc.CreateElement("sysStats"); + statsElem.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(stats.ID)); + + foreach(StatSlot stat in stats.StatSlots) + { + statsElem.AppendChild(CreateSystemStatElement(stat, doc)); + } + + return statsElem; + } + + private XmlElement CreateSystemStatElement(StatSlot stat, XmlDocument doc) + { + XmlElement statElem = doc.CreateElement("sysStat"); + statElem.SetAttribute("name", stat.Name); + + return statElem; + } + } +}