From 007ce010d4400108a9f628a91cefb810805dc276 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 2 Jul 2023 15:11:16 +0200 Subject: [PATCH] minedmap: rename RegionCoords to TileCoords With mipmapping, coords will not always correspond to regions anymore. --- src/bin/minedmap/common.rs | 10 +++++----- src/bin/minedmap/region_processor.rs | 10 +++++----- src/bin/minedmap/tile_renderer.rs | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/bin/minedmap/common.rs b/src/bin/minedmap/common.rs index 764fe4c..c3e0c0e 100644 --- a/src/bin/minedmap/common.rs +++ b/src/bin/minedmap/common.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use minedmap::{types::*, world::layer}; -pub type RegionCoords = (i32, i32); +pub type TileCoords = (i32, i32); #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ProcessedChunk { @@ -21,7 +21,7 @@ pub struct Config { pub map_dir: PathBuf, } -fn coord_filename(coords: RegionCoords, ext: &str) -> String { +fn coord_filename(coords: TileCoords, ext: &str) -> String { format!("r.{}.{}.{}", coords.0, coords.1, ext) } @@ -40,17 +40,17 @@ impl Config { } } - pub fn processed_path(&self, coords: RegionCoords) -> PathBuf { + pub fn processed_path(&self, coords: TileCoords) -> PathBuf { let filename = coord_filename(coords, "bin"); [&self.processed_dir, Path::new(&filename)].iter().collect() } - pub fn light_path(&self, coords: RegionCoords) -> PathBuf { + pub fn light_path(&self, coords: TileCoords) -> PathBuf { let filename = coord_filename(coords, "png"); [&self.light_dir, Path::new(&filename)].iter().collect() } - pub fn map_path(&self, coords: RegionCoords) -> PathBuf { + pub fn map_path(&self, coords: TileCoords) -> PathBuf { let filename = coord_filename(coords, "png"); [&self.map_dir, Path::new(&filename)].iter().collect() } diff --git a/src/bin/minedmap/region_processor.rs b/src/bin/minedmap/region_processor.rs index 03229be..a942817 100644 --- a/src/bin/minedmap/region_processor.rs +++ b/src/bin/minedmap/region_processor.rs @@ -15,7 +15,7 @@ use minedmap::{ use super::common::*; /// Parses a filename in the format r.X.Z.mca into the contained X and Z values -fn parse_region_filename(path: &Path) -> Option { +fn parse_region_filename(path: &Path) -> Option { let file_name = path.file_name()?.to_str()?; let parts: Vec<_> = file_name.split('.').collect(); let &["r", x, z, "mca"] = parts.as_slice() else { @@ -62,12 +62,12 @@ impl<'a> RegionProcessor<'a> { }) } - fn save_region(&self, coords: RegionCoords, processed_region: &ProcessedRegion) -> Result<()> { + fn save_region(&self, coords: TileCoords, processed_region: &ProcessedRegion) -> Result<()> { let output_path = self.config.processed_path(coords); storage::write(&output_path, processed_region) } - fn save_lightmap(&self, coords: RegionCoords, lightmap: &image::GrayAlphaImage) -> Result<()> { + fn save_lightmap(&self, coords: TileCoords, lightmap: &image::GrayAlphaImage) -> Result<()> { fs::create_with_tmpfile(&self.config.light_path(coords), |file| { lightmap .write_to(file, image::ImageFormat::Png) @@ -76,7 +76,7 @@ impl<'a> RegionProcessor<'a> { } /// Processes a single region file - fn process_region(&self, path: &Path, coords: RegionCoords) -> Result<()> { + fn process_region(&self, path: &Path, coords: TileCoords) -> Result<()> { const N: u32 = (BLOCKS_PER_CHUNK * CHUNKS_PER_REGION) as u32; println!("Processing region r.{}.{}.mca", coords.0, coords.1); @@ -114,7 +114,7 @@ impl<'a> RegionProcessor<'a> { /// Iterates over all region files of a Minecraft save directory /// /// Returns a list of the coordinates of all processed regions - pub fn run(self) -> Result> { + pub fn run(self) -> Result> { let read_dir = self.config.region_dir.read_dir().with_context(|| { format!( "Failed to read directory {}", diff --git a/src/bin/minedmap/tile_renderer.rs b/src/bin/minedmap/tile_renderer.rs index b4f4a3a..ef23547 100644 --- a/src/bin/minedmap/tile_renderer.rs +++ b/src/bin/minedmap/tile_renderer.rs @@ -17,7 +17,7 @@ impl<'a> TileRenderer<'a> { TileRenderer { config } } - fn load_region(&self, coords: RegionCoords) -> Result { + fn load_region(&self, coords: TileCoords) -> Result { let processed_path = self.config.processed_path(coords); storage::read(&processed_path).context("Failed to load processed region data") } @@ -56,7 +56,7 @@ impl<'a> TileRenderer<'a> { } } - fn render_tile(&self, coords: RegionCoords) -> Result<()> { + fn render_tile(&self, coords: TileCoords) -> Result<()> { const N: u32 = (BLOCKS_PER_CHUNK * CHUNKS_PER_REGION) as u32; let output_path = self.config.map_path(coords); @@ -80,7 +80,7 @@ impl<'a> TileRenderer<'a> { }) } - pub fn run(self, regions: &[RegionCoords]) -> Result<()> { + pub fn run(self, regions: &[TileCoords]) -> Result<()> { fs::create_dir_all(&self.config.map_dir)?; for &coords in regions {