feat(exporters): add build() and available_names() factory

This commit is contained in:
2026-03-23 01:44:02 +01:00
parent 8933a2e690
commit f3c81a370c
3 changed files with 59 additions and 0 deletions

View File

@@ -8,3 +8,4 @@ thiserror = "2.0.18"
tracing = "0.1.44" tracing = "0.1.44"
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] } tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
serde = { version = "1.0.228", features = ["derive"] } serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1"

View File

@@ -11,3 +11,6 @@ anyhow = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
[dev-dependencies]
serde_json = { workspace = true }

View File

@@ -1,5 +1,60 @@
mod litematica; mod litematica;
mod mcfunction; mod mcfunction;
use lib::{BlockPalette, StructureExporter};
pub use litematica::LitematicaExporter; pub use litematica::LitematicaExporter;
pub use mcfunction::McFunctionExporter; pub use mcfunction::McFunctionExporter;
pub fn available_names() -> &'static [&'static str] {
&["mcfunction", "litematica"]
}
pub fn build(name: &str, palette: &BlockPalette) -> Option<Box<dyn StructureExporter>> {
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"));
}
}