Mercurial > repos > IBBoard.WarFoundry.Plugin.Rollcall
view RollcallRaceParser.cs @ 11:9d0d40324494
* Update Rollcall plugin to use GPLv3 headers
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 25 Jun 2009 19:51:39 +0000 |
parents | 395f2bf0549e |
children | 9aecf6628eb0 |
line wrap: on
line source
// This file (RollcallRaceParser.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 IBBoard.CustomMath; using IBBoard.Ini; using IBBoard.IO; 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 = file.GetSectionLineValue("Army", "BitCodeID"); if (id == null) { throw new InvalidFileException("BitCodeID field of Rollcall race did not exist"); } id = "Rollcall" + id; name = file.GetSectionLineValue("Army", "Name"); if (name == null) { throw new InvalidFileException("Name field of Rollcall race did not exist"); } LogNotifier.Debug(typeof(RollcallRaceParser), "Loading Rollcall race ID "+id); Race race = new Race(id, name, RollcallFactory.GetFactory().RollcallSystem, RollcallFactory.GetFactory()); race.GameSystem = RollcallFactory.GetFactory().RollcallSystem; return race; } public static void ReadCategories(IniFile file, Race race) { ReadCategories(file["Category"], race); } private static void ReadCategories(IniSection categorySection, Race race) { foreach (string key in categorySection.Keys) { string valueString = categorySection.GetLineValue(key); 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); } else { LogNotifier.Warn(typeof(RollcallRaceParser), "Ignored non-standard category: "+key); } //Special cases (allies and aliases) need to be handled later } } public static void ReadUnitTypeAndEquipmentSections(IniFile file, Race race) { foreach (IniSection section in file) { try { 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); } } catch (InvalidFileException ex) { throw new InvalidFileException("Invalid file exception while loading data", ex); } } } } }