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