Mercurial > repos > IBBoard.WarFoundry.Plugin.Rollcall
annotate RollcallRaceParser.cs @ 10:395f2bf0549e
Re #17 - Complete core Rollcall loading
* Resolve warning about deprecated constructor
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 09 Apr 2009 15:25:31 +0000 |
parents | 35bc86f8c283 |
children | 9d0d40324494 |
rev | line source |
---|---|
6 | 1 // This file (RollcallRaceParser.cs) is a part of IBBoard.WarFoundry.Plugin.Rollcall library and is copyright 2009 IBBoard. |
2 // | |
3 // 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. | |
4 | |
5 using System; | |
6 using IBBoard.CustomMath; | |
7 using IBBoard.Ini; | |
8 | 8 using IBBoard.IO; |
6 | 9 using IBBoard.Logging; |
10 using IBBoard.WarFoundry.API.Objects; | |
11 | |
12 namespace IBBoard.WarFoundry.Plugin.Rollcall | |
13 { | |
14 /// <summary> | |
15 /// A helper class to construct a base Race object from an INI file | |
16 /// </summary> | |
17 public class RollcallRaceParser | |
18 { | |
19 public static Race ReadRaceDetails(IniFile file) | |
20 { | |
21 string id = null, name = null; | |
8 | 22 id = file.GetSectionLineValue("Army", "BitCodeID"); |
23 | |
24 if (id == null) | |
25 { | |
26 throw new InvalidFileException("BitCodeID field of Rollcall race did not exist"); | |
27 } | |
28 | |
29 id = "Rollcall" + id; | |
30 name = file.GetSectionLineValue("Army", "Name"); | |
31 | |
32 if (name == null) | |
33 { | |
34 throw new InvalidFileException("Name field of Rollcall race did not exist"); | |
35 } | |
36 | |
6 | 37 LogNotifier.Debug(typeof(RollcallRaceParser), "Loading Rollcall race ID "+id); |
10
395f2bf0549e
Re #17 - Complete core Rollcall loading
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
38 Race race = new Race(id, name, RollcallFactory.GetFactory().RollcallSystem, RollcallFactory.GetFactory()); |
6 | 39 race.GameSystem = RollcallFactory.GetFactory().RollcallSystem; |
40 return race; | |
41 } | |
42 | |
43 public static void ReadCategories(IniFile file, Race race) | |
44 { | |
8 | 45 ReadCategories(file["Category"], race); |
46 } | |
47 | |
48 private static void ReadCategories(IniSection categorySection, Race race) | |
49 { | |
50 foreach (string key in categorySection.Keys) | |
6 | 51 { |
8 | 52 string valueString = categorySection.GetLineValue(key); |
6 | 53 string[] values = valueString.Split(','); |
54 | |
55 if (values.Length == 3) | |
56 { | |
57 LogNotifier.Debug(typeof(RollcallRaceParser), "Loading category " + values[0]); | |
58 Category category = new Category(key, values[0]); | |
59 int minPercent = NumberParser.ParseAsInt(values[1], 0); | |
60 int maxPercent = NumberParser.ParseAsInt(values[2], 100); | |
61 maxPercent = Math.Max(0, Math.Min(100, Math.Max(minPercent, maxPercent))); | |
62 minPercent = Math.Max(0, Math.Min(100, minPercent)); | |
63 category.MaximumPercentage = maxPercent; | |
64 category.MinimumPercentage = minPercent; | |
65 race.AddCategory(category); | |
66 | |
67 } | |
8 | 68 else |
69 { | |
70 LogNotifier.Warn(typeof(RollcallRaceParser), "Ignored non-standard category: "+key); | |
71 } | |
6 | 72 //Special cases (allies and aliases) need to be handled later |
73 } | |
74 } | |
75 | |
76 public static void ReadUnitTypeAndEquipmentSections(IniFile file, Race race) | |
77 { | |
78 foreach (IniSection section in file) | |
79 { | |
8 | 80 try |
6 | 81 { |
8 | 82 string sectionName = section.Name; |
83 | |
84 if (sectionName == "Army" || sectionName == "Category") | |
85 { | |
86 continue; | |
87 } | |
88 else if (sectionName.StartsWith("Unit")) | |
89 { | |
90 RollcallUnitTypeParser.ReadUnitTypeSection(file, section, race); | |
91 } | |
92 else | |
93 { | |
94 RollcallUnitTypeParser.ReadEquipmentSection(file, section, race); | |
95 } | |
6 | 96 } |
8 | 97 catch (InvalidFileException ex) |
6 | 98 { |
8 | 99 throw new InvalidFileException("Invalid file exception while loading data", ex); |
6 | 100 } |
101 } | |
102 } | |
103 } | |
104 } |