Mirror von
https://github.com/Chaoscaot/schemsearch
synchronisiert 2024-11-16 17:00:14 +01:00
Commits vergleichen
Keine gemeinsamen Commits. "d1a01dc0c1f511f569e2ef0038307d76ffdb1642" und "9cca860db36603c25d8854b9146f70ba996c0fcd" haben vollständig unterschiedliche Historien.
d1a01dc0c1
...
9cca860db3
@ -7,7 +7,8 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
flate2 = "1.0.25"
|
||||
fastnbt = "2.4.3"
|
||||
hematite-nbt = "0.5.2"
|
||||
serde = "1.0.152"
|
||||
serde_json = "1.0.84"
|
||||
serde-this-or-that = "0.4.2"
|
||||
serde_repr = "0.1.12"
|
||||
|
||||
|
@ -15,22 +15,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use fastnbt::error::Error;
|
||||
use fastnbt::Value;
|
||||
use flate2::read::GzDecoder;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde::de::value::MapDeserializer;
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
struct SchematicRaw {
|
||||
version: i32,
|
||||
#[serde(flatten)]
|
||||
data: HashMap<String, Value>,
|
||||
}
|
||||
use nbt::{Error, from_gzip_reader, Map, Value};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde_this_or_that::as_i64;
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
#[serde(untagged, rename_all = "PascalCase")]
|
||||
@ -78,7 +67,7 @@ impl SchematicVersioned {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_palette(&self) -> &HashMap<String, i32> {
|
||||
pub fn get_palette(&self) -> &Map<String, i32> {
|
||||
return match self {
|
||||
SchematicVersioned::V1(schematic) => &schematic.palette,
|
||||
SchematicVersioned::V2(schematic) => &schematic.palette,
|
||||
@ -105,36 +94,16 @@ impl SchematicVersioned {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SchematicRaw> for SchematicVersioned {
|
||||
fn from(value: SchematicRaw) -> Self {
|
||||
match value.version {
|
||||
1 => {
|
||||
let schematic: SpongeV1Schematic = SpongeV1Schematic::deserialize(MapDeserializer::new(value.data.into_iter())).unwrap();
|
||||
return SchematicVersioned::V1(schematic);
|
||||
},
|
||||
2 => {
|
||||
let schematic: SpongeV2Schematic = SpongeV2Schematic::deserialize(MapDeserializer::new(value.data.into_iter())).unwrap();
|
||||
return SchematicVersioned::V2(schematic);
|
||||
},
|
||||
3 => {
|
||||
let schematic: SpongeV3Schematic = SpongeV3Schematic::deserialize(MapDeserializer::new(value.data.into_iter())).unwrap();
|
||||
return SchematicVersioned::V3(schematic);
|
||||
}
|
||||
_ => panic!("Unknown Schematic Version: {}", value.version),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct SpongeV1Schematic {
|
||||
pub metadata: HashMap<String, Value>,
|
||||
pub metadata: Map<String, Value>,
|
||||
pub width: u16,
|
||||
pub height: u16,
|
||||
pub length: u16,
|
||||
pub offset: [i32; 3],
|
||||
pub palette_max: i32,
|
||||
pub palette: HashMap<String, i32>,
|
||||
pub palette: Map<String, i32>,
|
||||
#[serde(deserialize_with = "read_blockdata")]
|
||||
pub block_data: Vec<i32>,
|
||||
pub tile_entities: Vec<BlockEntity>,
|
||||
@ -144,13 +113,13 @@ pub struct SpongeV1Schematic {
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct SpongeV2Schematic {
|
||||
pub data_version: i32,
|
||||
pub metadata: HashMap<String, Value>,
|
||||
pub metadata: Map<String, Value>,
|
||||
pub width: u16,
|
||||
pub height: u16,
|
||||
pub length: u16,
|
||||
pub offset: [i32; 3],
|
||||
pub palette_max: i32,
|
||||
pub palette: HashMap<String, i32>,
|
||||
pub palette: Map<String, i32>,
|
||||
#[serde(deserialize_with = "read_blockdata")]
|
||||
pub block_data: Vec<i32>,
|
||||
pub block_entities: Vec<BlockEntity>,
|
||||
@ -161,7 +130,7 @@ pub struct SpongeV2Schematic {
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct SpongeV3Schematic {
|
||||
pub data_version: i32,
|
||||
pub metadata: HashMap<String, Value>,
|
||||
pub metadata: Map<String, Value>,
|
||||
pub width: u16,
|
||||
pub height: u16,
|
||||
pub length: u16,
|
||||
@ -173,7 +142,7 @@ pub struct SpongeV3Schematic {
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct BlockContainer {
|
||||
pub palette: HashMap<String, i32>,
|
||||
pub palette: Map<String, i32>,
|
||||
#[serde(deserialize_with = "read_blockdata")]
|
||||
pub block_data: Vec<i32>,
|
||||
pub block_entities: Vec<BlockEntity>,
|
||||
@ -199,7 +168,7 @@ pub struct BlockEntity {
|
||||
pub struct BlockEntityV3 {
|
||||
pub id: String,
|
||||
pub pos: [i32; 3],
|
||||
pub data: HashMap<String, Value>,
|
||||
pub data: Map<String, Value>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@ -211,8 +180,8 @@ pub struct Entity {
|
||||
|
||||
impl SchematicVersioned {
|
||||
pub fn load_data<R>(data: R) -> Result<SchematicVersioned, Error> where R: Read {
|
||||
let raw: SchematicRaw = fastnbt::from_reader(GzDecoder::new(data))?;
|
||||
Ok(SchematicVersioned::from(raw))
|
||||
let schematic: SchematicVersioned = from_gzip_reader(data)?;
|
||||
Ok(schematic)
|
||||
}
|
||||
|
||||
pub fn load(path: &PathBuf) -> Result<SchematicVersioned, Error> {
|
||||
|
@ -10,3 +10,6 @@ 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,8 +18,10 @@
|
||||
pub mod pattern_mapper;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use nbt::Map;
|
||||
use pattern_mapper::match_palette;
|
||||
use schemsearch_files::SchematicVersioned;
|
||||
use schemsearch_files::{SchematicVersioned, SpongeV2Schematic};
|
||||
use schemsearch_files::SchematicVersioned::V2;
|
||||
use crate::pattern_mapper::match_palette_adapt;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren