MapWriter.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // MapWriter.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using Microsoft.Xna.Framework;
  13. using Microsoft.Xna.Framework.Graphics;
  14. using Microsoft.Xna.Framework.Content.Pipeline;
  15. using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
  16. using Microsoft.Xna.Framework.Content.Pipeline.Processors;
  17. using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
  18. using RolePlaying.Data;
  19. #endregion
  20. namespace RolePlaying.Processors
  21. {
  22. /// <summary>
  23. /// This class will be instantiated by the XNA Framework Content Pipeline
  24. /// to write the specified data type into binary .xnb format.
  25. ///
  26. /// This should be part of a Content Pipeline Extension Library project.
  27. /// </summary>
  28. [ContentTypeWriter]
  29. public class MapWriter : RolePlayingGameWriter<Map>
  30. {
  31. protected override void Write(ContentWriter output, Map value)
  32. {
  33. // validate the map first
  34. if ((value.MapDimensions.X <= 0) ||
  35. (value.MapDimensions.Y <= 0))
  36. {
  37. throw new InvalidContentException("Invalid map dimensions.");
  38. }
  39. int totalTiles = value.MapDimensions.X * value.MapDimensions.Y;
  40. if (value.BaseLayer.Length != totalTiles)
  41. {
  42. throw new InvalidContentException("Base layer was " +
  43. value.BaseLayer.Length.ToString() +
  44. " tiles, but the dimensions specify " +
  45. totalTiles.ToString() + ".");
  46. }
  47. if (value.FringeLayer.Length != totalTiles)
  48. {
  49. throw new InvalidContentException("Fringe layer was " +
  50. value.FringeLayer.Length.ToString() +
  51. " tiles, but the dimensions specify " +
  52. totalTiles.ToString() + ".");
  53. }
  54. if (value.ObjectLayer.Length != totalTiles)
  55. {
  56. throw new InvalidContentException("Object layer was " +
  57. value.ObjectLayer.Length.ToString() +
  58. " tiles, but the dimensions specify " +
  59. totalTiles.ToString() + ".");
  60. }
  61. if (value.CollisionLayer.Length != totalTiles)
  62. {
  63. throw new InvalidContentException("Collision layer was " +
  64. value.CollisionLayer.Length.ToString() +
  65. " tiles, but the dimensions specify " +
  66. totalTiles.ToString() + ".");
  67. }
  68. output.Write(value.Name);
  69. output.WriteObject(value.MapDimensions);
  70. output.WriteObject(value.TileSize);
  71. output.WriteObject(value.SpawnMapPosition);
  72. output.Write(value.TextureName);
  73. output.Write(value.CombatTextureName);
  74. output.Write(value.MusicCueName);
  75. output.Write(value.CombatMusicCueName);
  76. output.WriteObject(value.BaseLayer);
  77. output.WriteObject(value.FringeLayer);
  78. output.WriteObject(value.ObjectLayer);
  79. output.WriteObject(value.CollisionLayer);
  80. output.WriteObject(value.Portals);
  81. output.WriteObject(value.PortalEntries);
  82. output.WriteObject(value.ChestEntries);
  83. output.WriteObject(value.FixedCombatEntries);
  84. output.WriteObject(value.RandomCombat);
  85. output.WriteObject(value.QuestNpcEntries);
  86. output.WriteObject(value.PlayerNpcEntries);
  87. output.WriteObject(value.InnEntries);
  88. output.WriteObject(value.StoreEntries);
  89. }
  90. }
  91. }