40 pub can_rotate270: Option<bool>, |
40 pub can_rotate270: Option<bool>, |
41 } |
41 } |
42 |
42 |
43 #[derive(Deserialize)] |
43 #[derive(Deserialize)] |
44 pub struct TileDescriptionHelper(#[serde(with = "TileDesc")] TileDescription); |
44 pub struct TileDescriptionHelper(#[serde(with = "TileDesc")] TileDescription); |
|
45 #[derive(Deserialize)] |
|
46 pub struct EdgeDescriptionHelper(#[serde(with = "EdgeDesc")] EdgeDescription); |
|
47 |
|
48 #[derive(Deserialize)] |
|
49 pub struct NonStrictEdgesDesc { |
|
50 pub top: Option<EdgeDescriptionHelper>, |
|
51 pub right: Option<EdgeDescriptionHelper>, |
|
52 pub bottom: Option<EdgeDescriptionHelper>, |
|
53 pub left: Option<EdgeDescriptionHelper>, |
|
54 } |
45 |
55 |
46 #[derive(Deserialize)] |
56 #[derive(Deserialize)] |
47 pub struct TemplateDesc { |
57 pub struct TemplateDesc { |
48 pub width: usize, |
58 pub width: usize, |
49 pub height: usize, |
59 pub height: usize, |
50 pub can_invert: bool, |
60 pub can_invert: bool, |
51 pub is_negative: bool, |
61 pub is_negative: bool, |
52 pub put_girders: bool, |
62 pub put_girders: bool, |
53 pub max_hedgehogs: u8, |
63 pub max_hedgehogs: u8, |
54 pub wrap: bool, |
64 pub wrap: bool, |
|
65 pub edges: Option<NonStrictEdgesDesc>, |
55 pub tiles: Vec<TileDescriptionHelper>, |
66 pub tiles: Vec<TileDescriptionHelper>, |
56 } |
67 } |
57 |
68 |
58 #[derive(Deserialize)] |
69 #[derive(Deserialize)] |
59 pub struct TemplateCollectionDesc { |
70 pub struct TemplateCollectionDesc { |
61 pub template_types: HashMap<String, Vec<usize>>, |
72 pub template_types: HashMap<String, Vec<usize>>, |
62 } |
73 } |
63 |
74 |
64 impl From<&TemplateDesc> for TemplateDescription { |
75 impl From<&TemplateDesc> for TemplateDescription { |
65 fn from(desc: &TemplateDesc) -> Self { |
76 fn from(desc: &TemplateDesc) -> Self { |
|
77 let [top, right, bottom, left] = if let Some(edges) = &desc.edges { |
|
78 [ |
|
79 edges.top.as_ref(), |
|
80 edges.right.as_ref(), |
|
81 edges.bottom.as_ref(), |
|
82 edges.left.as_ref(), |
|
83 ] |
|
84 .map(|e| e.map(|EdgeDescriptionHelper(e)| e.clone())) |
|
85 } else { |
|
86 [None, None, None, None] |
|
87 }; |
|
88 |
66 Self { |
89 Self { |
67 size: Size::new(desc.width, desc.height), |
90 size: Size::new(desc.width, desc.height), |
68 tiles: desc |
91 tiles: desc |
69 .tiles |
92 .tiles |
70 .iter() |
93 .iter() |
71 .map(|TileDescriptionHelper(t)| t.clone()) |
94 .map(|TileDescriptionHelper(t)| t.clone()) |
72 .collect(), |
95 .collect(), |
73 wrap: desc.wrap, |
96 wrap: desc.wrap, |
|
97 edges: NonStrictEdgesDescription { |
|
98 top, |
|
99 right, |
|
100 bottom, |
|
101 left, |
|
102 }, |
74 } |
103 } |
75 } |
104 } |
76 } |
105 } |