Mercurial > repos > IBBoard.WarFoundry.Plugin.Rollcall
changeset 4:c82b194801dc
Re #21 - File loading in order
* Use new methods
* Only add GameSystem to returned collection once
Also
* Cleaner loading of objects
* Replace use of deprecated Category constructor
* Specify GameSystem of Race
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 25 Jan 2009 14:16:32 +0000 |
parents | 2a21138f50ed |
children | 8c34e01a11da |
files | RollcallFactory.cs |
diffstat | 1 files changed, 27 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/RollcallFactory.cs Sun Jan 18 20:54:26 2009 +0000 +++ b/RollcallFactory.cs Sun Jan 25 14:16:32 2009 +0000 @@ -30,11 +30,19 @@ namespace IBBoard.WarFoundry.Plugin.Rollcall { public class RollcallFactory : AbstractNonNativeFileExtensionWarFoundryFactory - { + { + private GameSystem rollcallSystem; + private bool addedSystem = false; + public static RollcallFactory CreateFactory() { return new RollcallFactory(); } + + private RollcallFactory() + { + rollcallSystem = new GameSystem("Rollcall", "Rollcall armies", this); + } public override string NonNativeDataType { @@ -56,23 +64,21 @@ protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FileInfo file) { - ICollection<IWarFoundryObject> objects = null; - IWarFoundryObject obj = null; + ICollection<IWarFoundryObject> objects = new List<IWarFoundryObject>(); - if (IsRaceFile(file)) + if (CheckCanHandleFileAsRace(file)) { - obj = CreateRaceFromFile(file); + objects.Add(CreateRaceFromFile(file)); } - else if (IsArmyFile(file)) + else if (CheckCanHandleFileAsArmy(file)) { - obj = CreateArmyFromFile(file); + objects.Add(CreateArmyFromFile(file)); } - if (obj != null) + if (!addedSystem && objects.Count > 0) { - objects = new List<IWarFoundryObject>(); - objects.Add(obj); - objects.Add(new GameSystem("Rollcall", "Rollcall armies", this)); + objects.Add(rollcallSystem); + addedSystem = true; } return objects; @@ -80,7 +86,7 @@ protected override Army CreateArmyFromFile (FileInfo file) { - return null; + throw new NotImplementedException(); } protected override Race CreateRaceFromFile(FileInfo file) @@ -98,7 +104,9 @@ id = "Rollcall" + file["Army"]["BitCodeID"].Value; name = file["Army"]["Name"].Value; LogNotifier.Debug(GetType(), "Loading Rollcall race ID "+id); - return new Race(id, name, "Rollcall", this); + Race race = new Race(id, name, "Rollcall", this); + race.GameSystem = rollcallSystem; + return race; } private void ReadCategories(IniFile file, Race race) @@ -119,7 +127,11 @@ int.TryParse(values[2], out maxPercent); maxPercent = Math.Max(0, Math.Min(100, Math.Max(minPercent, maxPercent))); minPercent = Math.Max(0, Math.Min(100, minPercent)); - race.AddCategory(new Category(key, values[0], 0, 0, minPercent, maxPercent, 0, -1, 0, 0, 0)); + Category category = new Category(key, values[0]); + category.MaximumPercentage = maxPercent; + category.MinimumPercentage = minPercent; + race.AddCategory(category); + } //Special cases (allies and aliases) need to be handled later } @@ -193,9 +205,7 @@ protected override GameSystem CreateGameSystemFromFile (FileInfo file) { - //Return null because there is no such thing - //TODO Determine whether we should exception - return null; + throw new InvalidDataException("No such file format (Rollcall GameSystem)"); } } }