Mirror von
https://github.com/Chaoscaot/schemsearch
synchronisiert 2024-11-19 10:20:08 +01:00
Something Working :D
Dieser Commit ist enthalten in:
Ursprung
9cca860db3
Commit
e03a805bdb
@ -9,6 +9,5 @@ edition = "2021"
|
||||
flate2 = "1.0.25"
|
||||
hematite-nbt = "0.5.2"
|
||||
serde = "1.0.152"
|
||||
serde-this-or-that = "0.4.2"
|
||||
serde_repr = "0.1.12"
|
||||
serde_json = "1.0.84"
|
||||
|
||||
|
@ -18,8 +18,15 @@
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use nbt::{Error, from_gzip_reader, Map, Value};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde_this_or_that::as_i64;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
struct SchematicRaw {
|
||||
version: i32,
|
||||
#[serde(flatten)]
|
||||
data: Map<String, Value>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
#[serde(untagged, rename_all = "PascalCase")]
|
||||
@ -94,6 +101,26 @@ impl SchematicVersioned {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SchematicRaw> for SchematicVersioned {
|
||||
fn from(value: SchematicRaw) -> Self {
|
||||
match value.version {
|
||||
1 => {
|
||||
let schematic: SpongeV1Schematic = serde_json::from_value(serde_json::to_value(value.data).unwrap()).unwrap();
|
||||
return SchematicVersioned::V1(schematic);
|
||||
},
|
||||
2 => {
|
||||
let schematic: SpongeV2Schematic = serde_json::from_value(serde_json::to_value(value.data).unwrap()).unwrap();
|
||||
return SchematicVersioned::V2(schematic);
|
||||
},
|
||||
3 => {
|
||||
let schematic: SpongeV3Schematic = serde_json::from_value(serde_json::to_value(value.data).unwrap()).unwrap();
|
||||
return SchematicVersioned::V3(schematic);
|
||||
}
|
||||
_ => panic!("Unknown Schematic Version: {}", value.version),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct SpongeV1Schematic {
|
||||
@ -180,8 +207,8 @@ pub struct Entity {
|
||||
|
||||
impl SchematicVersioned {
|
||||
pub fn load_data<R>(data: R) -> Result<SchematicVersioned, Error> where R: Read {
|
||||
let schematic: SchematicVersioned = from_gzip_reader(data)?;
|
||||
Ok(schematic)
|
||||
let raw: SchematicRaw = from_gzip_reader(data)?;
|
||||
Ok(SchematicVersioned::from(raw))
|
||||
}
|
||||
|
||||
pub fn load(path: &PathBuf) -> Result<SchematicVersioned, Error> {
|
||||
|
@ -10,6 +10,3 @@ license = "AGPL-3.0-or-later"
|
||||
hematite-nbt = "0.5.2"
|
||||
serde = "1.0.152"
|
||||
schemsearch-files = { path = "../schemsearch-files" }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0.95"
|
||||
|
@ -18,10 +18,8 @@
|
||||
pub mod pattern_mapper;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use nbt::Map;
|
||||
use pattern_mapper::match_palette;
|
||||
use schemsearch_files::{SchematicVersioned, SpongeV2Schematic};
|
||||
use schemsearch_files::SchematicVersioned::V2;
|
||||
use schemsearch_files::SchematicVersioned;
|
||||
use crate::pattern_mapper::match_palette_adapt;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren