comparison api/Objects/GameSystem.cs @ 6:150a5669cd7b

Re #9 - more granular loading * Remove SystemStatsSet class so that other classes don't know the internals of how GameSystem stores its stats (cleaner code principle) * Make XML loader each stats set and add to the game system * Add methods to GameSystem to remove use of SystemStatsSet and hide internal handling * Add methods to add SystemStats to GameSystem
author IBBoard <dev@ibboard.co.uk>
date Sun, 04 Jan 2009 12:13:59 +0000
parents 520818033bb6
children 613bc5eaac59
comparison
equal deleted inserted replaced
5:b9346894319c 6:150a5669cd7b
13 /// </summary> 13 /// </summary>
14 public class GameSystem : WarFoundryObject // WarFoundryStagedLoadSourceObject 14 public class GameSystem : WarFoundryObject // WarFoundryStagedLoadSourceObject
15 { 15 {
16 private bool warnOnError; 16 private bool warnOnError;
17 private Category[] categories; 17 private Category[] categories;
18 private SystemStatsSet stats; 18 private Dictionary<string, SystemStats> stats;
19 private string defaultStats; 19 private string defaultStats;
20 private FileInfo sourceFile; 20 private FileInfo sourceFile;
21 21
22 public GameSystem(string systemID, string systemName) : base(systemID, systemName) 22 public GameSystem(string systemID, string systemName) : base(systemID, systemName)
23 { 23 {
24 stats = new Dictionary<string,SystemStats>();
24 } 25 }
25 26
26 /*public void CompleteLoading(Category[] cats, Dictionary<string, SystemStats> sysStats, string defaultStatsID) 27 /*public void CompleteLoading(Category[] cats, Dictionary<string, SystemStats> sysStats, string defaultStatsID)
27 { 28 {
28 categories = cats; 29 categories = cats;
47 return categories[index]; 48 return categories[index];
48 } 49 }
49 50
50 public Category GetCategory(string id) 51 public Category GetCategory(string id)
51 { 52 {
52 for (int i = 0; i<categories.Length; i++) 53 Category categoryForID = null;
53 { 54
54 if (categories[i].ID == id) 55 for (int i = 0; i<Categories.Length; i++)
56 {
57 Category cat = Categories[i];
58 if (cat.ID == id)
55 { 59 {
56 return categories[i]; 60 categoryForID = cat;
57 } 61 }
58 } 62 }
59 63
60 return null; 64 return categoryForID;
61 } 65 }
62 66
63 public Category[] Categories 67 public Category[] Categories
64 { 68 {
65 get 69 get
106 return warnOnError; 110 return warnOnError;
107 } 111 }
108 set { warnOnError = value; } 112 set { warnOnError = value; }
109 } 113 }
110 114
115 public void AddSystemStats(SystemStats sysStats)
116 {
117 stats[sysStats.ID] = sysStats;
118 }
119
111 public SystemStats StandardSystemStats 120 public SystemStats StandardSystemStats
112 { 121 {
113 get 122 get
114 { 123 {
115 return SystemStats[defaultStats]; 124 return stats[defaultStats];
116 } 125 }
117 } 126 }
118 127
119 public string StandardSystemStatsID 128 public string StandardSystemStatsID
120 { 129 {
130 defaultStats = value; 139 defaultStats = value;
131 } 140 }
132 } 141 }
133 } 142 }
134 143
135 public SystemStatsSet SystemStats 144 public SystemStats[] SystemStats
136 { 145 {
137 get 146 get
138 { 147 {
139 return stats; 148 SystemStats[] statsArray = new SystemStats[stats.Count];
140 } 149 stats.Values.CopyTo(statsArray, 0);
141 set 150 return statsArray;
142 { 151 }
143 stats = value; 152 }
144 } 153
154 public SystemStats GetSystemStatsForID(string id)
155 {
156 SystemStats statsForID;
157 stats.TryGetValue(id, out statsForID);
158 return statsForID;
145 } 159 }
146 160
147 public Race SystemDefaultRace 161 public Race SystemDefaultRace
148 { 162 {
149 get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); } 163 get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); }