Mercurial > repos > IBBoard.WarFoundry.Plugin.Rollcall
view RollcallFactory.cs @ 0:c387d9f011a4
Initial commit of WarFoundry code
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 19 Dec 2008 15:57:51 +0000 |
parents | |
children | 9b17b3e35b9d |
line wrap: on
line source
// RollcallFactory.cs // // Copyright (C) 2008 IBBoard // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // using System; using System.Collections.Generic; using System.IO; using IBBoard.Logging; using IBBoard.WarFoundry.API.Factories; using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry.Plugin.Rollcall { public class RollcallFactory : AbstractNonNativeFileExtensionWarFoundryFactory { public static RollcallFactory CreateFactory() { return new RollcallFactory(); } public override string NonNativeDataType { get { return "Rollcall ADF files"; } } protected override string ArmyFileExtension { get { return null; } } protected override string GameSystemFileExtension { get { return null; } } protected override string RaceFileExtension { get { return ".adf"; } } protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FileInfo file) { ICollection<IWarFoundryObject> objects = null; IWarFoundryObject obj = null; if (IsRaceFile(file)) { obj = CreateRaceFromFile(file); } else if (IsArmyFile(file)) { obj = CreateArmyFromFile(file); } if (obj != null) { objects = new List<IWarFoundryObject>(); objects.Add(obj); objects.Add(new GameSystem("Rollcall", "Rollcall armies")); } return objects; } protected override Army CreateArmyFromFile (FileInfo file) { return null; } protected override Race CreateRaceFromFile(FileInfo file) { //TODO parse army file StreamReader stream = file.OpenText(); string id = null, name = null; while (!stream.EndOfStream) { string line = stream.ReadLine(); if (line.StartsWith("[")) { string sectionTitle = line.Trim().Substring(1, line.Length - 2); string sectionTitleLower = sectionTitle.ToLower(); if (sectionTitleLower.Equals("army")) { ReadRaceSection(stream, out id, out name); } else if (sectionTitleLower.Equals("category")) { ReadCategorySection(stream); } else if (sectionTitleLower.StartsWith("unit")) { ReadUnitSection(stream, sectionTitle); } else { ReadEquipmentSection(stream, sectionTitle); } } //else ignore the line } LogNotifier.Debug(GetType(), "Loaded race ID "+id); return new Race(id, name, "Rollcall"); } private void ReadRaceSection(StreamReader stream, out string id, out string name) { id = name = null; while (!stream.EndOfStream && stream.Peek() != '[') { string line = stream.ReadLine(); if (line.StartsWith("BitCodeID=")) { id = line.Substring(10); } else if (line.StartsWith("Name=")) { name = line.Substring(5); } } } private void ReadCategorySection(StreamReader stream) { } private void ReadUnitSection(StreamReader stream, string unitSectionTitle) { } private void ReadEquipmentSection(StreamReader stream, string equipmentSectionTitle) { } protected override GameSystem CreateGameSystemFromFile (FileInfo file) { //Return null because there is no such thing //TODO Check whether we should exception return null; } } }