From 4516c8dfc05deb0b71c303bad46d9ea5476a3fec Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sat, 5 Jun 2021 17:47:13 +0100 Subject: [PATCH] Pass through a crate prefix --- agb-image-converter/src/lib.rs | 4 ++++ agb-image-converter/src/rust_generator.rs | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index 3cc0d6c5..e13ce861 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -35,6 +35,9 @@ pub struct ImageConverterConfig { tile_size: TileSize, input_image: PathBuf, output_file: PathBuf, + + #[builder(default, setter(strip_option))] + crate_prefix: Option, } pub fn convert_image(settings: ImageConverterConfig) { @@ -56,6 +59,7 @@ pub fn convert_image(settings: ImageConverterConfig) { &optimisation_results, &image, settings.tile_size, + settings.crate_prefix.unwrap_or("agb".to_owned()), ) .expect("Failed to write data"); } diff --git a/agb-image-converter/src/rust_generator.rs b/agb-image-converter/src/rust_generator.rs index d6f42469..27c49021 100644 --- a/agb-image-converter/src/rust_generator.rs +++ b/agb-image-converter/src/rust_generator.rs @@ -10,14 +10,20 @@ pub(crate) fn generate_code( results: &Palette16OptimisationResults, image: &Image, tile_size: TileSize, + crate_prefix: String, ) -> io::Result<()> { writeln!( output, - "pub const PALETTE_DATA: &[crate::display::palette16::Palette16] = &[", + "pub const PALETTE_DATA: &[{}::display::palette16::Palette16] = &[", + crate_prefix, )?; for palette in &results.optimised_palettes { - write!(output, " crate::display::palette16::Palette16::new([")?; + write!( + output, + " {}::display::palette16::Palette16::new([", + crate_prefix + )?; for colour in palette.clone() { write!(output, "0x{:08x}, ", colour.to_rgb15())?;