changeset 40:3664eee50390

Fixes #47 - remove magic numbers * Create "infinity" in core types * Redefine special core types without trying to use non-existant INF for Integers * Use new types in Cats and Race * Remove special handling of INF when parsing an integer attribute Closes #46 - Resolve problems using custom restrictions of decimal and double * New schemas seem to work without exceptioning
author IBBoard <dev@ibboard.co.uk>
date Sat, 21 Mar 2009 17:04:33 +0000
parents 05c6745cc660
children 422ddd5fedd1
files api/Factories/Xml/WarFoundryXmlFactory.cs dtds/race.xsd dtds/warfoundry-cats.xsd dtds/warfoundry-core.xsd
diffstat 4 files changed, 26 insertions(+), 31 deletions(-) [+]
line diff
     1.1 --- a/api/Factories/Xml/WarFoundryXmlFactory.cs	Thu Mar 19 20:12:29 2009 +0000
     1.2 +++ b/api/Factories/Xml/WarFoundryXmlFactory.cs	Sat Mar 21 17:04:33 2009 +0000
     1.3 @@ -381,26 +381,14 @@
     1.4  				
     1.5  		private int GetIntValueFromAttribute(XmlElement elem, string attributeName)
     1.6  		{
     1.7 -			string attribValue = elem.GetAttribute(attributeName);
     1.8 -			int intValue = int.MaxValue;
     1.9 -			
    1.10 -			if ("INF".Equals(attribValue))
    1.11 +			try
    1.12  			{
    1.13 -				intValue = WarFoundryCore.INFINITY;
    1.14 +				return int.Parse(elem.GetAttribute(attributeName));
    1.15  			}
    1.16 -			else
    1.17 +			catch(FormatException)
    1.18  			{
    1.19 -				try
    1.20 -				{
    1.21 -					intValue = int.Parse(attribValue);
    1.22 -				}
    1.23 -				catch(FormatException)
    1.24 -				{
    1.25 -					throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid number", attributeName, elem.Name, elem.GetAttribute("id")));
    1.26 -				}
    1.27 +				throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid number", attributeName, elem.Name, elem.GetAttribute("id")));
    1.28  			}
    1.29 -			
    1.30 -			return intValue;
    1.31  		}
    1.32  						
    1.33  		private UnitType CreateUnitTypeFromElement(XmlElement elem, Race parentRace, GameSystem system)
     2.1 --- a/dtds/race.xsd	Thu Mar 19 20:12:29 2009 +0000
     2.2 +++ b/dtds/race.xsd	Sat Mar 21 17:04:33 2009 +0000
     2.3 @@ -33,12 +33,12 @@
     2.4    <xs:attribute name="id" type="xs:ID" />
     2.5    <xs:attribute name="typeName" type="xs:string" use="required"/>
     2.6    <xs:attribute name="cat" type="xs:string" use="required"/>
     2.7 -  <xs:attribute name="unitPoints" type="core:nonNegativeDouble" default="0"/>
     2.8 -  <xs:attribute name="points" type="core:nonNegativeDouble" use="required"/>
     2.9 +  <xs:attribute name="unitPoints" type="core:nonNegativeNonInfiniteDouble" default="0"/>
    2.10 +  <xs:attribute name="points" type="core:nonNegativeNonInfiniteDouble" use="required"/>
    2.11    <xs:attribute name="minNum" type="xs:nonNegativeInteger" default="0"/>
    2.12 -  <xs:attribute name="maxNum" type="xs:positiveInteger" default="INF"/>
    2.13 +  <xs:attribute name="maxNum" type="core:positiveOrInfiniteInteger" default="-1"/>
    2.14    <xs:attribute name="minSize" type="xs:positiveInteger" default="5"/>
    2.15 -  <xs:attribute name="maxSize" type="xs:positiveInteger" default="INF"/>
    2.16 +  <xs:attribute name="maxSize" type="core:positiveOrInfiniteInteger" default="-1"/>
    2.17    <xs:attribute name="baseSize" type="xs:nonNegativeInteger" default="0"/>
    2.18  </xs:complexType>
    2.19  <xs:complexType name="statstype">
    2.20 @@ -62,8 +62,8 @@
    2.21    <xs:attribute name="id" type="xs:IDREF" />
    2.22    <xs:attribute name="required" type="xs:boolean" default="false"/>
    2.23    <xs:attribute name="exclusivityGroup" type="xs:string" default=""/>
    2.24 -  <xs:attribute name="minNum" type="xs:positiveInteger" default="INF"/>
    2.25 -  <xs:attribute name="maxNum" type="xs:positiveInteger" default="INF"/>
    2.26 +  <xs:attribute name="minNum" type="core:positiveOrInfiniteInteger" default="-1"/>
    2.27 +  <xs:attribute name="maxNum" type="core:positiveOrInfiniteInteger" default="-1"/>
    2.28    <xs:attribute name="minPercentage" type="core:percentage" default="100"/>
    2.29    <xs:attribute name="maxPercentage" type="core:percentage" default="100"/>
    2.30    <xs:attribute name="roundDirection" type="updowntype" default="up"/>
    2.31 @@ -126,7 +126,7 @@
    2.32    </xs:all>
    2.33    <xs:attribute name="id" type="xs:ID" use="required"/>
    2.34    <xs:attribute name="name" type="xs:string" use="required"/>
    2.35 -  <xs:attribute name="cost" type="core:nonNegativeDouble" use="required"/>
    2.36 +  <xs:attribute name="cost" type="core:nonNegativeNonInfiniteDouble" use="required"/>
    2.37    <xs:attribute name="armoutType" type="armourtype" default="none"/>
    2.38  </xs:complexType>
    2.39  <xs:simpleType name="armourtype">
     3.1 --- a/dtds/warfoundry-cats.xsd	Thu Mar 19 20:12:29 2009 +0000
     3.2 +++ b/dtds/warfoundry-cats.xsd	Sat Mar 21 17:04:33 2009 +0000
     3.3 @@ -8,7 +8,7 @@
     3.4          <xs:attribute name="id" type="xs:ID" />
     3.5          <xs:attribute name="name" type="xs:string" use="required"/>
     3.6          <xs:attribute name="minPoints" type="core:nonNegativeDouble" default="0"/>
     3.7 -        <xs:attribute name="maxPoints" type="core:infiniteOrNonNegativeDouble" default="INF"/>
     3.8 +        <xs:attribute name="maxPoints" type="core:nonNegativeOrInfiniteInteger" default="-1"/>
     3.9          <xs:attribute name="minPercentage" type="core:percentage" default="0"/>
    3.10          <xs:attribute name="maxPercentage" type="core:percentage" default="100"/>
    3.11        </xs:complexType>
     4.1 --- a/dtds/warfoundry-core.xsd	Thu Mar 19 20:12:29 2009 +0000
     4.2 +++ b/dtds/warfoundry-core.xsd	Sat Mar 21 17:04:33 2009 +0000
     4.3 @@ -1,17 +1,24 @@
     4.4  <?xml version="1.0"?>
     4.5  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ibboard.co.uk/warfoundry/core"
     4.6  xmlns="http://ibboard.co.uk/warfoundry/core" elementFormDefault="qualified">
     4.7 -<xs:simpleType name="infiniteOrNonNegativeDouble">
     4.8 +<xs:simpleType name="positiveOrInfiniteInteger">
     4.9 +  <xs:union memberTypes="xs:positiveInteger infinity"/>
    4.10 +</xs:simpleType>
    4.11 +<xs:simpleType name="nonNegativeOrInfiniteInteger">
    4.12 +  <xs:union memberTypes="xs:nonNegativeInteger infinity"/>
    4.13 +</xs:simpleType>
    4.14 +<xs:simpleType name="infinity">
    4.15 +  <xs:restriction base="xs:integer">
    4.16 +    <xs:minInclusive value="-1"/>
    4.17 +    <xs:maxInclusive value="-1"/>
    4.18 +  </xs:restriction>
    4.19 +</xs:simpleType>
    4.20 +<xs:simpleType name="nonNegativeDouble">
    4.21    <xs:restriction base="xs:double">
    4.22      <xs:minInclusive value="0"/>
    4.23    </xs:restriction>
    4.24  </xs:simpleType>
    4.25 -<xs:simpleType name="infiniteOrNonNegativeInteger">
    4.26 -  <xs:restriction base="xs:integer">
    4.27 -    <xs:minInclusive value="0"/>
    4.28 -  </xs:restriction>
    4.29 -</xs:simpleType>
    4.30 -<xs:simpleType name="nonNegativeDouble">
    4.31 +<xs:simpleType name="nonNegativeNonInfiniteDouble">
    4.32    <xs:restriction base="xs:double">
    4.33      <xs:minInclusive value="0"/>
    4.34      <xs:maxExclusive value="INF"/>