Mercurial > repos > snowblizz-super-API-ideas
changeset 325:e0580a009e75
Re #324: Add saving of Race and System data to files
* Remove extra interfaces, as their replacements would be implementation specific and the break-down is now only a clean coding issue
* Strip out extra code from Army and GameSystem saver
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 12 Mar 2011 20:32:08 +0000 |
parents | e09a8d9c95f6 |
children | 331995582990 |
files | IBBoard.WarFoundry.API.csproj api/Savers/IWarFoundryArmySaver.cs api/Savers/IWarFoundryGameSystemSaver.cs api/Savers/IWarFoundryRaceSaver.cs api/Savers/Xml/WarFoundryXmlArmySaver.cs api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs |
diffstat | 6 files changed, 4 insertions(+), 173 deletions(-) [+] |
line wrap: on
line diff
--- a/IBBoard.WarFoundry.API.csproj Sat Mar 12 20:00:13 2011 +0000 +++ b/IBBoard.WarFoundry.API.csproj Sat Mar 12 20:32:08 2011 +0000 @@ -116,7 +116,6 @@ <Compile Include="api\Requirements\UnitRequirementMinNumber.cs" /> <Compile Include="api\Requirements\UnitRequiresAtLeastRequirement.cs" /> <Compile Include="api\Savers\IWarFoundryFileSaver.cs" /> - <Compile Include="api\Savers\IWarFoundryGameSystemSaver.cs" /> <Compile Include="api\Savers\WarFoundrySaver.cs" /> <Compile Include="api\Util\UnitEquipmentUtil.cs" /> <Compile Include="api\WarFoundryCore.cs" /> @@ -182,8 +181,6 @@ <Compile Include="api\Objects\UnitMemberType.cs" /> <Compile Include="api\Factories\Xml\WarFoundryXmlLimitParser.cs" /> <Compile Include="api\Factories\DummyWarFoundryFactory.cs" /> - <Compile Include="api\Savers\IWarFoundryArmySaver.cs" /> - <Compile Include="api\Savers\IWarFoundryRaceSaver.cs" /> <Compile Include="api\Objects\WarFoundryLoadedObject.cs" /> <Compile Include="api\Savers\Xml\WarFoundryXmlArmySaver.cs" /> <Compile Include="api\Savers\Xml\WarFoundryXmlGameSystemSaver.cs" />
--- a/api/Savers/IWarFoundryArmySaver.cs Sat Mar 12 20:00:13 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -// This file (IWarFoundryArmySaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 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 IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Savers -{ - public interface IWarFoundryArmySaver - { - /// <summary> - /// Saves an <see cref="Army"/> to a file on disk. - /// </summary> - /// <param name="army"> - /// The <see cref="Army"/> to save - /// </param> - /// <param name="path"> - /// The path to save the army to - /// </param> - /// <returns> - /// TRUE if saving succedes, else FALSE - /// </returns> - bool Save(Army army, string path); - } -} -
--- a/api/Savers/IWarFoundryGameSystemSaver.cs Sat Mar 12 20:00:13 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -// This file (IWarFoundryGameSystemSaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 2009, 2011 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 IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Savers -{ - public interface IWarFoundryGameSystemSaver - { - /// <summary> - /// Saves a <see cref="GameSystem"/> to a file on disk. - /// </summary> - /// <param name="system"> - /// The <see cref="GameSystem"/> to save - /// </param> - /// <param name="path"> - /// The path to save the system to - /// </param> - /// <returns> - /// TRUE if saving succedes, else FALSE - /// </returns> - bool Save(GameSystem system, string path); - } -} \ No newline at end of file
--- a/api/Savers/IWarFoundryRaceSaver.cs Sat Mar 12 20:00:13 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -// This file (IWarFoundryRaceSaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 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 IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API -{ - public interface IWarFoundryRaceSaver - { - /// <summary> - /// Saves an <see cref="Race"/> to a file on disk. - /// </summary> - /// <param name="race"> - /// The <see cref="Race"/> to save - /// </param> - /// <param name="path"> - /// The path to save the army to - /// </param> - /// <returns> - /// TRUE if saving succedes, else FALSE - /// </returns> - bool Save(Race race, string path); - } -} -
--- a/api/Savers/Xml/WarFoundryXmlArmySaver.cs Sat Mar 12 20:00:13 2011 +0000 +++ b/api/Savers/Xml/WarFoundryXmlArmySaver.cs Sat Mar 12 20:32:08 2011 +0000 @@ -17,52 +17,9 @@ namespace IBBoard.WarFoundry.API.Savers.Xml { - public class WarFoundryXmlArmySaver : IWarFoundryArmySaver + public class WarFoundryXmlArmySaver { - 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; - } - - public string CreateXmlString(WarFoundryObject toSave) - { - string xmlString = ""; - - if (toSave is Army) - { - xmlString = CreateArmyXmlString((Army)toSave); - } - - return xmlString; - } - - private string CreateArmyXmlString(Army toSave) + public string CreateXmlString(Army toSave) { XmlDocument doc = new XmlDocument(); XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
--- a/api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs Sat Mar 12 20:00:13 2011 +0000 +++ b/api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs Sat Mar 12 20:32:08 2011 +0000 @@ -17,52 +17,9 @@ namespace IBBoard.WarFoundry.API.Savers.Xml { - public class WarFoundryXmlGameSystemSaver : IWarFoundryGameSystemSaver + public class WarFoundryXmlGameSystemSaver { - 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; - } - - public string CreateXmlString(WarFoundryObject toSave) - { - string xmlString = ""; - - if (toSave is GameSystem) - { - xmlString = CreateGameSystemXmlString((GameSystem)toSave); - } - - return xmlString; - } - - private string CreateGameSystemXmlString(GameSystem toSave) + public string CreateXmlString(GameSystem toSave) { XmlDocument doc = new XmlDocument(); XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);