equal
deleted
inserted
replaced
104 |
104 |
105 pub fn get_template(&self, template_type: &str) -> Option<&OutlineTemplate> { |
105 pub fn get_template(&self, template_type: &str) -> Option<&OutlineTemplate> { |
106 self.templates.get(template_type).and_then(|t| thread_rng().choose(t)) |
106 self.templates.get(template_type).and_then(|t| thread_rng().choose(t)) |
107 } |
107 } |
108 |
108 |
109 pub fn make_texture(&self, land: &Land2D<u32>, theme: &Theme) -> Vec2D<u32> { |
109 pub fn make_texture(&self, land: &Land2D<u8>, theme: &Theme) -> Vec2D<u32> { |
110 let mut texture = Vec2D::new(land.size(), 0); |
110 let mut texture = Vec2D::new(land.size(), 0); |
111 if let Some(land_sprite) = theme.land_texture() { |
111 if let Some(land_sprite) = theme.land_texture() { |
112 for (row_index, (land_row, tex_row)) in land.rows() |
112 for (row_index, (land_row, tex_row)) in land.rows() |
113 .zip(texture.rows_mut()) |
113 .zip(texture.rows_mut()) |
114 .enumerate() |
114 .enumerate() |
125 |
125 |
126 x_offset += land_sprite.width() |
126 x_offset += land_sprite.width() |
127 } |
127 } |
128 |
128 |
129 if x_offset < land.width() { |
129 if x_offset < land.width() { |
130 let final_range = x_offset..land.width() - 1; |
130 let final_range = x_offset..land.width(); |
131 tex_row_copy( |
131 tex_row_copy( |
132 &land_row[final_range.clone()], |
132 &land_row[final_range.clone()], |
133 &mut tex_row[final_range], |
133 &mut tex_row[final_range], |
134 &sprite_row[..land.width() - x_offset] |
134 &sprite_row[..land.width() - x_offset] |
135 ); |
135 ); |
138 } |
138 } |
139 texture |
139 texture |
140 } |
140 } |
141 } |
141 } |
142 |
142 |
143 fn tex_row_copy(land_row: &[u32], tex_row: &mut [u32], sprite_row: &[u32]) { |
143 fn tex_row_copy(land_row: &[u8], tex_row: &mut [u32], sprite_row: &[u32]) { |
144 for ((land_v, tex_v), sprite_v) in |
144 for ((land_v, tex_v), sprite_v) in |
145 land_row.iter().zip(tex_row.iter_mut()).zip(sprite_row) |
145 land_row.iter().zip(tex_row.iter_mut()).zip(sprite_row) |
146 { |
146 { |
147 *tex_v = if *land_v == 0 { |
147 *tex_v = if *land_v == 0 { |
148 *sprite_v |
148 *sprite_v |
149 } else { |
149 } else { |
150 0 |
150 0 |
151 } |
|
152 } |
151 } |
|
152 } |
153 } |
153 } |
154 |
154 |
155 #[cfg(test)] |
155 #[cfg(test)] |
156 mod tests { |
156 mod tests { |
157 use crate::{ |
157 use crate::{ |