minedmap: rename RegionCoords to TileCoords

With mipmapping, coords will not always correspond to regions anymore.
This commit is contained in:
Matthias Schiffer 2023-07-02 15:11:16 +02:00
parent dede21806c
commit 007ce010d4
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
3 changed files with 13 additions and 13 deletions

View file

@ -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()
}

View file

@ -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<RegionCoords> {
fn parse_region_filename(path: &Path) -> Option<TileCoords> {
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<Vec<RegionCoords>> {
pub fn run(self) -> Result<Vec<TileCoords>> {
let read_dir = self.config.region_dir.read_dir().with_context(|| {
format!(
"Failed to read directory {}",

View file

@ -17,7 +17,7 @@ impl<'a> TileRenderer<'a> {
TileRenderer { config }
}
fn load_region(&self, coords: RegionCoords) -> Result<ProcessedRegion> {
fn load_region(&self, coords: TileCoords) -> Result<ProcessedRegion> {
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 {