mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
main: rename Paths to Config
This commit is contained in:
parent
ec09afcf15
commit
2ccb282f6f
1 changed files with 20 additions and 20 deletions
40
src/main.rs
40
src/main.rs
|
@ -18,19 +18,19 @@ struct Args {
|
|||
|
||||
type RegionCoords = (i32, i32);
|
||||
|
||||
struct Paths {
|
||||
struct Config {
|
||||
region_dir: PathBuf,
|
||||
processed_dir: PathBuf,
|
||||
map_dir: PathBuf,
|
||||
}
|
||||
|
||||
impl Paths {
|
||||
impl Config {
|
||||
fn new(args: 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 map_dir = [&args.output_dir, Path::new("map/0")].iter().collect();
|
||||
|
||||
Paths {
|
||||
Config {
|
||||
region_dir,
|
||||
processed_dir,
|
||||
map_dir,
|
||||
|
@ -51,14 +51,14 @@ impl Paths {
|
|||
/// Type with methods for processing the regions of a Minecraft save directory
|
||||
struct RegionProcessor<'a> {
|
||||
block_types: resource::BlockTypes,
|
||||
paths: &'a Paths,
|
||||
config: &'a Config,
|
||||
}
|
||||
|
||||
impl<'a> RegionProcessor<'a> {
|
||||
fn new(paths: &'a Paths) -> Self {
|
||||
fn new(config: &'a Config) -> Self {
|
||||
RegionProcessor {
|
||||
block_types: resource::BlockTypes::default(),
|
||||
paths,
|
||||
config,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,10 +84,10 @@ impl<'a> RegionProcessor<'a> {
|
|||
region: RegionCoords,
|
||||
processed_data: &ChunkArray<Option<Box<world::layer::BlockInfoArray>>>,
|
||||
) -> Result<()> {
|
||||
let tmp_path = self.paths.processed_path(region, true);
|
||||
let tmp_path = self.config.processed_path(region, true);
|
||||
storage::write(&tmp_path, processed_data)?;
|
||||
|
||||
let output_path = self.paths.processed_path(region, false);
|
||||
let output_path = self.config.processed_path(region, false);
|
||||
fs::rename(&tmp_path, &output_path).with_context(|| {
|
||||
format!(
|
||||
"Failed to rename {} to {}",
|
||||
|
@ -125,17 +125,17 @@ impl<'a> RegionProcessor<'a> {
|
|||
///
|
||||
/// Returns a list of the coordinates of all processed regions
|
||||
fn run(self) -> Result<Vec<RegionCoords>> {
|
||||
let read_dir = self.paths.region_dir.read_dir().with_context(|| {
|
||||
let read_dir = self.config.region_dir.read_dir().with_context(|| {
|
||||
format!(
|
||||
"Failed to read directory {}",
|
||||
self.paths.region_dir.display()
|
||||
self.config.region_dir.display()
|
||||
)
|
||||
})?;
|
||||
|
||||
fs::create_dir_all(&self.paths.processed_dir).with_context(|| {
|
||||
fs::create_dir_all(&self.config.processed_dir).with_context(|| {
|
||||
format!(
|
||||
"Failed to create directory {}",
|
||||
self.paths.processed_dir.display(),
|
||||
self.config.processed_dir.display(),
|
||||
)
|
||||
})?;
|
||||
|
||||
|
@ -168,12 +168,12 @@ impl<'a> RegionProcessor<'a> {
|
|||
}
|
||||
|
||||
struct TileRenderer<'a> {
|
||||
paths: &'a Paths,
|
||||
config: &'a Config,
|
||||
}
|
||||
|
||||
impl<'a> TileRenderer<'a> {
|
||||
fn new(paths: &'a Paths) -> Self {
|
||||
TileRenderer { paths }
|
||||
fn new(config: &'a Config) -> Self {
|
||||
TileRenderer { config }
|
||||
}
|
||||
|
||||
fn render_tile(&self, coords: RegionCoords) -> Result<()> {
|
||||
|
@ -183,10 +183,10 @@ impl<'a> TileRenderer<'a> {
|
|||
}
|
||||
|
||||
fn run(self, regions: &[RegionCoords]) -> Result<()> {
|
||||
fs::create_dir_all(&self.paths.map_dir).with_context(|| {
|
||||
fs::create_dir_all(&self.config.map_dir).with_context(|| {
|
||||
format!(
|
||||
"Failed to create directory {}",
|
||||
self.paths.map_dir.display(),
|
||||
self.config.map_dir.display(),
|
||||
)
|
||||
})?;
|
||||
|
||||
|
@ -200,10 +200,10 @@ impl<'a> TileRenderer<'a> {
|
|||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
let paths = Paths::new(args);
|
||||
let config = Config::new(args);
|
||||
|
||||
let regions = RegionProcessor::new(&paths).run()?;
|
||||
TileRenderer::new(&paths).run(®ions)?;
|
||||
let regions = RegionProcessor::new(&config).run()?;
|
||||
TileRenderer::new(&config).run(®ions)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue