mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 16:21:33 +11:00
Actually write to a file and also include palette assignments
This commit is contained in:
parent
4daafdec20
commit
d1412fb709
|
@ -6,10 +6,12 @@ fn main() -> () {
|
|||
let args: Vec<_> = env::args().collect();
|
||||
|
||||
let file_path = &args[1];
|
||||
let output_path = &args[2];
|
||||
convert_image(&ImageConverterConfig {
|
||||
transparent_colour: None,
|
||||
tile_size: TileSize::Tile8,
|
||||
input_image: file_path.into(),
|
||||
output_file: "".into(),
|
||||
output_file: output_path.into(),
|
||||
output_name: "HELLO".to_owned(),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::fs::File;
|
||||
use std::io::BufWriter;
|
||||
use std::path::PathBuf;
|
||||
|
||||
mod colour;
|
||||
|
@ -29,6 +31,7 @@ pub struct ImageConverterConfig {
|
|||
pub tile_size: TileSize,
|
||||
pub input_image: PathBuf,
|
||||
pub output_file: PathBuf,
|
||||
pub output_name: String,
|
||||
}
|
||||
|
||||
pub fn convert_image(settings: &ImageConverterConfig) {
|
||||
|
@ -42,16 +45,15 @@ pub fn convert_image(settings: &ImageConverterConfig) {
|
|||
let optimiser = optimiser_for_image(&image, tile_size);
|
||||
let optimisation_results = optimiser.optimise_palettes(settings.transparent_colour);
|
||||
|
||||
let stdout = std::io::stdout();
|
||||
let handle = stdout.lock();
|
||||
let mut writer = std::io::BufWriter::new(handle);
|
||||
let output_file = File::create(&settings.output_file).expect("Failed to create file");
|
||||
let mut writer = BufWriter::new(output_file);
|
||||
|
||||
rust_generator::generate_code(
|
||||
&mut writer,
|
||||
&optimisation_results,
|
||||
&image,
|
||||
settings.tile_size,
|
||||
"HELLO",
|
||||
&settings.output_name,
|
||||
)
|
||||
.expect("Failed to write data");
|
||||
}
|
||||
|
|
|
@ -74,7 +74,22 @@ pub(crate) fn generate_code(
|
|||
}
|
||||
}
|
||||
|
||||
write!(output, "];\n")?;
|
||||
write!(output, "];\n\n")?;
|
||||
|
||||
write!(
|
||||
output,
|
||||
"pub const {}_PALETTE_ASSIGNMENT: &'static [u8] = &[",
|
||||
tile_name
|
||||
)?;
|
||||
|
||||
for (i, assignment) in results.assignments.iter().enumerate() {
|
||||
if i % 16 == 0 {
|
||||
write!(output, "\n ")?;
|
||||
}
|
||||
write!(output, "{}, ", assignment)?;
|
||||
}
|
||||
|
||||
write!(output, "\n];\n")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue