Small ResourceManager refactor, add ResourceSaver<T>.

This commit is contained in:
2024-01-21 20:24:53 +01:00
parent cfec5a59b1
commit 62e0e013f1
16 changed files with 215 additions and 54 deletions

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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();
}
}
}