Pass through a crate prefix

This commit is contained in:
Gwilym Kuiper 2021-06-05 17:47:13 +01:00
parent c6b1c4b824
commit 4516c8dfc0
2 changed files with 12 additions and 2 deletions

View file

@ -35,6 +35,9 @@ pub struct ImageConverterConfig {
tile_size: TileSize,
input_image: PathBuf,
output_file: PathBuf,
#[builder(default, setter(strip_option))]
crate_prefix: Option<String>,
}
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");
}

View file

@ -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())?;