mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
main: introduce RegionCoords type alias
This commit is contained in:
parent
768ab13205
commit
b68f04496c
1 changed files with 20 additions and 13 deletions
33
src/main.rs
33
src/main.rs
|
@ -11,6 +11,8 @@ struct Args {
|
||||||
input_dir: PathBuf,
|
input_dir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RegionCoords = (i32, i32);
|
||||||
|
|
||||||
/// Type with methods for processing the regions of a Minecraft save directory
|
/// Type with methods for processing the regions of a Minecraft save directory
|
||||||
struct RegionProcessor {
|
struct RegionProcessor {
|
||||||
block_types: resource::BlockTypeMap,
|
block_types: resource::BlockTypeMap,
|
||||||
|
@ -24,7 +26,7 @@ impl RegionProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a filename in the format r.X.Z.mca into the contained X and Z values
|
/// Parses a filename in the format r.X.Z.mca into the contained X and Z values
|
||||||
fn parse_region_filename(path: &Path) -> Option<(i32, i32)> {
|
fn parse_region_filename(path: &Path) -> Option<RegionCoords> {
|
||||||
let file_name = path.file_name()?.to_str()?;
|
let file_name = path.file_name()?.to_str()?;
|
||||||
let parts: Vec<_> = file_name.split('.').collect();
|
let parts: Vec<_> = file_name.split('.').collect();
|
||||||
let &["r", x, z, "mca"] = parts.as_slice() else {
|
let &["r", x, z, "mca"] = parts.as_slice() else {
|
||||||
|
@ -35,17 +37,19 @@ impl RegionProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes a single region file
|
/// Processes a single region file
|
||||||
fn process_region(&self, path: &Path, _x: i32, _z: i32) -> Result<()> {
|
fn process_region(&self, path: &Path, _coords: RegionCoords) -> Result<()> {
|
||||||
minedmap::io::region::from_file(path)?.foreach_chunk(|coords, data: world::de::Chunk| {
|
minedmap::io::region::from_file(path)?.foreach_chunk(
|
||||||
(|| -> Result<()> {
|
|chunk_coords, data: world::de::Chunk| {
|
||||||
let chunk = world::chunk::Chunk::new(&data)?;
|
(|| -> Result<()> {
|
||||||
|
let chunk = world::chunk::Chunk::new(&data)?;
|
||||||
|
|
||||||
let _top_layer = world::layer::top_layer(&chunk, &self.block_types)?;
|
let _top_layer = world::layer::top_layer(&chunk, &self.block_types)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})()
|
})()
|
||||||
.with_context(|| format!("Failed to process chunk {:?}", coords))
|
.with_context(|| format!("Failed to process chunk {:?}", chunk_coords))
|
||||||
})
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterates over all region files of a Minecraft save directory
|
/// Iterates over all region files of a Minecraft save directory
|
||||||
|
@ -62,12 +66,15 @@ impl RegionProcessor {
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}) {
|
}) {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let Some((x, z)) = Self::parse_region_filename(&path) else {
|
let Some(coords) = Self::parse_region_filename(&path) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(err) = self.process_region(&path, x, z) {
|
if let Err(err) = self.process_region(&path, coords) {
|
||||||
eprintln!("Failed to process region r.{}.{}.mca: {}", x, z, err);
|
eprintln!(
|
||||||
|
"Failed to process region r.{}.{}.mca: {}",
|
||||||
|
coords.0, coords.1, err,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue