aada 0.1.0

纯 Rust 的 2D 骨骼动画引擎,兼容 Spine 4.x 导出格式(JSON + atlas)。求解到分层 Mesh 与各 Mesh 渲染设置为止,之后交给渲染器。
Documentation
//! slot 的序列化中间结构(store 层),可转换为运行时 [`SlotData`]。

use serde::{Deserialize, Serialize};

use crate::{
    data::runtime::{skeleton::Skeleton, slot::SlotData},
    error::Error,
};

/// 存储用的 slot 数据
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SlotDataStore {
    /// slot 名称(唯一标识符)
    pub name: String,
    /// 绑定的骨骼名称
    pub bone: String,
    /// 默认 attachment 的逻辑名称,用于在皮肤中查找
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub default_attachment: Option<String>,
    /// slot 默认颜色(RGBA 各分量 0-1,spine JSON 的 color 字段,缺省白色)
    #[serde(default = "default_color")]
    pub color: [f32; 4],
}

/// 默认颜色:白色
pub fn default_color() -> [f32; 4] {
    [1.0, 1.0, 1.0, 1.0]
}

impl SlotDataStore {
    pub fn to_rt(self, skeleton: &Skeleton) -> Result<SlotData, Error> {
        let bone = skeleton.get_bone_index(&self.bone).ok_or_else(|| {
            Error::InvalidData(format!("slot references unknown bone: {}", self.bone))
        })?;
        Ok(SlotData {
            name: self.name,
            bone,
            default_attachment: self.default_attachment,
            // 逻辑名索引在 build_rt 组装时由 intern 表回填
            default_attachment_idx: None,
            color: self.color,
        })
    }
}