#region File Description
//-----------------------------------------------------------------------------
// MapEntry.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
#endregion
namespace RolePlayingGameData
{
///
/// The description of where an instance of a world object is in the world.
///
public class MapEntry : ContentEntry where T : ContentObject
{
#region Map Data
///
/// The position of this object on the map.
///
private Point mapPosition;
///
/// The position of this object on the map.
///
public Point MapPosition
{
get { return mapPosition; }
set { mapPosition = value; }
}
///
/// The orientation of this object on the map.
///
private Direction direction;
///
/// The orientation of this object on the map.
///
[ContentSerializer(Optional = true)]
public Direction Direction
{
get { return direction; }
set { direction = value; }
}
#endregion
#region Object Implementation
///
/// Tests for equality between reference objects.
///
///
/// Implemented so that player-removed map entries from save games can be
/// compared to the data-driven map entries.
///
/// True if "equal".
public override bool Equals(object obj)
{
MapEntry mapEntry = obj as MapEntry;
return ((mapEntry != null) &&
(mapEntry.Content == Content) &&
(mapEntry.mapPosition == mapPosition) &&
(mapEntry.Direction == Direction));
}
///
/// Calculates the hash code for comparisons with this reference type.
///
/// Recommended specified overload when Equals is overridden.
public override int GetHashCode()
{
return base.GetHashCode();
}
#endregion
#region Graphics Data
///
/// The animating sprite for the map view.
///
///
/// Only used when there might be several of the same WorldObject
/// in the scene at once.
///
private AnimatingSprite mapSprite;
///
/// The animating sprite for the map view.
///
///
/// Only used when there might be several of the same WorldObject
/// in the scene at once.
///
[ContentSerializer(Optional = true)]
public AnimatingSprite MapSprite
{
get { return mapSprite; }
set { mapSprite = value; }
}
#endregion
#region Content Type Reader
///
/// Read a MapEntry object from the content pipeline.
///
public class MapEntryReader : ContentTypeReader>
{
///
/// Read a MapEntry object from the content pipeline.
///
protected override MapEntry Read(ContentReader input,
MapEntry existingInstance)
{
MapEntry desc = existingInstance;
if (desc == null)
{
desc = new MapEntry();
}
input.ReadRawObject>(desc as ContentEntry);
desc.MapPosition = input.ReadObject();
desc.Direction = (Direction)input.ReadInt32();
return desc;
}
}
#endregion
}
}