refactor(exporters): single registry source of truth
This commit is contained in:
@@ -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)]
|
||||||
|
|||||||
Reference in New Issue
Block a user