using System;
using System.IO;
using Microsoft.Xna.Framework.Content;
namespace MLEM.Data.Content {
///
/// Represents a way for any kind of raw content file to be read using a
///
public abstract class RawContentReader {
///
/// Returns if the given type can be loaded by this content reader
///
/// The type of asset
/// If the type can be loaded by this content reader
public abstract bool CanRead(Type t);
///
/// Reads the content file from disk and returns it.
///
/// The that is loading the asset
/// The full path to the asset, starting from the
/// A stream that leads to this asset
/// The type of asset to load
/// If this asset is being reloaded, this value contains the previous version of the asset.
/// The loaded asset
public abstract object Read(RawContentManager manager, string assetPath, Stream stream, Type t, object existing);
///
/// Represents the list of file extensions that this reader can read from.
///
/// The list of valid extensions
public abstract string[] GetFileExtensions();
}
///
public abstract class RawContentReader : RawContentReader {
///
public override bool CanRead(Type t) {
return typeof(T).IsAssignableFrom(t);
}
///
public override object Read(RawContentManager manager, string assetPath, Stream stream, Type t, object existing) {
return this.Read(manager, assetPath, stream, (T) existing);
}
///
/// Reads the content file that is represented by our generic type from disk.
///
/// The that is loading the asset
/// The full path to the asset, starting from the
/// A stream that leads to this asset
/// If this asset is being reloaded, this value contains the previous version of the asset.
/// The loaded asset
protected abstract T Read(RawContentManager manager, string assetPath, Stream stream, T existing);
}
}