Finishing

This commit is contained in:
Chaoscaot
2023-03-08 15:47:51 +01:00
parent 74df144d05
commit 98d797532e
11 changed files with 823 additions and 45 deletions

View File

@ -1,3 +1,4 @@
use std::io::Read;
use std::path::Path;
use nbt::{Map, Value};
use serde::{Deserialize, Deserializer, Serialize};
@ -55,16 +56,20 @@ pub struct Entity {
}
impl Schematic {
pub fn load_data<R>(data: R) -> Result<Schematic, String> where R: Read {
let schematic: Schematic = match nbt::from_gzip_reader(data) {
Ok(schem) => schem,
Err(e) => return Err(format!("Failed to parse schematic: {}", e))
};
Ok(schematic)
}
pub fn load(path: &Path) -> Result<Schematic, String> {
let file = match std::fs::File::open(path) {
Ok(x) => x,
Err(_) => return Err(format!("Failed to open file: {}", path.display()))
};
let schematic: Schematic = match nbt::from_gzip_reader(file) {
Ok(schem) => schem,
Err(e) => return Err(format!("Failed to parse schematic: {}", e))
};
Ok(schematic)
Schematic::load_data(file)
}
}