feat(exporters): scaffold PngExporter
This commit is contained in:
@@ -5,6 +5,7 @@ edition = "2024"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lib = { path = "../lib" }
|
lib = { path = "../lib" }
|
||||||
|
image = { version = "0.25", default-features = false, features = ["png"] }
|
||||||
fastnbt = "2.6.1"
|
fastnbt = "2.6.1"
|
||||||
flate2 = "1.1.9"
|
flate2 = "1.1.9"
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
|
|||||||
22
crates/exporters/src/image_export.rs
Normal file
22
crates/exporters/src/image_export.rs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
use lib::{BlockPalette, StructureExporter, VoxelGrid, VoxelType};
|
||||||
|
|
||||||
|
pub struct PngExporter {
|
||||||
|
palette: BlockPalette,
|
||||||
|
cell_size: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PngExporter {
|
||||||
|
pub fn new(palette: &BlockPalette, cell_size: u32) -> Self {
|
||||||
|
Self { palette: palette.clone(), cell_size }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StructureExporter for PngExporter {
|
||||||
|
fn export(&self, _grid: &VoxelGrid) -> anyhow::Result<Vec<u8>> {
|
||||||
|
todo!("png export not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn file_extension(&self) -> &'static str {
|
||||||
|
"png"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
|
mod image_export;
|
||||||
mod litematica;
|
mod litematica;
|
||||||
mod mcfunction;
|
mod mcfunction;
|
||||||
|
|
||||||
use lib::{BlockPalette, StructureExporter};
|
use lib::{BlockPalette, StructureExporter};
|
||||||
|
|
||||||
|
pub use image_export::PngExporter;
|
||||||
pub use litematica::LitematicaExporter;
|
pub use litematica::LitematicaExporter;
|
||||||
pub use mcfunction::McFunctionExporter;
|
pub use mcfunction::McFunctionExporter;
|
||||||
|
|
||||||
@@ -11,12 +13,17 @@ type ExporterFactory = fn(&BlockPalette) -> Box<dyn StructureExporter>;
|
|||||||
const REGISTRY: &[(&str, ExporterFactory)] = &[
|
const REGISTRY: &[(&str, ExporterFactory)] = &[
|
||||||
("mcfunction", |p| Box::new(McFunctionExporter::new(p))),
|
("mcfunction", |p| Box::new(McFunctionExporter::new(p))),
|
||||||
("litematica", |p| Box::new(LitematicaExporter::new(p))),
|
("litematica", |p| Box::new(LitematicaExporter::new(p))),
|
||||||
|
("png", |p| Box::new(PngExporter::new(p, 16))),
|
||||||
];
|
];
|
||||||
|
|
||||||
pub fn available_names() -> Vec<&'static str> {
|
pub fn available_names() -> Vec<&'static str> {
|
||||||
REGISTRY.iter().map(|(name, _)| *name).collect()
|
REGISTRY.iter().map(|(name, _)| *name).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn build_png(palette: &BlockPalette, cell_size: u32) -> Box<dyn StructureExporter> {
|
||||||
|
Box::new(PngExporter::new(palette, cell_size))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build(name: &str, palette: &BlockPalette) -> Option<Box<dyn StructureExporter>> {
|
pub fn build(name: &str, palette: &BlockPalette) -> Option<Box<dyn StructureExporter>> {
|
||||||
REGISTRY.iter()
|
REGISTRY.iter()
|
||||||
.find(|(n, _)| *n == name)
|
.find(|(n, _)| *n == name)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ pub use fonts::ttf_font::TtfFont;
|
|||||||
pub use grid::VoxelGrid;
|
pub use grid::VoxelGrid;
|
||||||
pub use models::VoxelType;
|
pub use models::VoxelType;
|
||||||
pub use palette::BlockPalette;
|
pub use palette::BlockPalette;
|
||||||
|
pub use palette::PaletteMappings;
|
||||||
|
|
||||||
pub trait StructureExporter {
|
pub trait StructureExporter {
|
||||||
fn export(&self, grid: &VoxelGrid) -> anyhow::Result<Vec<u8>>;
|
fn export(&self, grid: &VoxelGrid) -> anyhow::Result<Vec<u8>>;
|
||||||
|
|||||||
Reference in New Issue
Block a user