MapEntry.cs 3.9 KB

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