view RollcallFactory.cs @ 6:0509ed2e686a

Re #16 - File loading * Refactor race detail parsing and unit type parsing in to their own classes Re #17 - Unit detail loading * Add a couple of extra attributes to those loaded
author IBBoard <dev@ibboard.co.uk>
date Mon, 26 Jan 2009 20:31:05 +0000
parents 8c34e01a11da
children 35bc86f8c283
line wrap: on
line source

// This file (RollcallFactory.cs) is a part of the IBBoard.WarFoundry.Plugin.Rollcall project and is copyright 2009 IBBoard.
//
// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.

using System;
using System.Collections.Generic;
using System.IO;
using IBBoard.Ini;
using IBBoard.IO;
using IBBoard.Logging;
using IBBoard.WarFoundry.API.Factories;
using IBBoard.WarFoundry.API.Objects;

namespace IBBoard.WarFoundry.Plugin.Rollcall
{
	public class RollcallFactory : AbstractNonNativeFileExtensionWarFoundryFactory
	{
		private static RollcallFactory factory;
		private GameSystem rollcallSystem;
		private bool addedSystem = false;
		
		public static RollcallFactory GetFactory()
		{
			if (factory == null)
			{
				factory = new RollcallFactory();
			}
			
			return factory;
		}

		private RollcallFactory()
		{
			rollcallSystem = new GameSystem("Rollcall", "Rollcall armies", this);
		}
		
		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"; }
		}

		public GameSystem RollcallSystem
		{
			get
			{
				return rollcallSystem;
			}
		}
		
		protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FileInfo file)
		{			
			ICollection<IWarFoundryObject> objects = new List<IWarFoundryObject>();
			
			if (CheckCanHandleFileAsRace(file))
			{
				objects.Add(CreateRaceFromFile(file));
			}
			else if (CheckCanHandleFileAsArmy(file))
			{
				objects.Add(CreateArmyFromFile(file));
			}
			
			if (!addedSystem && objects.Count > 0)
			{
				objects.Add(RollcallSystem);
				addedSystem = true;
			}
			
			return objects;
		}

		protected override Army CreateArmyFromFile (FileInfo file)
		{			
			throw new NotImplementedException();
		}
		
		protected override Race CreateRaceFromFile(FileInfo file)
		{
			IniFile rollcallFile = IniFileReader.ReadFile(file);			
			Race race = RollcallRaceParser.ReadRaceDetails(rollcallFile);
			RollcallRaceParser.ReadCategories(rollcallFile, race);
			RollcallRaceParser.ReadUnitTypeAndEquipmentSections(rollcallFile, race);
			return race;
		}
		
		protected override GameSystem CreateGameSystemFromFile (FileInfo file)
		{
			throw new InvalidDataException("No such file format (Rollcall GameSystem)");
		}
	}
}