minedmap: introduce generic tile path function, pass mipmap level

This commit is contained in:
Matthias Schiffer 2023-07-02 18:51:17 +02:00
parent b53d34da3d
commit b1f7f759f1
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
3 changed files with 29 additions and 19 deletions

View file

@ -30,26 +30,28 @@ pub type ProcessedRegion = ChunkArray<Option<ProcessedChunk>>;
pub struct Config {
pub region_dir: PathBuf,
pub processed_dir: PathBuf,
pub light_dir: PathBuf,
pub map_dir: PathBuf,
pub output_dir: PathBuf,
}
fn coord_filename(coords: TileCoords, ext: &str) -> String {
format!("r.{}.{}.{}", coords.x, coords.z, ext)
}
#[derive(Debug, Clone, Copy)]
pub enum TileKind {
Map,
Lightmap,
}
impl Config {
pub fn new(args: super::Args) -> Self {
let region_dir = [&args.input_dir, Path::new("region")].iter().collect();
let processed_dir = [&args.output_dir, Path::new("processed")].iter().collect();
let light_dir = [&args.output_dir, Path::new("light/0")].iter().collect();
let map_dir = [&args.output_dir, Path::new("map/0")].iter().collect();
Config {
region_dir,
processed_dir,
light_dir,
map_dir,
output_dir: args.output_dir,
}
}
@ -58,14 +60,19 @@ impl Config {
[&self.processed_dir, Path::new(&filename)].iter().collect()
}
pub fn light_path(&self, coords: TileCoords) -> PathBuf {
let filename = coord_filename(coords, "png");
[&self.light_dir, Path::new(&filename)].iter().collect()
pub fn tile_dir(&self, kind: TileKind, level: usize) -> PathBuf {
let prefix = match kind {
TileKind::Map => "map",
TileKind::Lightmap => "light",
};
let dir = format!("{}/{}", prefix, level);
[&self.output_dir, Path::new(&dir)].iter().collect()
}
pub fn map_path(&self, coords: TileCoords) -> PathBuf {
pub fn tile_path(&self, kind: TileKind, level: usize, coords: TileCoords) -> PathBuf {
let filename = coord_filename(coords, "png");
[&self.map_dir, Path::new(&filename)].iter().collect()
let dir = self.tile_dir(kind, level);
[Path::new(&dir), Path::new(&filename)].iter().collect()
}
}