diff --git a/Cargo.toml b/Cargo.toml index 096e388..e656006 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ thiserror = "2.0.18" tracing = "0.1.44" tracing-subscriber = { version = "0.3.23", features = ["env-filter"] } serde = { version = "1.0.228", features = ["derive"] } +serde_json = "1" diff --git a/crates/exporters/Cargo.toml b/crates/exporters/Cargo.toml index be7734e..41dabdb 100644 --- a/crates/exporters/Cargo.toml +++ b/crates/exporters/Cargo.toml @@ -11,3 +11,6 @@ anyhow = { workspace = true } thiserror = { workspace = true } tracing = { workspace = true } serde = { workspace = true } + +[dev-dependencies] +serde_json = { workspace = true } diff --git a/crates/exporters/src/lib.rs b/crates/exporters/src/lib.rs index 3be9955..e4c2888 100644 --- a/crates/exporters/src/lib.rs +++ b/crates/exporters/src/lib.rs @@ -1,5 +1,60 @@ mod litematica; mod mcfunction; +use lib::{BlockPalette, StructureExporter}; + pub use litematica::LitematicaExporter; pub use mcfunction::McFunctionExporter; + +pub fn available_names() -> &'static [&'static str] { + &["mcfunction", "litematica"] +} + +pub fn build(name: &str, palette: &BlockPalette) -> Option> { + match name { + "mcfunction" => Some(Box::new(McFunctionExporter::new(palette))), + "litematica" => Some(Box::new(LitematicaExporter::new(palette))), + _ => None, + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn dummy_palette() -> BlockPalette { + serde_json::from_str(r#"{ + "name": "test", + "blocks": { + "body": "minecraft:stone", + "outline": "minecraft:cobblestone", + "shadow": "minecraft:gravel" + } + }"#).unwrap() + } + + #[test] + fn build_mcfunction_returns_some() { + let p = dummy_palette(); + assert!(build("mcfunction", &p).is_some()); + } + + #[test] + fn build_litematica_returns_some() { + let p = dummy_palette(); + assert!(build("litematica", &p).is_some()); + } + + #[test] + fn build_unknown_returns_none() { + let p = dummy_palette(); + assert!(build("foo", &p).is_none()); + } + + #[test] + fn available_names_contains_both() { + let names = available_names(); + assert!(names.contains(&"mcfunction")); + assert!(names.contains(&"litematica")); + } +}