diff --git a/assets/textures/grass.png b/assets/textures/grass.png new file mode 100644 index 0000000..6dfc320 Binary files /dev/null and b/assets/textures/grass.png differ diff --git a/build.rs b/build.rs index 879bf6c..a7cbc4f 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,6 @@ use std::fs::create_dir_all; -use image::RgbaImage; +use image::{RgbaImage, GenericImage}; use image::imageops::{rotate90, rotate180, rotate270}; fn superpose(image: &RgbaImage, superposition: &RgbaImage) -> RgbaImage { @@ -20,12 +20,15 @@ fn superpose(image: &RgbaImage, superposition: &RgbaImage) -> RgbaImage { fn main() { create_dir_all("assets/textures-generated").unwrap(); - let background = image::open("assets/textures/grass/background.png").unwrap().to_rgba(); - let border = image::open("assets/textures/grass/border.png").unwrap().to_rgba(); - let corner_horiz = image::open("assets/textures/grass/corner-horiz.png").unwrap().to_rgba(); - let corner_vert = image::open("assets/textures/grass/corner-vert.png").unwrap().to_rgba(); - let corner_inside = image::open("assets/textures/grass/corner-inside.png").unwrap().to_rgba(); - let corner_outside = image::open("assets/textures/grass/corner-outside.png").unwrap().to_rgba(); + let mut texture = image::open("assets/textures/grass.png").unwrap().to_rgba(); + let background = texture.sub_image(0, 0, 32, 32).to_image(); + let border = texture.sub_image(32, 0, 32, 32).to_image(); + let corner_horiz = texture.sub_image(32 * 2 , 0, 32, 32).to_image(); + let corner_vert = texture.sub_image(32 * 3, 0, 32, 32).to_image(); + let corner_inside = texture.sub_image(32 * 4, 0, 32, 32).to_image(); + let corner_outside = texture.sub_image(32 * 5, 0, 32, 32).to_image(); + let mut background_color = texture.sub_image(32 * 6, 0, 32, 32); + let background_color = background_color.get_pixel_mut(0, 0); let mut vec = vec![]; @@ -181,10 +184,12 @@ fn main() { for (index, image) in vec.into_iter().enumerate() { for y in 0 .. image.width() { for x in 0 .. image.height() { - *output.get_pixel_mut(x + 32 * index as u32, y) = *background.get_pixel(x, y); let new_pixel = image.get_pixel(x, y); - if new_pixel[3] > 0 { - *output.get_pixel_mut(x + 32 * index as u32, y) = *new_pixel; + if new_pixel != background_color { + *output.get_pixel_mut(x + 32 * index as u32, y) = *background.get_pixel(x, y); + if new_pixel[3] > 0 { + *output.get_pixel_mut(x + 32 * index as u32, y) = *new_pixel; + } } } }