]> Dogcows Code - chaz/carfire/blobdiff - CarFire/CarFire/CarFire/MapReader.cs
git-svn-id: https://bd85.net/svn/cs3505_group@168 92bb83a3-7c8f-8a45-bc97-515c4e399668
[chaz/carfire] / CarFire / CarFire / CarFire / MapReader.cs
index cfb1f945219cb1bf73e315957bee1cc0fd7285f4..347f6bd87309164dfb440d3500c07f4cea824121 100644 (file)
@@ -15,30 +15,6 @@ namespace CarFire
     /// </summary>\r
     public class MapReader : ContentTypeReader<Map>\r
     {\r
-        #region Public Exceptions\r
-\r
-        /// <summary>\r
-        /// This exception is thrown during the loading of a map if any\r
-        /// part of the map file is inconsistent with the expected format\r
-        /// and order.\r
-        /// </summary>\r
-        public class ParserException : System.ApplicationException\r
-        {\r
-            public ParserException() {}\r
-\r
-            public ParserException(string message) :\r
-                base(message) {}\r
-\r
-            public ParserException(string message, System.Exception inner) :\r
-                base(message, inner) {}\r
-\r
-            protected ParserException(SerializationInfo info, StreamingContext context) :\r
-                base(info, context) {}\r
-        }\r
-\r
-        #endregion\r
-\r
-\r
         #region Protected Methods\r
 \r
         protected override Map Read(ContentReader input, Map existingInstance)\r
@@ -96,7 +72,7 @@ namespace CarFire
 \r
             public Map GetMap()\r
             {\r
-                return new Map(mMetadata, mGrid, mEntities);\r
+                return new Map(mMetadata, mGrid, mDefaultTile, mEntities, mPlayerPositions);\r
             }\r
 \r
 \r
@@ -129,12 +105,12 @@ namespace CarFire
                             }\r
                             else\r
                             {\r
-                                throw new ParserException("Unexpected section on line " + mInput.LineNumber + ": " + section);\r
+                                throw new Exception("Unexpected section on line " + mInput.LineNumber + ": " + section);\r
                             }\r
                         }\r
                         else\r
                         {\r
-                            throw new ParserException("Unexpected text on line " + mInput.LineNumber + ": " + line);\r
+                            throw new Exception("Unexpected text on line " + mInput.LineNumber + ": " + line);\r
                         }\r
                     }\r
                 }\r
@@ -161,7 +137,7 @@ namespace CarFire
                         catch (System.MissingMethodException ex)\r
 #pragma warning restore 0168\r
                         {\r
-                            throw new ParserException("Unexpected key on line " + mInput.LineNumber + ": " + pair[0]);\r
+                            throw new Exception("Unexpected key on line " + mInput.LineNumber + ": " + pair[0]);\r
                         }\r
                     }\r
                     else\r
