Refactor ResourceLoader, use only Texture2d in Renderer.
This commit is contained in:
9
Source/Resources/Loaders/FontLoader.cs
Normal file
9
Source/Resources/Loaders/FontLoader.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace DaggerFramework;
|
||||
|
||||
public class FontLoader : ResourceLoader<Font>
|
||||
{
|
||||
public override Font Load(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
8
Source/Resources/Loaders/ResourceLoader.cs
Executable file
8
Source/Resources/Loaders/ResourceLoader.cs
Executable file
@@ -0,0 +1,8 @@
|
||||
namespace DaggerFramework
|
||||
{
|
||||
public abstract class ResourceLoader<T> : IDisposable where T : Resource
|
||||
{
|
||||
public void Dispose() { }
|
||||
public abstract T Load(string path);
|
||||
}
|
||||
}
|
||||
15
Source/Resources/Loaders/SoundLoader.cs
Normal file
15
Source/Resources/Loaders/SoundLoader.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace DaggerFramework
|
||||
{
|
||||
public class SoundLoader : ResourceLoader<Sound>
|
||||
{
|
||||
public override Sound Load(string path)
|
||||
{
|
||||
// TODO
|
||||
// var data = File.ReadAllBytes(path);
|
||||
var sound = new Sound(path, new byte[] { });
|
||||
sound.Path = path;
|
||||
|
||||
return sound;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Source/Resources/Loaders/Texture2dLoader.cs
Executable file
22
Source/Resources/Loaders/Texture2dLoader.cs
Executable file
@@ -0,0 +1,22 @@
|
||||
using StbImageSharp;
|
||||
|
||||
namespace DaggerFramework
|
||||
{
|
||||
public class Texture2dLoader : ResourceLoader<Texture2d>
|
||||
{
|
||||
public override Texture2d Load(string path)
|
||||
{
|
||||
ImageResult image;
|
||||
using (var stream = File.OpenRead(path))
|
||||
{
|
||||
image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
|
||||
}
|
||||
|
||||
Texture2d result = new Texture2d(path, image.Data);
|
||||
result.Width = image.Width;
|
||||
result.Height = image.Height;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user