From 0d0627b223e6db74d5f20ff7fa32bfcc27c8da10 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Mon, 23 Mar 2026 02:30:11 +0100 Subject: [PATCH] feat(exporters): scaffold PngExporter --- crates/exporters/Cargo.toml | 1 + crates/exporters/src/image_export.rs | 22 ++++++++++++++++++++++ crates/exporters/src/lib.rs | 7 +++++++ crates/lib/src/lib.rs | 1 + 4 files changed, 31 insertions(+) create mode 100644 crates/exporters/src/image_export.rs diff --git a/crates/exporters/Cargo.toml b/crates/exporters/Cargo.toml index 41dabdb..32df3a6 100644 --- a/crates/exporters/Cargo.toml +++ b/crates/exporters/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] lib = { path = "../lib" } +image = { version = "0.25", default-features = false, features = ["png"] } fastnbt = "2.6.1" flate2 = "1.1.9" anyhow = { workspace = true } diff --git a/crates/exporters/src/image_export.rs b/crates/exporters/src/image_export.rs new file mode 100644 index 0000000..fec1ea9 --- /dev/null +++ b/crates/exporters/src/image_export.rs @@ -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> { + todo!("png export not yet implemented") + } + + fn file_extension(&self) -> &'static str { + "png" + } +} diff --git a/crates/exporters/src/lib.rs b/crates/exporters/src/lib.rs index c91ce40..1588f27 100644 --- a/crates/exporters/src/lib.rs +++ b/crates/exporters/src/lib.rs @@ -1,8 +1,10 @@ +mod image_export; mod litematica; mod mcfunction; use lib::{BlockPalette, StructureExporter}; +pub use image_export::PngExporter; pub use litematica::LitematicaExporter; pub use mcfunction::McFunctionExporter; @@ -11,12 +13,17 @@ type ExporterFactory = fn(&BlockPalette) -> Box; const REGISTRY: &[(&str, ExporterFactory)] = &[ ("mcfunction", |p| Box::new(McFunctionExporter::new(p))), ("litematica", |p| Box::new(LitematicaExporter::new(p))), + ("png", |p| Box::new(PngExporter::new(p, 16))), ]; pub fn available_names() -> Vec<&'static str> { REGISTRY.iter().map(|(name, _)| *name).collect() } +pub fn build_png(palette: &BlockPalette, cell_size: u32) -> Box { + Box::new(PngExporter::new(palette, cell_size)) +} + pub fn build(name: &str, palette: &BlockPalette) -> Option> { REGISTRY.iter() .find(|(n, _)| *n == name) diff --git a/crates/lib/src/lib.rs b/crates/lib/src/lib.rs index e531707..cf35f28 100644 --- a/crates/lib/src/lib.rs +++ b/crates/lib/src/lib.rs @@ -13,6 +13,7 @@ pub use fonts::ttf_font::TtfFont; pub use grid::VoxelGrid; pub use models::VoxelType; pub use palette::BlockPalette; +pub use palette::PaletteMappings; pub trait StructureExporter { fn export(&self, grid: &VoxelGrid) -> anyhow::Result>;