Mercurial > repos > snowblizz-super-API-ideas
changeset 306:886d28c1b6e5
Re #99: Define points systems
* Simplify the code and leave translations until we support them
Re #329 and re #327: Use "points" in UI
* Use new method in UnitEquipmentItem object's ToString() method
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 13 Feb 2011 16:24:12 +0000 |
parents | 92d10b06ab0f |
children | afa7a5dd0eea |
files | api/Objects/EquipmentItem.cs api/Objects/GameSystem.cs api/Objects/UnitEquipmentItem.cs |
diffstat | 3 files changed, 129 insertions(+), 95 deletions(-) [+] |
line wrap: on
line diff
--- a/api/Objects/EquipmentItem.cs Wed Jan 26 20:27:50 2011 +0000 +++ b/api/Objects/EquipmentItem.cs Sun Feb 13 16:24:12 2011 +0000 @@ -44,6 +44,11 @@ { get { return equipForRace; } } + + public GameSystem GameSystem + { + get { return equipForRace.GameSystem; } + } public bool CanBeUsedWithItem(EquipmentItem item) {
--- a/api/Objects/GameSystem.cs Wed Jan 26 20:27:50 2011 +0000 +++ b/api/Objects/GameSystem.cs Sun Feb 13 16:24:12 2011 +0000 @@ -1,14 +1,9 @@ -// This file (GameSystem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. +// This file (GameSystem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009, 2010, 2011 IBBoard. // // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. -using System; using System.Collections.Generic; -using System.Xml; -using System.IO; -using IBBoard.Logging; using IBBoard.WarFoundry.API.Factories; -using ICSharpCode.SharpZipLib.Zip; namespace IBBoard.WarFoundry.API.Objects { @@ -17,41 +12,65 @@ /// </summary> public class GameSystem : WarFoundryStagedLoadingObject { - private static int SYSTEM_DEFAULT_ARMY_SIZE = 1000; - private bool warnOnError; + private static int SYSTEM_DEFAULT_ARMY_SIZE = 1000; + private bool warnOnError; private bool allowAllies; - private Dictionary<string, Category> categories = new Dictionary<string,Category>(); - private Dictionary<string, SystemStats> stats = new Dictionary<string,SystemStats>(); + private Dictionary<string, Category> categories = new Dictionary<string, Category>(); + private Dictionary<string, SystemStats> stats = new Dictionary<string, SystemStats>(); private string defaultStats; - private int defaultArmySize; + private int defaultArmySize; + private string systemPtsAbbrevSingle; + private string systemPtsAbbrevPlural; + private string systemPtsNameSingle; + private string systemPtsNamePlural; public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory) : base(systemID, systemName, creatingFactory) { - stats = new Dictionary<string,SystemStats>(); + stats = new Dictionary<string, SystemStats>(); } - public int SystemArmyDefaultSize - { - get { return defaultArmySize; } - set - { - if (value == 0) - { - defaultArmySize = SYSTEM_DEFAULT_ARMY_SIZE; - } - else - { - defaultArmySize = value; - } - } - } - + public int SystemArmyDefaultSize + { + get { return defaultArmySize; } + set + { + if (value == 0) + { + defaultArmySize = SYSTEM_DEFAULT_ARMY_SIZE; + } + else + { + defaultArmySize = value; + } + } + } + + public string SystemPtsAbbrevSingle + { + get { return systemPtsAbbrevSingle; } + set { systemPtsAbbrevSingle = value; } + } + public string SystemPtsAbbrevPlural + { + get { return systemPtsAbbrevPlural; } + set { systemPtsAbbrevPlural = value; } + } + public string SystemPtsNameSingle + { + get { return systemPtsNameSingle; } + set { systemPtsNameSingle = value; } + } + public string SystemPtsNamePlural + { + get { return systemPtsNamePlural; } + set { systemPtsNamePlural = value; } + } public bool AllowAllies { get { return allowAllies; } set { allowAllies = value; } } - + public void AddCategory(Category cat) { RawCategories[cat.ID] = cat; @@ -64,25 +83,25 @@ RawCategories.TryGetValue(id, out cat); return cat; } - + public void SetCategory(Category cat) { Category old; RawCategories.TryGetValue(cat.ID, out old); - - if(old == null) + + if (old == null) { AddCategory(cat); } else { - if(!old.Equals(cat)) + if (!old.Equals(cat)) { RawCategories[old.ID] = cat; } } } - + public void RemoveCategory(string id) { RawCategories.Remove(id); @@ -90,13 +109,13 @@ public Category[] Categories { - get - { + get + { EnsureFullyLoaded(); - return DictionaryUtils.ToArray<string, Category>(RawCategories); + return DictionaryUtils.ToArray<string, Category>(RawCategories); } } - + protected Dictionary<string, Category> RawCategories { get { return categories; } @@ -110,12 +129,12 @@ } set { warnOnError = value; } } - + public void AddSystemStats(SystemStats sysStats) { stats[sysStats.ID] = sysStats; } - + public SystemStats StandardSystemStats { get @@ -124,7 +143,7 @@ return stats[defaultStats]; } } - + public string StandardSystemStatsID { get @@ -132,7 +151,7 @@ EnsureFullyLoaded(); return defaultStats; } - + set { if (value != null && value.Trim().Length > 0) @@ -144,15 +163,15 @@ public SystemStats[] SystemStats { - get - { + get + { EnsureFullyLoaded(); SystemStats[] statsArray = new SystemStats[stats.Count]; stats.Values.CopyTo(statsArray, 0); return statsArray; } } - + public SystemStats GetSystemStatsForID(string id) { EnsureFullyLoaded(); @@ -160,30 +179,30 @@ stats.TryGetValue(id, out statsForID); return statsForID; } - + public void SetSystemStats(SystemStats newStats) { SystemStats old; stats.TryGetValue(newStats.ID, out old); - - if(old == null) + + if (old == null) { AddSystemStats(newStats); } else { - if(!old.Equals(newStats)) + if (!old.Equals(newStats)) { stats[old.ID] = newStats; } } } - + public void RemoveSystemStats(string id) { stats.Remove(id); } - + public Race SystemDefaultRace { get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); } @@ -191,7 +210,7 @@ public bool Matches(GameSystem otherSystem) { - if (otherSystem==null) + if (otherSystem == null) { return false; } @@ -203,9 +222,9 @@ { if (obj == null) { - return false; + return false; } - + if (obj.GetType().Equals(this.GetType())) { GameSystem otherSystem = (GameSystem)obj; @@ -220,95 +239,105 @@ public override int GetHashCode() { - return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode(); + return ID.GetHashCode() + Name.GetHashCode() + (RawCategories != null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode(); } public bool UnitTypeMaxed(UnitType unitType, Army army) { - return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber; + return unitType.MaxNumber != WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber; } public bool UnitTypeMinned(UnitType unitType, Army army) { return army.GetUnitTypeCount(unitType) <= unitType.MinNumber; } - + public List<EquipmentItem> GetSystemEquipmentList() { List<EquipmentItem> items = new List<EquipmentItem>(); Race defaultRace = SystemDefaultRace; - - if (defaultRace!=null) - { + + if (defaultRace != null) + { items = defaultRace.GetEquipmentList(); } - + return items; } - + public EquipmentItem GetSystemEquipmentItem(string id) { EquipmentItem item = null; Race defaultRace = SystemDefaultRace; - - if (defaultRace!=null) - { + + if (defaultRace != null) + { item = defaultRace.GetEquipmentItem(id); } - + return item; } - + public UnitType[] GetSystemUnitTypes(Category cat) { UnitType[] items = new UnitType[0]; Race defaultRace = SystemDefaultRace; - - if (defaultRace!=null) - { + + if (defaultRace != null) + { items = defaultRace.GetUnitTypes(cat); } - + return items; } - + public UnitType GetSystemUnitType(string id) { UnitType unit = null; Race defaultRace = SystemDefaultRace; - - if (defaultRace!=null) - { + + if (defaultRace != null) + { unit = defaultRace.GetUnitType(id); } - + return unit; } - + public List<Ability> GetSystemAbilityList() { List<Ability> items = new List<Ability>(); Race defaultRace = SystemDefaultRace; - - if (defaultRace!=null) - { + + if (defaultRace != null) + { items = defaultRace.GetAbilityList(); } - + return items; } - + public Ability GetSystemAbility(string id) { Ability ability = null; Race defaultRace = SystemDefaultRace; - - if (defaultRace!=null) - { + + if (defaultRace != null) + { ability = defaultRace.GetAbility(id); } - + return ability; } + + public string GetPointsAbbrev(double pointTemp) + { + return (pointTemp == 1 ? SystemPtsAbbrevSingle : SystemPtsAbbrevPlural); + } + + public string GetPointsName(double pointTemp) + { + return (pointTemp == 1 ? SystemPtsNameSingle : SystemPtsNamePlural); + } } }
--- a/api/Objects/UnitEquipmentItem.cs Wed Jan 26 20:27:50 2011 +0000 +++ b/api/Objects/UnitEquipmentItem.cs Sun Feb 13 16:24:12 2011 +0000 @@ -5,7 +5,8 @@ using System; using IBBoard.CustomMath; using IBBoard.Limits; -using IBBoard.WarFoundry.API.Util; +using IBBoard.WarFoundry.API.Util; +using IBBoard.Lang; //using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry.API.Objects @@ -24,12 +25,7 @@ private UnitType unitType; private string slotName = ""; private ILimit minLimit; - private ILimit maxLimit; - public GameSystem CurrentGameSystem - { - get { return WarFoundryCore.CurrentGameSystem; } - set { WarFoundryCore.CurrentGameSystem = value; } - } + private ILimit maxLimit; public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor) : this(equipmentItem, equipmentFor, new string[0]) { @@ -68,7 +64,6 @@ } } - public string EquipmentItemID { get { return item.ID; } @@ -111,6 +106,11 @@ get { return roundUp; } set { roundUp = value; } } + + public GameSystem GameSystem + { + get { return EquipmentItem.GameSystem; } + } public String[] MutexGroups { @@ -198,7 +198,7 @@ public override string ToString() { - return CurrentGameSystem.setUnitEquipmentItemName(EquipmentItem.Name, Cost); + return Translation.GetTranslation("UnitEquipmentItemName", "{0} ({1}{2} each)", Name, Cost, GameSystem.GetPointsAbbrev(Cost)); } public bool HasAlternatives()