From e5c96ecb99e90aed1d72d09753372264b8b52bb2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 2 Jul 2023 15:45:18 +0200 Subject: [PATCH] minedmap: replace TileCoords type alias with a struct --- src/bin/minedmap/common.rs | 19 ++++++++++++++++--- src/bin/minedmap/region_processor.rs | 7 +++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/bin/minedmap/common.rs b/src/bin/minedmap/common.rs index c3e0c0e..8d64171 100644 --- a/src/bin/minedmap/common.rs +++ b/src/bin/minedmap/common.rs @@ -1,10 +1,23 @@ -use std::path::{Path, PathBuf}; +use std::{ + fmt::Debug, + path::{Path, PathBuf}, +}; use serde::{Deserialize, Serialize}; use minedmap::{types::*, world::layer}; -pub type TileCoords = (i32, i32); +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub struct TileCoords { + pub x: i32, + pub z: i32, +} + +impl Debug for TileCoords { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "({}, {})", self.x, self.z) + } +} #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ProcessedChunk { @@ -22,7 +35,7 @@ pub struct Config { } fn coord_filename(coords: TileCoords, ext: &str) -> String { - format!("r.{}.{}.{}", coords.0, coords.1, ext) + format!("r.{}.{}.{}", coords.x, coords.z, ext) } impl Config { diff --git a/src/bin/minedmap/region_processor.rs b/src/bin/minedmap/region_processor.rs index a942817..6072636 100644 --- a/src/bin/minedmap/region_processor.rs +++ b/src/bin/minedmap/region_processor.rs @@ -22,7 +22,10 @@ fn parse_region_filename(path: &Path) -> Option { return None; }; - Some((x.parse().ok()?, z.parse().ok()?)) + Some(TileCoords { + x: x.parse().ok()?, + z: z.parse().ok()?, + }) } /// Type with methods for processing the regions of a Minecraft save directory @@ -79,7 +82,7 @@ impl<'a> RegionProcessor<'a> { 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); + println!("Processing region r.{}.{}.mca", coords.x, coords.z); let mut processed_region = ProcessedRegion::default(); let mut lightmap = image::GrayAlphaImage::new(N, N);