Small ResourceManager refactor, add ResourceSaver<T>.
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
namespace DaggerFramework.Resources;
|
||||
|
||||
public class FontLoader : IResourceLoader
|
||||
public class FontLoader : IResourceLoader<Font>
|
||||
{
|
||||
public IEnumerable<string> SupportedExtensions => new string[]
|
||||
{
|
||||
"ttf"
|
||||
};
|
||||
|
||||
public Type ResourceType => typeof(Font);
|
||||
|
||||
public Resource Load(string path)
|
||||
public Font Load(string path)
|
||||
{
|
||||
byte[] fileBuffer = File.ReadAllBytes(path);
|
||||
var result = new Font(path, fileBuffer);
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
namespace DaggerFramework.Resources
|
||||
{
|
||||
public interface IResourceLoader
|
||||
public interface IResourceLoader<T> where T : Resource
|
||||
{
|
||||
public IEnumerable<string> SupportedExtensions { get; }
|
||||
public Type ResourceType { get; }
|
||||
public Resource Load(string path);
|
||||
public T Load(string path);
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,14 @@ using StbVorbisSharp;
|
||||
|
||||
namespace DaggerFramework.Resources
|
||||
{
|
||||
public class SoundLoader : IResourceLoader
|
||||
public class SoundLoader : IResourceLoader<Sound>
|
||||
{
|
||||
public IEnumerable<string> SupportedExtensions => new string[]
|
||||
{
|
||||
"ogg"
|
||||
};
|
||||
|
||||
public Type ResourceType => typeof(Sound);
|
||||
|
||||
public Resource Load(string path)
|
||||
public Sound Load(string path)
|
||||
{
|
||||
Vorbis vorbis;
|
||||
Sound result;
|
||||
|
||||
@@ -3,7 +3,7 @@ using StbImageSharp;
|
||||
|
||||
namespace DaggerFramework
|
||||
{
|
||||
public class Texture2dLoader : IResourceLoader
|
||||
public class Texture2dLoader : IResourceLoader<Texture2d>
|
||||
{
|
||||
public IEnumerable<string> SupportedExtensions => new string[]
|
||||
{
|
||||
@@ -12,9 +12,7 @@ namespace DaggerFramework
|
||||
".jpeg"
|
||||
};
|
||||
|
||||
public Type ResourceType => typeof(Texture2d);
|
||||
|
||||
public Resource Load(string path)
|
||||
public Texture2d Load(string path)
|
||||
{
|
||||
ImageResult image;
|
||||
using (var stream = File.OpenRead(path))
|
||||
@@ -28,10 +26,5 @@ namespace DaggerFramework
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Resource IResourceLoader.Load(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user