Mercurial > repos > IBBoard.WarFoundry.Plugin.Rollcall
diff RollcallRaceParser.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 | |
children | 35bc86f8c283 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RollcallRaceParser.cs Mon Jan 26 20:31:05 2009 +0000 @@ -0,0 +1,76 @@ +// This file (RollcallRaceParser.cs) is a part of IBBoard.WarFoundry.Plugin.Rollcall library and is copyright 2009 IBBoard. +// +// The file and the library/program it is in are licensed under the GNU LGPL license. Please see COPYING.LGPL for more information and the full license. + +using System; +using IBBoard.CustomMath; +using IBBoard.Ini; +using IBBoard.Logging; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.Plugin.Rollcall +{ + /// <summary> + /// A helper class to construct a base Race object from an INI file + /// </summary> + public class RollcallRaceParser + { + public static Race ReadRaceDetails(IniFile file) + { + string id = null, name = null; + id = "Rollcall" + file["Army"]["BitCodeID"].Value; + name = file["Army"]["Name"].Value; + LogNotifier.Debug(typeof(RollcallRaceParser), "Loading Rollcall race ID "+id); + Race race = new Race(id, name, "Rollcall", RollcallFactory.GetFactory()); + race.GameSystem = RollcallFactory.GetFactory().RollcallSystem; + return race; + } + + public static void ReadCategories(IniFile file, Race race) + { + IniSection section = file["Category"]; + + foreach (string key in section.Keys) + { + string valueString = section[key].Value; + string[] values = valueString.Split(','); + + if (values.Length == 3) + { + LogNotifier.Debug(typeof(RollcallRaceParser), "Loading category " + values[0]); + Category category = new Category(key, values[0]); + int minPercent = NumberParser.ParseAsInt(values[1], 0); + int maxPercent = NumberParser.ParseAsInt(values[2], 100); + maxPercent = Math.Max(0, Math.Min(100, Math.Max(minPercent, maxPercent))); + minPercent = Math.Max(0, Math.Min(100, minPercent)); + category.MaximumPercentage = maxPercent; + category.MinimumPercentage = minPercent; + race.AddCategory(category); + + } + //Special cases (allies and aliases) need to be handled later + } + } + + public static void ReadUnitTypeAndEquipmentSections(IniFile file, Race race) + { + foreach (IniSection section in file) + { + string sectionName = section.Name; + + if (sectionName == "Army" || sectionName == "Category") + { + continue; + } + else if (sectionName.StartsWith("Unit")) + { + RollcallUnitTypeParser.ReadUnitTypeSection(file, section, race); + } + else + { + RollcallUnitTypeParser.ReadEquipmentSection(file, section, race); + } + } + } + } +}