Mercurial > repos > IBDev-IBBoard.WarFoundry.API
diff api/Objects/GameSystem.cs @ 8:613bc5eaac59
Re #9 - Make WarFoundry loading granular
* Remove specific staged loading classes
* Rework category loading for GameSystem and Race to make it use AddCategory(Category) method
* Promote staged loading from Native Factory to all Factories level
* Refactor XML Factory to use smaller methods
Also removed some commented code that isn't used any more
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 04 Jan 2009 19:24:13 +0000 |
parents | 150a5669cd7b |
children | 0770e5cbba7c |
line wrap: on
line diff
--- a/api/Objects/GameSystem.cs Sun Jan 04 13:12:55 2009 +0000 +++ b/api/Objects/GameSystem.cs Sun Jan 04 19:24:13 2009 +0000 @@ -1,3 +1,21 @@ +// GameSystem.cs is a part of the IBBoard.WarFoundry.API library (referred to from here as "this program") +// +// Copyright (C) 2009 IBBoard +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + using System; using System.Collections.Generic; using System.Xml; @@ -11,15 +29,14 @@ /// <summary> /// Summary description for GameSystem. /// </summary> - public class GameSystem : WarFoundryObject // WarFoundryStagedLoadSourceObject + public class GameSystem : WarFoundryStagedLoadingObject { private bool warnOnError; - private Category[] categories; - private Dictionary<string, SystemStats> stats; - private string defaultStats; - private FileInfo sourceFile; + private Dictionary<string, Category> categories = new Dictionary<string,Category>(); + private Dictionary<string, SystemStats> stats = new Dictionary<string,SystemStats>(); + private string defaultStats; - public GameSystem(string systemID, string systemName) : base(systemID, systemName) + public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory) : base(systemID, systemName, creatingFactory) { stats = new Dictionary<string,SystemStats>(); } @@ -32,75 +49,31 @@ base.CompleteLoading(); }*/ - public FileInfo SourceFile + public void AddCategory(Category cat) { - get { return sourceFile; } - set { sourceFile = value; } - } - - public int GetCategoryCount() - { - return categories.Length; - } - - public Category GetCategory(int index) - { - return categories[index]; + RawCategories[cat.ID] = cat; } public Category GetCategory(string id) { - Category categoryForID = null; - - for (int i = 0; i<Categories.Length; i++) - { - Category cat = Categories[i]; - if (cat.ID == id) - { - categoryForID = cat; - } - } - - return categoryForID; + EnsureFullyLoaded(); + Category cat = null; + RawCategories.TryGetValue(id, out cat); + return cat; } public Category[] Categories { get - { - return SystemCategories; - } - set - { - SystemCategories = value; + { + EnsureFullyLoaded(); + return DictionaryToArrayConverter.Convert<string, Category>(RawCategories); } } - protected virtual Category[] SystemCategories + protected Dictionary<string, Category> RawCategories { - get - { - return RawSystemCategories; - } - set - { - RawSystemCategories = value; - } - } - - protected Category[] RawSystemCategories - { - get - { - return categories; - } - set - { - if (value!=null) - { - categories = value; - } - } + get { return categories; } } public bool WarnOnError @@ -145,6 +118,7 @@ { get { + EnsureFullyLoaded(); SystemStats[] statsArray = new SystemStats[stats.Count]; stats.Values.CopyTo(statsArray, 0); return statsArray; @@ -153,6 +127,7 @@ public SystemStats GetSystemStatsForID(string id) { + EnsureFullyLoaded(); SystemStats statsForID; stats.TryGetValue(id, out statsForID); return statsForID; @@ -184,7 +159,7 @@ { GameSystem otherSystem = (GameSystem)obj; - return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawSystemCategories == null && otherSystem.RawSystemCategories == null) || this.RawSystemCategories.Equals(otherSystem.RawSystemCategories)); + return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawCategories == null && otherSystem.RawCategories == null) || this.RawCategories.Equals(otherSystem.RawCategories)); } else { @@ -194,7 +169,7 @@ public override int GetHashCode() { - return ID.GetHashCode() + Name.GetHashCode() + (RawSystemCategories!=null ? RawSystemCategories.GetHashCode() : 0) + warnOnError.GetHashCode(); + return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode(); } public bool UnitTypeMaxed(UnitType unitType, Army army)