use serde::{Deserialize, Serialize};
use crate::{
data::runtime::{skeleton::Skeleton, slot::SlotData},
error::Error,
};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SlotDataStore {
pub name: String,
pub bone: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub default_attachment: Option<String>,
#[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,
default_attachment_idx: None,
color: self.color,
})
}
}