mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 01:24:53 +01:00
minedmap: rename RegionCoords to TileCoords
With mipmapping, coords will not always correspond to regions anymore.
This commit is contained in:
parent
dede21806c
commit
007ce010d4
3 changed files with 13 additions and 13 deletions
|
@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use minedmap::{types::*, world::layer};
|
use minedmap::{types::*, world::layer};
|
||||||
|
|
||||||
pub type RegionCoords = (i32, i32);
|
pub type TileCoords = (i32, i32);
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct ProcessedChunk {
|
pub struct ProcessedChunk {
|
||||||
|
@ -21,7 +21,7 @@ pub struct Config {
|
||||||
pub map_dir: PathBuf,
|
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)
|
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");
|
let filename = coord_filename(coords, "bin");
|
||||||
[&self.processed_dir, Path::new(&filename)].iter().collect()
|
[&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");
|
let filename = coord_filename(coords, "png");
|
||||||
[&self.light_dir, Path::new(&filename)].iter().collect()
|
[&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");
|
let filename = coord_filename(coords, "png");
|
||||||
[&self.map_dir, Path::new(&filename)].iter().collect()
|
[&self.map_dir, Path::new(&filename)].iter().collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use minedmap::{
|
||||||
use super::common::*;
|
use super::common::*;
|
||||||
|
|
||||||
/// 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<RegionCoords> {
|
fn parse_region_filename(path: &Path) -> Option<TileCoords> {
|
||||||
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 {
|
||||||
|
@ -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);
|
let output_path = self.config.processed_path(coords);
|
||||||
storage::write(&output_path, processed_region)
|
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| {
|
fs::create_with_tmpfile(&self.config.light_path(coords), |file| {
|
||||||
lightmap
|
lightmap
|
||||||
.write_to(file, image::ImageFormat::Png)
|
.write_to(file, image::ImageFormat::Png)
|
||||||
|
@ -76,7 +76,7 @@ impl<'a> RegionProcessor<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes a single region file
|
/// 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;
|
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.0, coords.1);
|
||||||
|
@ -114,7 +114,7 @@ impl<'a> RegionProcessor<'a> {
|
||||||
/// Iterates over all region files of a Minecraft save directory
|
/// Iterates over all region files of a Minecraft save directory
|
||||||
///
|
///
|
||||||
/// Returns a list of the coordinates of all processed regions
|
/// 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(|| {
|
let read_dir = self.config.region_dir.read_dir().with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
"Failed to read directory {}",
|
"Failed to read directory {}",
|
||||||
|
|
|
@ -17,7 +17,7 @@ impl<'a> TileRenderer<'a> {
|
||||||
TileRenderer { config }
|
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);
|
let processed_path = self.config.processed_path(coords);
|
||||||
storage::read(&processed_path).context("Failed to load processed region data")
|
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;
|
const N: u32 = (BLOCKS_PER_CHUNK * CHUNKS_PER_REGION) as u32;
|
||||||
|
|
||||||
let output_path = self.config.map_path(coords);
|
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)?;
|
fs::create_dir_all(&self.config.map_dir)?;
|
||||||
|
|
||||||
for &coords in regions {
|
for &coords in regions {
|
||||||
|
|
Loading…
Add table
Reference in a new issue