//-----------------------------------------------------------------------------
// StoreCategory.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
namespace RolePlaying.Data
{
///
/// A category of gear for sale in a store.
///
public class StoreCategory
{
///
/// The display name of this store category.
///
private string name;
///
/// The display name of this store category.
///
public string Name
{
get { return name; }
set { name = value; }
}
///
/// The content names for the gear available in this category.
///
private List availableContentNames = new List();
///
/// The content names for the gear available in this category.
///
public List AvailableContentNames
{
get { return availableContentNames; }
set { availableContentNames = value; }
}
///
/// The gear available in this category.
///
private List availableGear = new List();
///
/// The gear available in this category.
///
[ContentSerializerIgnore]
public List AvailableGear
{
get { return availableGear; }
set { availableGear = value; }
}
///
/// Reads a StoreCategory object from the content pipeline.
///
public class StoreCategoryReader : ContentTypeReader
{
///
/// Reads a StoreCategory object from the content pipeline.
///
protected override StoreCategory Read(ContentReader input,
StoreCategory existingInstance)
{
StoreCategory storeCategory = existingInstance;
if (storeCategory == null)
{
storeCategory = new StoreCategory();
}
storeCategory.Name = input.ReadString();
storeCategory.AvailableContentNames.AddRange(
input.ReadObject>());
// populate the gear list based on the content names
foreach (string gearName in storeCategory.AvailableContentNames)
{
storeCategory.AvailableGear.Add(input.ContentManager.Load(Path.Combine("Gear", gearName)));
}
return storeCategory;
}
}
internal static StoreCategory Load(XElement storeCategoryElement, ContentManager contentManager)
{
var storeCategory = new StoreCategory
{
Name = storeCategoryElement.Element("Name").Value,
AvailableContentNames = storeCategoryElement.Element("AvailableContentNames")
.Elements("Item")
.Select(contentNameElement => contentNameElement.Value)
.ToList(),
};
foreach (string gearName in storeCategory.AvailableContentNames)
{
var gearAsset = XmlHelper.GetAssetElementFromXML(System.IO.Path.Combine("Gear", gearName));
var gear = new Item
{
AssetName = gearName,
Name = gearAsset.Element("Name").Value,
Description = gearAsset.Element("Description").Value,
GoldValue = int.Parse(gearAsset.Element("GoldValue").Value),
IsDroppable = bool.Parse(gearAsset.Element("IsDroppable").Value),
IsOffensive = bool.Parse(gearAsset.Element("IsOffensive").Value),
MinimumCharacterLevel = int.Parse(gearAsset.Element("MinimumCharacterLevel").Value),
IconTextureName = gearAsset.Element("IconTextureName").Value,
IconTexture = contentManager.Load(Path.Combine("Textures", "Gear", gearAsset.Element("IconTextureName").Value)),
TargetDuration = int.Parse(gearAsset.Element("TargetDuration").Value),
AdjacentTargets = int.Parse(gearAsset.Element("AdjacentTargets").Value),
UsingCueName = gearAsset.Element("UsingCueName").Value,
ImpactCueName = gearAsset.Element("ImpactCueName").Value,
BlockCueName = gearAsset.Element("BlockCueName").Value,
};
// Load other properties of Gear as needed
storeCategory.AvailableGear.Add(gear);
}
return storeCategory;
}
}
}