@@ -177,7 +153,7 @@ namespace CarFire
             {\r
                 if (mMetadata == null || mMetadata.GridWidth == 0 || mMetadata.GridHeight == 0)\r
                 {\r
-                    throw new ParserException("Unexpected section on line " + mInput.LineNumber +\r
+                    throw new Exception("Unexpected section on line " + mInput.LineNumber +\r
                         ": You must define the map dimensions before this section.");\r
                 }\r
 \r
@@ -190,7 +166,7 @@ namespace CarFire
 \r
                     if (line.Length < mMetadata.GridWidth)\r
                     {\r
-                        throw new ParserException("Unexpected EOL on line " + mInput.LineNumber +\r
+                        throw new Exception("Unexpected EOL on line " + mInput.LineNumber +\r
                             ": The number of characters should match the width dimension (" + mMetadata.GridWidth + ").");\r
                     }\r
 \r
@@ -202,7 +178,7 @@ namespace CarFire
 \r
                 if (y < mMetadata.GridHeight)\r
                 {\r
-                    throw new ParserException("Unexpected EOF on line " + mInput.LineNumber +\r
+                    throw new Exception("Unexpected EOF on line " + mInput.LineNumber +\r
                         ": The number of lines in this section should match the height dimension (" + mMetadata.GridHeight + ").");\r
                 }\r
 \r
@@ -237,7 +213,7 @@ namespace CarFire
             {\r
                 if (mMetadata == null || mGrid == null)\r
                 {\r
-                    throw new ParserException("Missing a required section.  Make sure the metadata and grid are there.");\r
+                    throw new Exception("Missing a required section.  Make sure the metadata and grid are there.");\r
                 }\r
 \r
                 mEntities = new List<Map.RawEntity>();\r
@@ -263,7 +239,7 @@ namespace CarFire
                             }\r
                             else\r
                             {\r
-                                throw new ParserException("Unexpected value of key `create' defined for entity " + identifier + ".");\r
+                                throw new Exception("Unexpected value of key `create' defined for entity " + identifier + ".");\r
                             }\r
                         }\r
                         pairs.Remove("create");\r
@@ -289,7 +265,7 @@ namespace CarFire
                             }\r
                             else\r
                             {\r
-                                throw new ParserException("Unexpected entity (" + identifier +\r
+                                throw new Exception("Unexpected entity (" + identifier +\r
                                     ") placed on the grid at [" + x + "," + y + "] but not defined.");\r
                             }\r
                             mGrid[x, y] = mDefaultTile;\r
@@ -311,8 +287,8 @@ namespace CarFire
                 {\r
                     if (mPlayerPositions[i] == default(Point))\r
                     {\r
-                        throw new ParserException("Not enough player positions were defined on the grid; " +\r
-                            "are missing a spot for player " + i + ".");\r
+                        throw new Exception("Not enough player positions were defined on the grid; " +\r
+                            "you are missing a spot for player " + i + ".");\r
                     }\r
                 }\r
             }\r
@@ -335,21 +311,28 @@ namespace CarFire
             {\r
                 string value = Parse.String(atom);\r
                 if (value != null) mMetadata.Author = value;\r
-                else throw new ParserException("Unexpected value on line " + mInput.LineNumber + ": " + atom);\r
+                else throw new Exception("Unexpected value on line " + mInput.LineNumber + ": " + atom);\r
             }\r
 \r
             public void set_levelname(string atom)\r
             {\r
                 string value = Parse.String(atom);\r
                 if (value != null) mMetadata.Name = value;\r
-                else throw new ParserException("Unexpected value on line " + mInput.LineNumber + ": " + atom);\r
+                else throw new Exception("Unexpected value on line " + mInput.LineNumber + ": " + atom);\r
+            }\r
+\r
+            public void set_next(string atom)\r
+            {\r
+                string value = Parse.String(atom);\r
+                if (value != null) mMetadata.Next = value;\r
+                else throw new Exception("Unexpected value on line " + mInput.LineNumber + ": " + atom);\r
             }\r
 \r
             public void set_type(string atom)\r
             {\r
-                Map.Type value = Parse.Constant<Map.Type>(atom);\r
-                if (value != default(Map.Type)) mMetadata.Type = value;\r
-                else throw new ParserException("Unexpected type on line " + mInput.LineNumber + ": " + atom);\r
+                Map.Mode? value = Parse.Constant<Map.Mode>(atom);\r
+                if (value != null) mMetadata.Type = value.Value;\r
+                else throw new Exception("Unexpected type on line " + mInput.LineNumber + ": " + atom);\r
             }\r
 \r
             public void set_dimensions(string atom)\r
@@ -361,12 +344,12 @@ namespace CarFire
                     mMetadata.GridHeight = dimensions.Value.Y;\r
                     if (mMetadata.GridWidth <= 0 || mMetadata.GridHeight <= 0)\r
                     {\r
-                        throw new ParserException("Invalid dimensions on line " + mInput.LineNumber + ": " + atom);\r
+                        throw new Exception("Invalid dimensions on line " + mInput.LineNumber + ": " + atom);\r
                     }\r
                 }\r
                 else\r
                 {\r
-                    throw new ParserException("Unexpected value on line " + mInput.LineNumber + ": " + atom);\r
+                    throw new Exception("Unexpected value on line " + mInput.LineNumber + ": " + atom);\r
                 }\r
             }\r
 \r
@@ -374,14 +357,14 @@ namespace CarFire
             {\r
                 string value = Parse.String(atom);\r
                 if (value != null) mMetadata.Tileset = value;\r
-                else throw new ParserException("Unexpected tileset on line " + mInput.LineNumber + ": " + atom);\r
+                else throw new Exception("Unexpected tileset on line " + mInput.LineNumber + ": " + atom);\r
             }\r
 \r
             public void set_defaulttile(string atom)\r
             {\r
                 char? value = Parse.Char(atom);\r
                 if (value != null) mDefaultTile = value.Value;\r
-                else throw new ParserException("Unexpected tile value on line " + mInput.LineNumber + ": " + atom);\r
+                else throw new Exception("Unexpected tile value on line " + mInput.LineNumber + ": " + atom);\r
             }\r
 \r
             public void set_numplayers(string atom)\r
@@ -407,16 +390,16 @@ namespace CarFire
                             continue;\r
                         }\r
 \r
-                        throw new ParserException("Unexpected atom on line " + mInput.LineNumber + ": " + item);\r
+                        throw new Exception("Unexpected atom on line " + mInput.LineNumber + ": " + item);\r
                     }\r
                     if (mMetadata.NumPlayers.Count == 0)\r
                     {\r
-                        throw new ParserException("No numbers given on line " + mInput.LineNumber + ": " + atom);\r
+                        throw new Exception("No numbers given on line " + mInput.LineNumber + ": " + atom);\r
                     }\r
                 }\r
                 else\r
                 {\r
-                    throw new ParserException("Unexpected value on line " + mInput.LineNumber + ": " + atom);\r
+                    throw new Exception("Unexpected value on line " + mInput.LineNumber + ": " + atom);\r
                 }\r
             }\r
 \r
@@ -425,10 +408,9 @@ namespace CarFire
             char[,] mGrid;\r
             List<Map.RawEntity> mEntities;\r
             Point[] mPlayerPositions;\r
-\r
-            Dictionary<char, Dictionary<string, string>> mEntitySections = new Dictionary<char, Dictionary<string, string>>();\r
             char mDefaultTile = ' ';\r
 \r
+            Dictionary<char, Dictionary<string, string>> mEntitySections = new Dictionary<char, Dictionary<string, string>>();\r
             LineReader mInput;\r
         }\r
 \r
This page took 0.026053 seconds and 4 git commands to generate.