1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-26 18:19:24 +01:00
MLEM/MLEM.Data/Content/RawContentReader.cs

61 lines
2.8 KiB
C#
Raw Normal View History

2020-04-22 00:30:55 +02:00
using System;
using System.IO;
using Microsoft.Xna.Framework.Content;
2020-04-22 00:30:55 +02:00
namespace MLEM.Data.Content {
2020-05-20 23:59:40 +02:00
/// <summary>
/// Represents a way for any kind of raw content file to be read using a <see cref="RawContentManager"/>
/// </summary>
2020-04-22 00:30:55 +02:00
public abstract class RawContentReader {
2020-05-20 23:59:40 +02:00
/// <summary>
/// Returns if the given type can be loaded by this content reader
/// </summary>
/// <param name="t">The type of asset</param>
/// <returns>If the type can be loaded by this content reader</returns>
2020-04-22 00:30:55 +02:00
public abstract bool CanRead(Type t);
2020-05-20 23:59:40 +02:00
/// <summary>
/// Reads the content file from disk and returns it.
/// </summary>
/// <param name="manager">The <see cref="RawContentManager"/> that is loading the asset</param>
/// <param name="assetPath">The full path to the asset, starting from the <see cref="ContentManager.RootDirectory"/></param>
2020-05-20 23:59:40 +02:00
/// <param name="stream">A stream that leads to this asset</param>
/// <param name="t">The type of asset to load</param>
/// <param name="existing">If this asset is being reloaded, this value contains the previous version of the asset.</param>
/// <returns>The loaded asset</returns>
2020-04-22 00:47:09 +02:00
public abstract object Read(RawContentManager manager, string assetPath, Stream stream, Type t, object existing);
2020-04-22 00:30:55 +02:00
2020-05-20 23:59:40 +02:00
/// <summary>
/// Represents the list of file extensions that this reader can read from.
/// </summary>
/// <returns>The list of valid extensions</returns>
2020-04-22 00:30:55 +02:00
public abstract string[] GetFileExtensions();
}
2020-05-20 23:59:40 +02:00
/// <inheritdoc/>
2020-04-22 00:30:55 +02:00
public abstract class RawContentReader<T> : RawContentReader {
2020-05-20 23:59:40 +02:00
/// <inheritdoc/>
2020-04-22 00:30:55 +02:00
public override bool CanRead(Type t) {
return typeof(T).IsAssignableFrom(t);
}
2020-05-20 23:59:40 +02:00
/// <inheritdoc/>
2020-04-22 00:47:09 +02:00
public override object Read(RawContentManager manager, string assetPath, Stream stream, Type t, object existing) {
2020-04-22 00:30:55 +02:00
return this.Read(manager, assetPath, stream, (T) existing);
}
2020-05-20 23:59:40 +02:00
/// <summary>
/// Reads the content file that is represented by our generic type from disk.
/// </summary>
/// <param name="manager">The <see cref="RawContentManager"/> that is loading the asset</param>
/// <param name="assetPath">The full path to the asset, starting from the <see cref="ContentManager.RootDirectory"/></param>
2020-05-20 23:59:40 +02:00
/// <param name="stream">A stream that leads to this asset</param>
/// <param name="existing">If this asset is being reloaded, this value contains the previous version of the asset.</param>
/// <returns>The loaded asset</returns>
2020-04-22 00:30:55 +02:00
protected abstract T Read(RawContentManager manager, string assetPath, Stream stream, T existing);
}
}