X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FMap.cs;h=ddfa9d5457b309f80a9fd8a48bad537fcee7ff06;hb=c813c24c363d1a397b18f1d99a877071f20f2d2f;hp=c277a7aa4590633359fd50a7d7ef9349f0ec0eff;hpb=722dcd763d115992b2a56d4001db80d11e583064;p=chaz%2Fcarfire diff --git a/CarFire/CarFire/CarFire/Map.cs b/CarFire/CarFire/CarFire/Map.cs index c277a7a..ddfa9d5 100644 --- a/CarFire/CarFire/CarFire/Map.cs +++ b/CarFire/CarFire/CarFire/Map.cs @@ -22,9 +22,33 @@ namespace CarFire // DEBUG: Tilesets not implemented at all. public static Texture2D DefaultTile; + #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 RuntimeException : System.ApplicationException + { + public RuntimeException() { } + + public RuntimeException(string message) : + base(message) { } + + public RuntimeException(string message, System.Exception inner) : + base(message, inner) { } + + protected RuntimeException(SerializationInfo info, StreamingContext context) : + base(info, context) { } + } + + #endregion + + #region Public Constants - public const float PixelsToUnitSquares = 8.0f; + public const float PixelsToUnitSquares = 60.0f; #endregion @@ -34,7 +58,7 @@ namespace CarFire /// /// The type of a map helps determine how the map is intended to be used. /// - public enum Type + public enum Mode { None, Campaign, @@ -47,7 +71,7 @@ namespace CarFire public class Metadata { public string Name; - public Type Type; + public Mode Type; public string Author; public HashSet NumPlayers = new HashSet(); public string Tileset; @@ -78,7 +102,7 @@ namespace CarFire /// /// Get the type of the map. /// - //public Type Type { get { return mData.mMetadata.Type; } } + public Mode Type { get { return mData.Metadata.Type; } } /// /// Get the author of the map. @@ -127,7 +151,9 @@ namespace CarFire /// /// Construct a map with the provided map data. /// - /// Map data. + /// The metadata. + /// The grid. + /// The entities. public Map(Metadata metadata, char[,] grid, List entities) { mData = new Modal(metadata, grid, entities); @@ -288,9 +314,19 @@ namespace CarFire args[1] = raw.Position; args[2] = raw.Attributes; - object entity = Activator.CreateInstance(System.Type.GetType("CarFire." + typename), args); - if (entity != null) list.Add(entity); - else Console.WriteLine("Entity of type " + typename + " not loaded because an entity class can't be found."); + try + { + + object entity = Activator.CreateInstance(System.Type.GetType("CarFire." + typename), args); + if (entity != null) list.Add(entity); + else throw new RuntimeException(); + } +#pragma warning disable 0168 + catch (System.Exception ex) +#pragma warning restore 0168 + { + throw new RuntimeException("Entity of type " + typename + " not loaded because an entity class can't be found."); + } } else { @@ -318,7 +354,7 @@ namespace CarFire T entity = (T)Activator.CreateInstance(type, args); if (entity != null) list.Add(entity); - else Console.WriteLine("Entity of type " + typename + " not loaded because an entity class can't be found."); + else throw new RuntimeException("Entity of type " + typename + " not loaded because an entity class can't be found."); } }