#region File Description
//-----------------------------------------------------------------------------
// PlayerData.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.Graphics;
using Microsoft.Xna.Framework.Net;
#endregion
namespace NetRumble
{
///
/// Data for each player in a network session.
///
public class PlayerData
{
#region Gameplay Data
///
/// The color of the overlay portion of the ship.
///
private byte shipColor = 0;
public byte ShipColor
{
get { return shipColor; }
set
{
if ((value < 0) || (value >= Ship.ShipColors.Length))
{
throw new ArgumentOutOfRangeException("value");
}
shipColor = value;
// apply the change to the ship immediately
if (ship != null)
{
ship.Color = Ship.ShipColors[shipColor];
}
}
}
///
/// The ship model to use.
///
private byte shipVariation = 0;
public byte ShipVariation
{
get { return shipVariation; }
set
{
if ((value < 0) || (value >= Ship.Variations))
{
throw new ArgumentOutOfRangeException("value");
}
shipVariation = value;
// apply the change to the ship immediately
if (ship != null)
{
ship.Variation = shipVariation;
}
}
}
///
/// The ship used by this player.
///
private Ship ship = null;
public Ship Ship
{
get { return ship; }
set
{
ship = value;
// apply the other values to the ship immediately
if (ship != null)
{
ship.Variation = shipVariation;
ship.Color = Ship.ShipColors[shipColor];
}
}
}
#endregion
#region Initialization Methods
///
/// Constructs a PlayerData object.
///
public PlayerData()
{
Ship = new Ship();
}
#endregion
#region Networking Methods
///
/// Deserialize from the packet into the current object.
///
/// The packet reader that has the data.
public void Deserialize(PacketReader packetReader)
{
// safety-check the parameter, as it must be valid.
if (packetReader == null)
{
throw new ArgumentNullException("packetReader");
}
ShipColor = packetReader.ReadByte();
ShipVariation = packetReader.ReadByte();
}
///
/// Serialize the current object to a packet.
///
/// The packet writer that receives the data.
public void Serialize(PacketWriter packetWriter)
{
// safety-check the parameter, as it must be valid.
if (packetWriter == null)
{
throw new ArgumentNullException("packetWriter");
}
packetWriter.Write(ShipColor);
packetWriter.Write(ShipVariation);
}
#endregion
}
}