WIP: ResourceManager refactor, hot reloading using ResourceRef, API changes.

This commit is contained in:
2024-10-15 02:44:12 +02:00
parent a1d282908a
commit 851abd7c90
16 changed files with 394 additions and 117 deletions

View File

@@ -1,34 +1,34 @@
using System.Text.Json.Serialization;
using Voile.Resources;
namespace Voile
{
/// <summary>
/// Wraps a reference to an asset of a given type.
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class ResourceRef<T> where T : Resource
{
public readonly Guid Guid = Guid.Empty;
public bool HasValue => Guid != Guid.Empty;
public T Value => ResourceManager.GetResource<T>(Guid);
public ResourceRef(Guid guid)
{
Guid = guid;
}
}
public abstract class Resource : IDisposable
{
public Guid Guid { get; set; } = Guid.NewGuid();
public string Path { get; private set; } = string.Empty;
public string? Path { get => _path; set => _path = value; }
[JsonIgnore]
public byte[]? Buffer { get => _buffer; set => _buffer = value; }
[JsonIgnore]
public long BufferSize { get; set; }
public Resource(string path, byte[] buffer)
public Resource(string path)
{
_path = path;
_buffer = buffer;
BufferSize = buffer.Length;
Path = path;
}
public void Dispose()
{
Buffer = null;
Path = null;
}
private string? _path;
private byte[]? _buffer;
}
}