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, 28 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlFactory.cs	Thu Mar 19 20:12:29 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlFactory.cs	Sat Mar 21 17:04:33 2009 +0000
@@ -381,26 +381,14 @@
 				
 		private int GetIntValueFromAttribute(XmlElement elem, string attributeName)
 		{
-			string attribValue = elem.GetAttribute(attributeName);
-			int intValue = int.MaxValue;
-			
-			if ("INF".Equals(attribValue))
-			{
-				intValue = WarFoundryCore.INFINITY;
-			}
-			else
+			try
 			{
-				try
-				{
-					intValue = int.Parse(attribValue);
-				}
-				catch(FormatException)
-				{
-					throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid number", attributeName, elem.Name, elem.GetAttribute("id")));
-				}
+				return int.Parse(elem.GetAttribute(attributeName));
 			}
-			
-			return intValue;
+			catch(FormatException)
+			{
+				throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid number", attributeName, elem.Name, elem.GetAttribute("id")));
+			}
 		}
 						
 		private UnitType CreateUnitTypeFromElement(XmlElement elem, Race parentRace, GameSystem system)
--- a/dtds/race.xsd	Thu Mar 19 20:12:29 2009 +0000
+++ b/dtds/race.xsd	Sat Mar 21 17:04:33 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:nonNegativeDouble" default="0"/>
-  <xs:attribute name="points" type="core:nonNegativeDouble" use="required"/>
+  <xs:attribute name="unitPoints" type="core:nonNegativeNonInfiniteDouble" default="0"/>
+  <xs:attribute name="points" type="core:nonNegativeNonInfiniteDouble" use="required"/>
   <xs:attribute name="minNum" type="xs:nonNegativeInteger" default="0"/>
-  <xs:attribute name="maxNum" type="xs:positiveInteger" default="INF"/>
+  <xs:attribute name="maxNum" type="core:positiveOrInfiniteInteger" default="-1"/>
   <xs:attribute name="minSize" type="xs:positiveInteger" default="5"/>
-  <xs:attribute name="maxSize" type="xs:positiveInteger" default="INF"/>
+  <xs:attribute name="maxSize" type="core:positiveOrInfiniteInteger" default="-1"/>
   <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:positiveInteger" default="INF"/>
-  <xs:attribute name="maxNum" type="xs:positiveInteger" default="INF"/>
+  <xs:attribute name="minNum" type="core:positiveOrInfiniteInteger" default="-1"/>
+  <xs:attribute name="maxNum" type="core:positiveOrInfiniteInteger" default="-1"/>
   <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:nonNegativeDouble" use="required"/>
+  <xs:attribute name="cost" type="core:nonNegativeNonInfiniteDouble" use="required"/>
   <xs:attribute name="armoutType" type="armourtype" default="none"/>
 </xs:complexType>
 <xs:simpleType name="armourtype">
--- a/dtds/warfoundry-cats.xsd	Thu Mar 19 20:12:29 2009 +0000
+++ b/dtds/warfoundry-cats.xsd	Sat Mar 21 17:04:33 2009 +0000
@@ -8,7 +8,7 @@
         <xs:attribute name="id" type="xs:ID" />
         <xs:attribute name="name" type="xs:string" use="required"/>
         <xs:attribute name="minPoints" type="core:nonNegativeDouble" default="0"/>
-        <xs:attribute name="maxPoints" type="core:infiniteOrNonNegativeDouble" default="INF"/>
+        <xs:attribute name="maxPoints" type="core:nonNegativeOrInfiniteInteger" default="-1"/>
         <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	Thu Mar 19 20:12:29 2009 +0000
+++ b/dtds/warfoundry-core.xsd	Sat Mar 21 17:04:33 2009 +0000
@@ -1,17 +1,24 @@
 <?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="infiniteOrNonNegativeDouble">
+<xs:simpleType name="positiveOrInfiniteInteger">
+  <xs:union memberTypes="xs:positiveInteger infinity"/>
+</xs:simpleType>
+<xs:simpleType name="nonNegativeOrInfiniteInteger">
+  <xs:union memberTypes="xs:nonNegativeInteger infinity"/>
+</xs:simpleType>
+<xs:simpleType name="infinity">
+  <xs:restriction base="xs:integer">
+    <xs:minInclusive value="-1"/>
+    <xs:maxInclusive value="-1"/>
+  </xs:restriction>
+</xs:simpleType>
+<xs:simpleType name="nonNegativeDouble">
   <xs:restriction base="xs:double">
     <xs:minInclusive value="0"/>
   </xs:restriction>
 </xs:simpleType>
-<xs:simpleType name="infiniteOrNonNegativeInteger">
-  <xs:restriction base="xs:integer">
-    <xs:minInclusive value="0"/>
-  </xs:restriction>
-</xs:simpleType>
-<xs:simpleType name="nonNegativeDouble">
+<xs:simpleType name="nonNegativeNonInfiniteDouble">
   <xs:restriction base="xs:double">
     <xs:minInclusive value="0"/>
     <xs:maxExclusive value="INF"/>