/// </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
\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
}\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
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
{\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
\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
\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
{\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
}\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
}\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
{\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
{\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
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
{\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
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
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