31 pub left: Option<ComplexEdgeDesc>, |
31 pub left: Option<ComplexEdgeDesc>, |
32 } |
32 } |
33 |
33 |
34 #[derive(Debug, Deserialize)] |
34 #[derive(Debug, Deserialize)] |
35 pub struct TemplateDesc { |
35 pub struct TemplateDesc { |
36 pub width: usize, |
36 pub width: u32, |
37 pub height: usize, |
37 pub height: u32, |
38 pub can_invert: Option<bool>, |
38 pub can_invert: Option<bool>, |
39 pub is_negative: Option<bool>, |
39 pub is_negative: Option<bool>, |
40 pub put_girders: Option<bool>, |
40 pub put_girders: Option<bool>, |
41 pub max_hedgehogs: u8, |
41 pub max_hedgehogs: u8, |
42 pub wrap: Option<bool>, |
42 pub wrap: Option<bool>, |
51 pub edges: HashMap<String, NonStrictComplexEdgesDesc>, |
51 pub edges: HashMap<String, NonStrictComplexEdgesDesc>, |
52 pub template_types: HashMap<String, Vec<usize>>, |
52 pub template_types: HashMap<String, Vec<usize>>, |
53 } |
53 } |
54 |
54 |
55 impl TemplateDesc { |
55 impl TemplateDesc { |
56 pub fn to_template(&self, tiles: &HashMap<String, Vec<TileDesc>>, edges: &HashMap<String, NonStrictComplexEdgesDesc>) -> TemplateDescription { |
56 pub fn to_template( |
|
57 &self, |
|
58 tiles: &HashMap<String, Vec<TileDesc>>, |
|
59 edges: &HashMap<String, NonStrictComplexEdgesDesc>, |
|
60 ) -> TemplateDescription { |
57 let [top, right, bottom, left]: [Option<ComplexEdgeDescription>; 4] = |
61 let [top, right, bottom, left]: [Option<ComplexEdgeDescription>; 4] = |
58 if let Some(edges_name) = &self.edges { |
62 if let Some(edges_name) = &self.edges { |
59 let edges = edges.get(edges_name).expect("missing template edges"); |
63 let edges = edges.get(edges_name).expect("missing template edges"); |
60 [&edges.top, &edges.right, &edges.bottom, &edges.left] |
64 [&edges.top, &edges.right, &edges.bottom, &edges.left] |
61 .map(|e| e.as_ref().map(Into::into)) |
65 .map(|e| e.as_ref().map(Into::into)) |
62 } else { |
66 } else { |
63 [None, None, None, None] |
67 [None, None, None, None] |
64 }; |
68 }; |
65 |
69 |
66 let tiles = self.tiles.iter().flat_map(|t| tiles.get(t).expect("missing template tiles")).collect::<Vec<_>>(); |
70 let tiles = self |
|
71 .tiles |
|
72 .iter() |
|
73 .flat_map(|t| tiles.get(t).expect("missing template tiles")) |
|
74 .collect::<Vec<_>>(); |
67 |
75 |
68 TemplateDescription { |
76 TemplateDescription { |
69 size: Size::new(self.width, self.height), |
77 size: Size::new(self.width, self.height), |
70 tiles: tiles.into_iter().map(|t| t.into()).collect(), |
78 tiles: tiles.into_iter().map(|t| t.into()).collect(), |
71 wrap: self.wrap.unwrap_or(false), |
79 wrap: self.wrap.unwrap_or(false), |