Mercurial > repos > snowblizz-super-API-ideas
comparison api/Factories/Xml/WarFoundryXmlFactory.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 |
---|---|
240 | 240 |
241 cats = catList.ToArray(); | 241 cats = catList.ToArray(); |
242 LogNotifier.DebugFormat(GetType(), "Found {0} categories", cats.Length); | 242 LogNotifier.DebugFormat(GetType(), "Found {0} categories", cats.Length); |
243 | 243 |
244 XmlElement statsElem = (XmlElement)catsElem.NextSibling; | 244 XmlElement statsElem = (XmlElement)catsElem.NextSibling; |
245 Dictionary<string, SystemStats> sysStats = CreateSystemStatsSetFromElement(statsElem); | 245 LoadSystemStatsFromElement(statsElem, system); |
246 string defaultStatsID = statsElem.GetAttribute("defaultStats"); | 246 string defaultStatsID = statsElem.GetAttribute("defaultStats"); |
247 | 247 |
248 LogNotifier.DebugFormat(GetType(), "Complete loading of {0}", system.Name); | 248 LogNotifier.DebugFormat(GetType(), "Complete loading of {0}", system.Name); |
249 system.Categories = cats; | 249 system.Categories = cats; |
250 system.SystemStats = new SystemStatsSet(sysStats); | |
251 system.StandardSystemStatsID = defaultStatsID; | 250 system.StandardSystemStatsID = defaultStatsID; |
252 } | 251 } |
253 else if (obj is Race) | 252 else if (obj is Race) |
254 { | 253 { |
255 Race race = (Race)obj; | 254 Race race = (Race)obj; |
581 { | 580 { |
582 statsSet = system.StandardSystemStats; | 581 statsSet = system.StandardSystemStats; |
583 } | 582 } |
584 else | 583 else |
585 { | 584 { |
586 statsSet = system.SystemStats[statsID]; | 585 statsSet = system.GetSystemStatsForID(statsID); |
587 } | 586 } |
588 | 587 |
589 Stats stats = new Stats(statsSet); | 588 Stats stats = new Stats(statsSet); |
590 | 589 |
591 foreach (XmlElement stat in elem.ChildNodes) | 590 foreach (XmlElement stat in elem.ChildNodes) |
606 stats.SetStats(statsList); | 605 stats.SetStats(statsList); |
607 | 606 |
608 return stats; | 607 return stats; |
609 } | 608 } |
610 | 609 |
611 private Dictionary<string, SystemStats> CreateSystemStatsSetFromElement(XmlElement elem) | 610 private void LoadSystemStatsFromElement(XmlElement elem, GameSystem system) |
612 { | 611 { |
613 Dictionary<string, SystemStats> dict = new Dictionary<string,SystemStats>(); | |
614 | |
615 foreach (XmlElement stats in elem.ChildNodes) | 612 foreach (XmlElement stats in elem.ChildNodes) |
616 { | 613 { |
617 SystemStats sysStats = CreateSystemStatsFromElement(stats); | 614 SystemStats sysStats = CreateSystemStatsFromElement(stats); |
618 dict.Add(sysStats.ID, sysStats); | 615 system.AddSystemStats(sysStats); |
619 } | 616 } |
620 | |
621 return dict; | |
622 } | 617 } |
623 | 618 |
624 private SystemStats CreateSystemStatsFromElement(XmlElement elem) | 619 private SystemStats CreateSystemStatsFromElement(XmlElement elem) |
625 { | 620 { |
626 List<StatSlot> slots = new List<StatSlot>(); | 621 List<StatSlot> slots = new List<StatSlot>(); |