mindustry logic execution, map- and schematic- parsing and rendering
add a background
| -rw-r--r-- | src/data/renderer.rs | 4 | ||||
| -rw-r--r-- | src/utils/image.rs | 13 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/data/renderer.rs b/src/data/renderer.rs index e6cbe2b..a22a7ef 100644 --- a/src/data/renderer.rs +++ b/src/data/renderer.rs @@ -7,6 +7,8 @@ use image::imageops::overlay; use image::{DynamicImage, RgbaImage}; use zip::ZipArchive; +use crate::utils::image::repeat; + use super::schematic::Schematic; pub(crate) fn load(category: &str, name: &str) -> Option<RgbaImage> { @@ -75,6 +77,8 @@ impl<'l> Renderer { pub fn render(s: &'l Schematic<'_>) -> RgbaImage { load_zip(); let mut canvas = RgbaImage::new((s.width * 32).into(), (s.height * 32).into()); + // fill background + repeat(&mut canvas, &load("environment", "metal-floor").unwrap()); for tile in s.block_iter() { let x = (tile.pos.0 - ((tile.block.get_size() - 1) / 2) as u16) as i64; let y = (s.height - tile.pos.1 - ((tile.block.get_size() / 2) + 1) as u16) as i64; diff --git a/src/utils/image.rs b/src/utils/image.rs index 50a4cf7..867d1fc 100644 --- a/src/utils/image.rs +++ b/src/utils/image.rs @@ -12,3 +12,16 @@ pub fn tint(image: &mut RgbaImage, color: Rgb<u8>) { *b = (*b as f32 * tb) as u8; } } + +pub fn repeat(to: &mut RgbaImage, from: &RgbaImage) { + for x in 0..(to.width() / from.width()) { + for y in 0..(to.height() / from.height()) { + image::imageops::overlay( + to, + from, + (x * from.width()).into(), + (y * from.height()).into(), + ); + } + } +} |