54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
namespace Minint.Core.Models;
|
|
|
|
/// <summary>
|
|
/// A single document (frame) within a container.
|
|
/// Has its own palette shared by all layers, plus a list of layers.
|
|
/// </summary>
|
|
public sealed class MinintDocument
|
|
{
|
|
public string Name { get; set; }
|
|
|
|
/// <summary>
|
|
/// Delay before showing the next frame during animation playback (ms).
|
|
/// </summary>
|
|
public uint FrameDelayMs { get; set; }
|
|
|
|
/// <summary>
|
|
/// Document palette. Index 0 is always <see cref="RgbaColor.Transparent"/>.
|
|
/// All layers reference colors by index into this list.
|
|
/// </summary>
|
|
public List<RgbaColor> Palette { get; }
|
|
|
|
public List<MinintLayer> Layers { get; }
|
|
|
|
public MinintDocument(string name)
|
|
{
|
|
Name = name;
|
|
FrameDelayMs = 100;
|
|
Palette = [RgbaColor.Transparent];
|
|
Layers = [];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor for deserialization — accepts pre-built palette and layers.
|
|
/// </summary>
|
|
public MinintDocument(string name, uint frameDelayMs, List<RgbaColor> palette, List<MinintLayer> layers)
|
|
{
|
|
Name = name;
|
|
FrameDelayMs = frameDelayMs;
|
|
Palette = palette;
|
|
Layers = layers;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the number of bytes needed to store a single palette index on disk.
|
|
/// </summary>
|
|
public int IndexByteWidth => Palette.Count switch
|
|
{
|
|
<= 255 => 1,
|
|
<= 65_535 => 2,
|
|
<= 16_777_215 => 3,
|
|
_ => 4
|
|
};
|
|
}
|