paperdoll/
doll.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    common::{is_zero, Point},
5    image::ImageData,
6};
7
8/// The fundamental part of the paper doll model.
9#[derive(Clone, Debug, Deserialize, Serialize)]
10pub struct Doll {
11    id: u32,
12
13    /// The description of the doll.
14    #[serde(default, skip_serializing_if = "String::is_empty")]
15    pub desc: String,
16
17    /// The width of the doll in pixels.
18    #[serde(default, skip_serializing_if = "is_zero")]
19    pub width: u32,
20
21    /// The height of the doll in pixels.
22    #[serde(default, skip_serializing_if = "is_zero")]
23    pub height: u32,
24
25    /// The offset of the background image of the doll.
26    #[serde(default, skip_serializing_if = "Point::is_zero")]
27    pub offset: Point,
28
29    /// A list of id of [slots](crate::Slot) those can be used in the doll.
30    pub slots: Vec<u32>,
31
32    /// The path of the background image.
33    ///
34    /// Leave empty if no background.
35    pub path: String,
36
37    /// The data of the background image.
38    #[serde(skip)]
39    pub image: ImageData,
40}
41
42impl Doll {
43    pub(crate) fn new(id: u32) -> Self {
44        Self {
45            id,
46            desc: String::default(),
47            width: 0,
48            height: 0,
49            offset: Point::default(),
50            slots: vec![],
51            path: String::default(),
52            image: ImageData::default(),
53        }
54    }
55
56    pub fn id(&self) -> u32 {
57        self.id
58    }
59}