MapEntry.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // MapEntry.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 Microsoft.Xna.Framework;
  12. using Microsoft.Xna.Framework.Content;
  13. #endregion
  14. namespace RolePlayingGameData
  15. {
  16. /// <summary>
  17. /// The description of where an instance of a world object is in the world.
  18. /// </summary>
  19. public class MapEntry<T> : ContentEntry<T> where T : ContentObject
  20. {
  21. #region Map Data
  22. /// <summary>
  23. /// The position of this object on the map.
  24. /// </summary>
  25. private Point mapPosition;
  26. /// <summary>
  27. /// The position of this object on the map.
  28. /// </summary>
  29. public Point MapPosition
  30. {
  31. get { return mapPosition; }
  32. set { mapPosition = value; }
  33. }
  34. /// <summary>
  35. /// The orientation of this object on the map.
  36. /// </summary>
  37. private Direction direction;
  38. /// <summary>
  39. /// The orientation of this object on the map.
  40. /// </summary>
  41. [ContentSerializer(Optional = true)]
  42. public Direction Direction
  43. {
  44. get { return direction; }
  45. set { direction = value; }
  46. }
  47. #endregion
  48. #region Object Implementation
  49. /// <summary>
  50. /// Tests for equality between reference objects.
  51. /// </summary>
  52. /// <remarks>
  53. /// Implemented so that player-removed map entries from save games can be
  54. /// compared to the data-driven map entries.
  55. /// </remarks>
  56. /// <returns>True if "equal".</returns>
  57. public override bool Equals(object obj)
  58. {
  59. MapEntry<T> mapEntry = obj as MapEntry<T>;
  60. return ((mapEntry != null) &&
  61. (mapEntry.Content == Content) &&
  62. (mapEntry.mapPosition == mapPosition) &&
  63. (mapEntry.Direction == Direction));
  64. }
  65. /// <summary>
  66. /// Calculates the hash code for comparisons with this reference type.
  67. /// </summary>
  68. /// <remarks>Recommended specified overload when Equals is overridden.</remarks>
  69. public override int GetHashCode()
  70. {
  71. return base.GetHashCode();
  72. }
  73. #endregion
  74. #region Graphics Data
  75. /// <summary>
  76. /// The animating sprite for the map view.
  77. /// </summary>
  78. /// <remarks>
  79. /// Only used when there might be several of the same WorldObject
  80. /// in the scene at once.
  81. /// </remarks>
  82. private AnimatingSprite mapSprite;
  83. /// <summary>
  84. /// The animating sprite for the map view.
  85. /// </summary>
  86. /// <remarks>
  87. /// Only used when there might be several of the same WorldObject
  88. /// in the scene at once.
  89. /// </remarks>
  90. [ContentSerializer(Optional = true)]
  91. public AnimatingSprite MapSprite
  92. {
  93. get { return mapSprite; }
  94. set { mapSprite = value; }
  95. }
  96. #endregion
  97. #region Content Type Reader
  98. /// <summary>
  99. /// Read a MapEntry object from the content pipeline.
  100. /// </summary>
  101. public class MapEntryReader : ContentTypeReader<MapEntry<T>>
  102. {
  103. /// <summary>
  104. /// Read a MapEntry object from the content pipeline.
  105. /// </summary>
  106. protected override MapEntry<T> Read(ContentReader input,
  107. MapEntry<T> existingInstance)
  108. {
  109. MapEntry<T> desc = existingInstance;
  110. if (desc == null)
  111. {
  112. desc = new MapEntry<T>();
  113. }
  114. input.ReadRawObject<ContentEntry<T>>(desc as ContentEntry<T>);
  115. desc.MapPosition = input.ReadObject<Point>();
  116. desc.Direction = (Direction)input.ReadInt32();
  117. return desc;
  118. }
  119. }
  120. #endregion
  121. }
  122. }