diff --git a/src/bin/minedmap/tile_renderer.rs b/src/bin/minedmap/tile_renderer.rs index fcd3e85..64c9d55 100644 --- a/src/bin/minedmap/tile_renderer.rs +++ b/src/bin/minedmap/tile_renderer.rs @@ -2,23 +2,10 @@ use std::fs; use anyhow::{Context, Result}; -use minedmap::{io::storage, resource::Biome, types::*, world}; +use minedmap::{io::storage, resource::block_color, types::*, world}; use super::common::*; -fn block_color(block: &world::layer::BlockInfo, _biome: &Biome) -> [u8; 4] { - let h = block - .depth - .map(|depth| 0.5 + 0.005 * depth.0 as f32) - .unwrap_or_default(); - let c = block - .block_type - .color - .0 - .map(|v| (f32::from(v) * h).clamp(0.0, 255.0) as u8); - [c[0], c[1], c[2], 255] -} - pub struct TileRenderer<'a> { config: &'a Config, } @@ -47,7 +34,14 @@ impl<'a> TileRenderer<'a> { z: BlockZ(z as u8), }; image::Rgba(match (&blocks[coords], &biomes[coords]) { - (Some(block), Some(biome)) => block_color(block, biome), + ( + Some(world::layer::BlockInfo { + block_type, + depth: Some(depth), + .. + }), + Some(biome), + ) => block_color(*block_type, biome, depth.0 as f32), _ => [0, 0, 0, 0], }) }); diff --git a/src/resource/block_color.rs b/src/resource/block_color.rs new file mode 100644 index 0000000..31434de --- /dev/null +++ b/src/resource/block_color.rs @@ -0,0 +1,10 @@ +use super::{Biome, BlockType}; + +pub fn block_color(block: BlockType, _biome: &Biome, depth: f32) -> [u8; 4] { + let h = 0.5 + 0.005 * depth; + let c = block + .color + .0 + .map(|v| (f32::from(v) * h).clamp(0.0, 255.0) as u8); + [c[0], c[1], c[2], 255] +} diff --git a/src/resource/mod.rs b/src/resource/mod.rs index 62c5d9c..a1abaf8 100644 --- a/src/resource/mod.rs +++ b/src/resource/mod.rs @@ -1,4 +1,5 @@ mod biomes; +mod block_color; mod block_types; mod legacy_block_types; @@ -90,6 +91,7 @@ impl BlockTypes { } pub use biomes::Biome; +pub use block_color::block_color; #[derive(Debug)] pub struct BiomeTypes {