refactor(exporters): single registry source of truth

This commit is contained in:
2026-03-23 01:46:31 +01:00
parent f3c81a370c
commit c425b63361

View File

@@ -6,16 +6,21 @@ use lib::{BlockPalette, StructureExporter};
pub use litematica::LitematicaExporter;
pub use mcfunction::McFunctionExporter;
pub fn available_names() -> &'static [&'static str] {
&["mcfunction", "litematica"]
type ExporterFactory = fn(&BlockPalette) -> Box<dyn StructureExporter>;
const REGISTRY: &[(&str, ExporterFactory)] = &[
("mcfunction", |p| Box::new(McFunctionExporter::new(p))),
("litematica", |p| Box::new(LitematicaExporter::new(p))),
];
pub fn available_names() -> Vec<&'static str> {
REGISTRY.iter().map(|(name, _)| *name).collect()
}
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,
}
REGISTRY.iter()
.find(|(n, _)| *n == name)
.map(|(_, factory)| factory(palette))
}
#[cfg(test)]