Change folder structure, add solution to the root.
This commit is contained in:
9
DaggerFramework/Source/Resources/Font.cs
Normal file
9
DaggerFramework/Source/Resources/Font.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace DaggerFramework;
|
||||
|
||||
public class Font : Resource
|
||||
{
|
||||
public int Size = 16;
|
||||
public Font(string path, byte[] buffer) : base(path, buffer)
|
||||
{
|
||||
}
|
||||
}
|
||||
9
DaggerFramework/Source/Resources/Loaders/FontLoader.cs
Normal file
9
DaggerFramework/Source/Resources/Loaders/FontLoader.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace DaggerFramework;
|
||||
|
||||
public class FontLoader : ResourceLoader<Font>
|
||||
{
|
||||
public override Font Load(string path)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
8
DaggerFramework/Source/Resources/Loaders/ResourceLoader.cs
Executable file
8
DaggerFramework/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);
|
||||
}
|
||||
}
|
||||
47
DaggerFramework/Source/Resources/Loaders/SoundLoader.cs
Normal file
47
DaggerFramework/Source/Resources/Loaders/SoundLoader.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using StbVorbisSharp;
|
||||
|
||||
namespace DaggerFramework
|
||||
{
|
||||
public class SoundLoader : ResourceLoader<Sound>
|
||||
{
|
||||
public override Sound Load(string path)
|
||||
{
|
||||
Vorbis vorbis;
|
||||
Sound result;
|
||||
|
||||
var fileBuffer = File.ReadAllBytes(path);
|
||||
vorbis = Vorbis.FromMemory(fileBuffer);
|
||||
|
||||
vorbis.SubmitBuffer();
|
||||
|
||||
if (vorbis.Decoded == 0)
|
||||
{
|
||||
vorbis.Restart();
|
||||
vorbis.SubmitBuffer();
|
||||
}
|
||||
|
||||
var audioShort = vorbis.SongBuffer;
|
||||
int length = vorbis.Decoded * vorbis.Channels;
|
||||
byte[] audioData = new byte[length * 2];
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
if (i * 2 >= audioData.Length) break;
|
||||
|
||||
var b1 = (byte)(audioShort[i] >> 8);
|
||||
var b2 = (byte)(audioShort[i] & 256);
|
||||
|
||||
audioData[i * 2] = b2;
|
||||
audioData[i * 2 + 1] = b1;
|
||||
}
|
||||
|
||||
result = new Sound(path, audioData);
|
||||
result.Format = (SoundFormat)vorbis.Channels - 1;
|
||||
result.SampleRate = vorbis.SampleRate;
|
||||
result.BufferSize = length;
|
||||
|
||||
vorbis.Dispose();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
DaggerFramework/Source/Resources/Loaders/Texture2dLoader.cs
Executable file
22
DaggerFramework/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;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
DaggerFramework/Source/Resources/Resource.cs
Executable file
23
DaggerFramework/Source/Resources/Resource.cs
Executable file
@@ -0,0 +1,23 @@
|
||||
namespace DaggerFramework
|
||||
{
|
||||
public abstract class Resource : IDisposable
|
||||
{
|
||||
public string? Path { get => _path; set => _path = value; }
|
||||
public byte[]? Buffer { get => _buffer; set => _buffer = value; }
|
||||
|
||||
public Resource(string path, byte[] buffer)
|
||||
{
|
||||
_path = path;
|
||||
_buffer = buffer;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Buffer = null;
|
||||
Path = null;
|
||||
}
|
||||
|
||||
private string? _path;
|
||||
private byte[]? _buffer;
|
||||
}
|
||||
}
|
||||
19
DaggerFramework/Source/Resources/Sound.cs
Normal file
19
DaggerFramework/Source/Resources/Sound.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace DaggerFramework
|
||||
{
|
||||
public class Sound : Resource
|
||||
{
|
||||
public SoundFormat Format { get; set; }
|
||||
public int SampleRate { get; set; }
|
||||
public int BufferSize { get; set; }
|
||||
|
||||
public Sound(string path, byte[] buffer) : base(path, buffer)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public enum SoundFormat
|
||||
{
|
||||
Mono,
|
||||
Stereo
|
||||
}
|
||||
}
|
||||
11
DaggerFramework/Source/Resources/Texture2d.cs
Executable file
11
DaggerFramework/Source/Resources/Texture2d.cs
Executable file
@@ -0,0 +1,11 @@
|
||||
namespace DaggerFramework
|
||||
{
|
||||
public class Texture2d : Resource
|
||||
{
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
public Texture2d(string path, byte[] buffer) : base(path, buffer)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user