Update avatar_layers implementation, assets and documentation
This commit is contained in:
commit
1753766a5d
21 files changed
+757
No files matched your search
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using Cthangover.Core.Mods;
|
||||
using Cthangover.Core.Mods.Resolvers;
|
||||
using Godot;
|
||||
|
||||
namespace Cthangover.Mods.AvatarLayers
|
||||
{
|
||||
/// <summary>Loads exact PNG paths through mod providers, so ZIP assets and overrides work alike.</summary>
|
||||
internal static class AvatarLayerImages
|
||||
{
|
||||
// The renderer owns the returned texture and must dispose it after detaching all node references.
|
||||
internal static Texture2D Load(string path)
|
||||
{
|
||||
if (!path.EndsWith(".png", StringComparison.Ordinal))
|
||||
throw new ArgumentException($"Avatar layer image '{path}' must be an exact .png path.");
|
||||
if (!Files.Collect("avatar_layers").TryGetValue(path, out var file))
|
||||
throw new ArgumentException($"Avatar layer image '{path}' was not found in avatar_layers.");
|
||||
var bytes = ModManager.Instance.ReadFileBinary(file.ModId, file.FullPath);
|
||||
if (bytes == null) throw new ArgumentException($"Cannot read avatar layer image '{path}'.");
|
||||
using var image = new Image();
|
||||
if (image.LoadPngFromBuffer(bytes) != Error.Ok)
|
||||
throw new ArgumentException($"Avatar layer image '{path}' is not a valid PNG.");
|
||||
return ImageTexture.CreateFromImage(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user