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 litematica::LitematicaExporter;
pub use mcfunction::McFunctionExporter; pub use mcfunction::McFunctionExporter;
pub fn available_names() -> &'static [&'static str] { type ExporterFactory = fn(&BlockPalette) -> Box<dyn StructureExporter>;
&["mcfunction", "litematica"]
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>> { pub fn build(name: &str, palette: &BlockPalette) -> Option<Box<dyn StructureExporter>> {
match name { REGISTRY.iter()
"mcfunction" => Some(Box::new(McFunctionExporter::new(palette))), .find(|(n, _)| *n == name)
"litematica" => Some(Box::new(LitematicaExporter::new(palette))), .map(|(_, factory)| factory(palette))
_ => None,
}
} }
#[cfg(test)] #[cfg(test)]