mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
main: pass region_dir to RegionProcessor::new(), consume when processing
This commit is contained in:
parent
a2ba7e4738
commit
c5ca1d9821
1 changed files with 8 additions and 6 deletions
14
src/main.rs
14
src/main.rs
|
@ -21,13 +21,15 @@ type RegionCoords = (i32, i32);
|
|||
/// Type with methods for processing the regions of a Minecraft save directory
|
||||
struct RegionProcessor<'a> {
|
||||
block_types: resource::BlockTypeMap,
|
||||
region_dir: &'a Path,
|
||||
processed_dir: &'a Path,
|
||||
}
|
||||
|
||||
impl<'a> RegionProcessor<'a> {
|
||||
fn new(processed_dir: &'a Path) -> Self {
|
||||
fn new(region_dir: &'a Path, processed_dir: &'a Path) -> Self {
|
||||
RegionProcessor {
|
||||
block_types: resource::block_types(),
|
||||
region_dir,
|
||||
processed_dir,
|
||||
}
|
||||
}
|
||||
|
@ -104,10 +106,11 @@ impl<'a> RegionProcessor<'a> {
|
|||
/// Iterates over all region files of a Minecraft save directory
|
||||
///
|
||||
/// Returns a list of the coordinates of all processed regions
|
||||
fn process_region_dir(&self, region_dir: &Path) -> Result<Vec<RegionCoords>> {
|
||||
let read_dir = region_dir
|
||||
fn run(self) -> Result<Vec<RegionCoords>> {
|
||||
let read_dir = self
|
||||
.region_dir
|
||||
.read_dir()
|
||||
.with_context(|| format!("Failed to read directory {}", region_dir.display()))?;
|
||||
.with_context(|| format!("Failed to read directory {}", self.region_dir.display()))?;
|
||||
|
||||
fs::create_dir_all(&self.processed_dir).with_context(|| {
|
||||
format!(
|
||||
|
@ -150,8 +153,7 @@ fn main() -> Result<()> {
|
|||
let region_dir: PathBuf = [&args.input_dir, Path::new("region")].iter().collect();
|
||||
let processed_dir: PathBuf = [&args.output_dir, Path::new("processed")].iter().collect();
|
||||
|
||||
let region_processor = RegionProcessor::new(&processed_dir);
|
||||
region_processor.process_region_dir(®ion_dir)?;
|
||||
RegionProcessor::new(®ion_dir, &processed_dir).run()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue