mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
core/metadata_writer: write entity list for viewer
This commit is contained in:
parent
cde6a4b6e6
commit
d29c0df25d
2 changed files with 44 additions and 7 deletions
|
@ -144,7 +144,9 @@ pub struct Config {
|
||||||
/// Path for storage of the final merged processed entity data file
|
/// Path for storage of the final merged processed entity data file
|
||||||
pub entities_path_final: PathBuf,
|
pub entities_path_final: PathBuf,
|
||||||
/// Path of viewer metadata file
|
/// Path of viewer metadata file
|
||||||
pub metadata_path: PathBuf,
|
pub viewer_info_path: PathBuf,
|
||||||
|
/// Path of viewer entities file
|
||||||
|
pub viewer_entities_path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
@ -161,7 +163,10 @@ impl Config {
|
||||||
let processed_dir: PathBuf = [&args.output_dir, Path::new("processed")].iter().collect();
|
let processed_dir: PathBuf = [&args.output_dir, Path::new("processed")].iter().collect();
|
||||||
let entities_dir: PathBuf = [&processed_dir, Path::new("entities")].iter().collect();
|
let entities_dir: PathBuf = [&processed_dir, Path::new("entities")].iter().collect();
|
||||||
let entities_path_final = [&entities_dir, Path::new("entities.bin")].iter().collect();
|
let entities_path_final = [&entities_dir, Path::new("entities.bin")].iter().collect();
|
||||||
let metadata_path = [&args.output_dir, Path::new("info.json")].iter().collect();
|
let viewer_info_path = [&args.output_dir, Path::new("info.json")].iter().collect();
|
||||||
|
let viewer_entities_path = [&args.output_dir, Path::new("entities.json")]
|
||||||
|
.iter()
|
||||||
|
.collect();
|
||||||
|
|
||||||
Config {
|
Config {
|
||||||
num_threads,
|
num_threads,
|
||||||
|
@ -171,7 +176,8 @@ impl Config {
|
||||||
processed_dir,
|
processed_dir,
|
||||||
entities_dir,
|
entities_dir,
|
||||||
entities_path_final,
|
entities_path_final,
|
||||||
metadata_path,
|
viewer_info_path,
|
||||||
|
viewer_entities_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{core::common::*, io::fs, world::de};
|
use crate::{
|
||||||
|
core::common::*,
|
||||||
|
io::{fs, storage},
|
||||||
|
world::{block_entity::BlockEntity, de},
|
||||||
|
};
|
||||||
|
|
||||||
/// Minimum and maximum X and Z tile coordinates for a mipmap level
|
/// Minimum and maximum X and Z tile coordinates for a mipmap level
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
@ -46,6 +50,13 @@ struct Metadata<'t> {
|
||||||
spawn: Spawn,
|
spawn: Spawn,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Viewer entity JSON data structure
|
||||||
|
#[derive(Debug, Serialize, Default)]
|
||||||
|
struct Entities {
|
||||||
|
/// List of signs
|
||||||
|
signs: Vec<BlockEntity>,
|
||||||
|
}
|
||||||
|
|
||||||
/// The MetadataWriter is used to generate the viewer metadata file
|
/// The MetadataWriter is used to generate the viewer metadata file
|
||||||
pub struct MetadataWriter<'a> {
|
pub struct MetadataWriter<'a> {
|
||||||
/// Common MinedMap configuration from command line
|
/// Common MinedMap configuration from command line
|
||||||
|
@ -109,6 +120,19 @@ impl<'a> MetadataWriter<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generates [Entities] data from collected entity lists
|
||||||
|
fn entities(&self) -> Result<Entities> {
|
||||||
|
let data: ProcessedEntities =
|
||||||
|
storage::read_file(&self.config.entities_path_final, storage::Format::Json)
|
||||||
|
.context("Failed to read entity data file")?;
|
||||||
|
|
||||||
|
let ret = Entities {
|
||||||
|
signs: data.block_entities,
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(ret)
|
||||||
|
}
|
||||||
|
|
||||||
/// Runs the viewer metadata file generation
|
/// Runs the viewer metadata file generation
|
||||||
pub fn run(self) -> Result<()> {
|
pub fn run(self) -> Result<()> {
|
||||||
let level_dat = self.read_level_dat()?;
|
let level_dat = self.read_level_dat()?;
|
||||||
|
@ -122,8 +146,15 @@ impl<'a> MetadataWriter<'a> {
|
||||||
metadata.mipmaps.push(Self::mipmap_entry(tile_map));
|
metadata.mipmaps.push(Self::mipmap_entry(tile_map));
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::create_with_tmpfile(&self.config.metadata_path, |file| {
|
fs::create_with_tmpfile(&self.config.viewer_info_path, |file| {
|
||||||
serde_json::to_writer(file, &metadata).context("Failed to write metadata")
|
serde_json::to_writer(file, &metadata).context("Failed to write info.json")
|
||||||
})
|
})?;
|
||||||
|
|
||||||
|
let entities = self.entities()?;
|
||||||
|
fs::create_with_tmpfile(&self.config.viewer_entities_path, |file| {
|
||||||
|
serde_json::to_writer(file, &entities).context("Failed to write entities.json")
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue