Mercurial > repos > IBDev-IBBoard.WarFoundry.API
changeset 38:548cfc776f54
Fixes #34 - Remove "Choices" and "Base/Increment" from Category
* Remove Choices and Base/Increment from code
Re #47: Remove magic numbers
* Replace "-1" magic number with WarFoundryCore.INFINITY
* Use INFINITY instead of -1 in code
* Use INF in schemas instead of -1
* Handle and parse INF as a special value in XML Factory
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 19 Mar 2009 20:11:07 +0000 |
parents | 465a215a21a2 |
children | 05c6745cc660 |
files | api/Objects/Category.cs api/Objects/EquipmentItem.cs api/Objects/GameSystem.cs api/Objects/Unit.cs api/Objects/UnitEquipmentItemObj.cs api/Objects/UnitType.cs api/WarFoundryCore.cs dtds/race.xsd dtds/warfoundry-cats.xsd dtds/warfoundry-core.xsd |
diffstat | 10 files changed, 31 insertions(+), 120 deletions(-) [+] |
line wrap: on
line diff
--- a/api/Objects/Category.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/Objects/Category.cs Thu Mar 19 20:11:07 2009 +0000 @@ -14,14 +14,9 @@ public class Category : WarFoundryObject { private int minPts = 0; - private int maxPts = -1; + private int maxPts = WarFoundryCore.INFINITY; private int minPc = 0; private int maxPc = 100; - private int minChoice = 0; - private int maxChoice = -1; - private int baseVal = 0; - private int incVal = 0; - private int incAmount = 0; public Category(string id, string name) : base(id, name) @@ -35,9 +30,6 @@ MaximumPoints = maxPoints; MinimumPercentage = minPercent; MaximumPercentage = maxPercent; - BaseValue = baseValue; - IncrementValue = incrementValue; - IncrementAmount = incrementAmount; } protected override string DefaultName() @@ -60,14 +52,14 @@ get { return maxPts; } set { - maxPts = (value >= -1 ? value : -1); + maxPts = (value >= 0 ? value : WarFoundryCore.INFINITY); CheckMinimumPoints(); } } private void CheckMinimumPoints() { - if (MinimumPoints > MaximumPoints && MaximumPoints!=-1) + if (MinimumPoints > MaximumPoints && MaximumPoints!=WarFoundryCore.INFINITY) { MinimumPoints = MaximumPoints; LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum points limit greater than its maximum points limit.", Name, ID); @@ -114,52 +106,5 @@ LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum percentage limit greater than its maximum percentage limit.", Name, ID); } } - - public int MinimumChoices - { - get { return minChoice; } - set - { - minChoice = (value >= 0 ? value : 0); - CheckMinimumChoices(); - } - } - - public int MaximumChoices - { - get { return maxChoice; } - set - { - maxChoice = (value >= -1 ? value : -1); - CheckMinimumChoices(); - } - } - - private void CheckMinimumChoices() - { - if (MinimumPercentage > MaximumPercentage && MaximumPercentage!=-1) - { - MinimumPercentage = MaximumPercentage; - LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum number of choices greater than its maximum number of choices.", Name, ID); - } - } - - public int BaseValue - { - get { return baseVal; } - set { baseVal = (value >= 0 ? value : 0); } - } - - public int IncrementValue - { - get { return incVal; } - set { incVal = (value >= 0 ? value : 0); } - } - - public int IncrementAmount - { - get { return incAmount; } - set { incAmount = (value >= 0 ? value : 0); } - } } }
--- a/api/Objects/EquipmentItem.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/Objects/EquipmentItem.cs Thu Mar 19 20:11:07 2009 +0000 @@ -35,9 +35,9 @@ get { return min; } set { - min = (value >= 0 || value == -1) ? value : 0; + min = (value >= 0 || value == WarFoundryCore.INFINITY) ? value : 0; - if (MaxNumber != -1 && min > MaxNumber) + if (MaxNumber != WarFoundryCore.INFINITY && min > MaxNumber) { MaxNumber = min; } @@ -49,9 +49,9 @@ get { return max; } set { - max = (value > 0 || value == -1) ? value : -1; + max = (value > 0 || value == WarFoundryCore.INFINITY) ? value : WarFoundryCore.INFINITY; - if (max != -1 && MinNumber > max) + if (max != WarFoundryCore.INFINITY && MinNumber > max) { MinNumber = max; }
--- a/api/Objects/GameSystem.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/Objects/GameSystem.cs Thu Mar 19 20:11:07 2009 +0000 @@ -160,7 +160,7 @@ public bool UnitTypeMaxed(UnitType unitType, Army army) { - return unitType.MaxNumber!=-1 && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber; + return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber; } public bool UnitTypeMinned(UnitType unitType, Army army)
--- a/api/Objects/Unit.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/Objects/Unit.cs Thu Mar 19 20:11:07 2009 +0000 @@ -99,7 +99,7 @@ } else { - if (count == -1) + if (count == WarFoundryCore.INFINITY) { points+= size * equipItem.Cost; } @@ -288,7 +288,7 @@ } else { - if (amount >=1 || amount == -1) + if (amount >=1 || amount == WarFoundryCore.INFINITY) { amount = (float)Math.Round(amount); } @@ -307,7 +307,7 @@ if (amount!=oldAmount) { - if (amount > 0 || amount == -1) + if (amount > 0 || amount == WarFoundryCore.INFINITY) { equipment[equipID] = amount; } @@ -369,41 +369,5 @@ { get { return UnitType.UnitStats; } } - - /*public override string ToXmlString() - { - StringBuilder sb = new StringBuilder(); - float amount; - - foreach(string key in equipment.Keys) - { - amount = (float)equipment[key]; - - if (amount > 0 || amount == -1) - { - sb.Append("<equipItem id=\""+key+"\" amount=\""+amount+"\" />"); - } - } - - string equipmentString; - - if (sb.Length > 0) - { - equipmentString = "<equipment>"+sb.ToString()+"</equipment>"; - } - else - { - equipmentString = ""; - } - - if (equipmentString == "") - { - return "<unit id=\""+ID+"\" unitType=\""+UnitType.ID+"\" unitName=\""+name+"\" size=\""+Size+"\" />"; - } - else - { - return "<unit id=\""+ID+"\" unitType=\""+UnitType.ID+"\" unitName=\""+name+"\" size=\""+Size+"\">"+equipmentString+"</unit>"; - } - }*/ } }
--- a/api/Objects/UnitEquipmentItemObj.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/Objects/UnitEquipmentItemObj.cs Thu Mar 19 20:11:07 2009 +0000 @@ -58,7 +58,7 @@ } else { - if (amount == -1) + if (amount == WarFoundryCore.INFINITY) { return "all"; }
--- a/api/Objects/UnitType.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/Objects/UnitType.cs Thu Mar 19 20:11:07 2009 +0000 @@ -85,7 +85,7 @@ get { return maxSize; } set { - maxSize = (value >= -1 ? value : -1); + maxSize = (value >= 0 ? value : WarFoundryCore.INFINITY); CheckMinimumSize(); } } @@ -110,14 +110,14 @@ get { return max; } set { - max = (value >= -1 ? value : -1); + max = (value >= 0 ? value : WarFoundryCore.INFINITY); CheckMinimumNumber(); } } private void CheckMinimumNumber() { - if (MinNumber > MaxNumber && MaxNumber!=-1) + if (MinNumber > MaxNumber && MaxNumber!=WarFoundryCore.INFINITY) { MinNumber = MaxNumber; LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum number greater than their maximum number.", Name, ID); @@ -126,7 +126,7 @@ private void CheckMinimumSize() { - if (MinSize > MaxSize && MaxSize!=-1) + if (MinSize > MaxSize && MaxSize!=WarFoundryCore.INFINITY) { MinSize = MaxSize; LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum size greater than their maximum size.", Name, ID);
--- a/api/WarFoundryCore.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/WarFoundryCore.cs Thu Mar 19 20:11:07 2009 +0000 @@ -10,6 +10,7 @@ { public class WarFoundryCore { + public static readonly int INFINITY = -1; public static event GameSystemChangedDelegate GameSystemChanged; public static event ArmyChangedDelegate ArmyChanged;
--- a/dtds/race.xsd Mon Mar 16 20:53:22 2009 +0000 +++ b/dtds/race.xsd Thu Mar 19 20:11:07 2009 +0000 @@ -33,12 +33,12 @@ <xs:attribute name="id" type="xs:ID" /> <xs:attribute name="typeName" type="xs:string" use="required"/> <xs:attribute name="cat" type="xs:string" use="required"/> - <xs:attribute name="unitPoints" type="core:nonNegativeDecimal" default="0"/> - <xs:attribute name="points" type="core:nonNegativeDecimal" use="required"/> + <xs:attribute name="unitPoints" type="core:nonNegativeDouble" default="0"/> + <xs:attribute name="points" type="core:nonNegativeDouble" use="required"/> <xs:attribute name="minNum" type="xs:nonNegativeInteger" default="0"/> - <xs:attribute name="maxNum" type="xs:integer" default="-1"/> + <xs:attribute name="maxNum" type="xs:positiveInteger" default="INF"/> <xs:attribute name="minSize" type="xs:positiveInteger" default="5"/> - <xs:attribute name="maxSize" type="xs:integer" default="-1"/> + <xs:attribute name="maxSize" type="xs:positiveInteger" default="INF"/> <xs:attribute name="baseSize" type="xs:nonNegativeInteger" default="0"/> </xs:complexType> <xs:complexType name="statstype"> @@ -62,8 +62,8 @@ <xs:attribute name="id" type="xs:IDREF" /> <xs:attribute name="required" type="xs:boolean" default="false"/> <xs:attribute name="exclusivityGroup" type="xs:string" default=""/> - <xs:attribute name="minNum" type="xs:integer" default="-1"/> - <xs:attribute name="maxNum" type="xs:integer" default="-1"/> + <xs:attribute name="minNum" type="xs:positiveInteger" default="INF"/> + <xs:attribute name="maxNum" type="xs:positiveInteger" default="INF"/> <xs:attribute name="minPercentage" type="core:percentage" default="100"/> <xs:attribute name="maxPercentage" type="core:percentage" default="100"/> <xs:attribute name="roundDirection" type="updowntype" default="up"/> @@ -126,7 +126,7 @@ </xs:all> <xs:attribute name="id" type="xs:ID" use="required"/> <xs:attribute name="name" type="xs:string" use="required"/> - <xs:attribute name="cost" type="core:nonNegativeDecimal" use="required"/> + <xs:attribute name="cost" type="core:nonNegativeDouble" use="required"/> <xs:attribute name="armoutType" type="armourtype" default="none"/> </xs:complexType> <xs:simpleType name="armourtype">
--- a/dtds/warfoundry-cats.xsd Mon Mar 16 20:53:22 2009 +0000 +++ b/dtds/warfoundry-cats.xsd Thu Mar 19 20:11:07 2009 +0000 @@ -7,8 +7,8 @@ <xs:complexType> <xs:attribute name="id" type="xs:ID" /> <xs:attribute name="name" type="xs:string" use="required"/> - <xs:attribute name="minPoints" type="core:nonNegativeDecimal" default="0"/> - <xs:attribute name="maxPoints" type="core:infiniteOrNonNegativeDecimal" default="-1"/> + <xs:attribute name="minPoints" type="core:nonNegativeDouble" default="0"/> + <xs:attribute name="maxPoints" type="core:infiniteOrNonNegativeDouble" default="INF"/> <xs:attribute name="minPercentage" type="core:percentage" default="0"/> <xs:attribute name="maxPercentage" type="core:percentage" default="100"/> </xs:complexType>
--- a/dtds/warfoundry-core.xsd Mon Mar 16 20:53:22 2009 +0000 +++ b/dtds/warfoundry-core.xsd Thu Mar 19 20:11:07 2009 +0000 @@ -1,19 +1,20 @@ <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ibboard.co.uk/warfoundry/core" xmlns="http://ibboard.co.uk/warfoundry/core" elementFormDefault="qualified"> -<xs:simpleType name="infiniteOrNonNegativeDecimal"> +<xs:simpleType name="infiniteOrNonNegativeDouble"> <xs:restriction base="xs:double"> - <xs:minInclusive value="-1"/> + <xs:minInclusive value="0"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="infiniteOrNonNegativeInteger"> <xs:restriction base="xs:integer"> - <xs:minInclusive value="-1"/> + <xs:minInclusive value="0"/> </xs:restriction> </xs:simpleType> -<xs:simpleType name="nonNegativeDecimal"> +<xs:simpleType name="nonNegativeDouble"> <xs:restriction base="xs:double"> <xs:minInclusive value="0"/> + <xs:maxExclusive value="INF"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="percentage">