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

@@ -0,0 +1,20 @@
using System.Text.Json.Serialization;
namespace DaggerFramework.SceneGraph
{
public class SerializedScene : Resource
{
public Dictionary<string, Layer> Layers { get; set; }
public SerializedScene(string path, byte[] buffer) : base(path, buffer)
{
}
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(SerializedScene))]
internal partial class SerializedSceneContext : JsonSerializerContext
{
}
}

View File

@@ -0,0 +1,23 @@
using DaggerFramework.Resources;
using DaggerFramework.Utils;
namespace DaggerFramework.SceneGraph
{
public class SerializedSceneSaver : IResourceSaver<SerializedScene>
{
public bool TrySave(string path, in SerializedScene resource)
{
if (resource.Buffer is null)
{
_logger.Error($"Tried to save a resource at \"{path}\" with a null buffer!");
return false;
}
File.WriteAllBytes(path, resource.Buffer);
return true;
}
private Logger _logger = new(nameof(SerializedSceneSaver));
}
}