Sprite order for tileset plugin

master
Ashley N. 2023-08-09 22:00:48 -04:00
parent 81a1888f6d
commit 9799226e80
2 changed files with 55 additions and 12 deletions

View File

@ -27,6 +27,14 @@ fn main() {
.default_value( "bin" )
.takes_value( true )
)
.arg(
Arg::with_name( "TILEORDER" )
.short( "to" )
.long( "tile-order" )
.help( "Specify tile order for tileset (valid TILEORDER options: tile, sprite" )
.default_value( "tile" )
.takes_value( true )
)
)
.get_matches();
@ -35,7 +43,12 @@ fn main() {
// Get input and output filenames
if let Some( input_filename ) = matches.value_of( "input" ) {
if let Some( output_filename ) = matches.value_of( "output" ) {
return tileset::generate( input_filename, output_filename, matches.value_of( "FORMAT" ).unwrap() );
return tileset::generate(
input_filename,
output_filename,
matches.value_of( "FORMAT" ).unwrap(),
matches.value_of( "TILEORDER" ).unwrap()
);
} else {
utility::print_error( "expected: output_filename (-o,--output)" );
}

View File

@ -114,7 +114,7 @@ fn output_inc( image_filename: &str, output_filename: &str, palette: [u16; 16],
utility::print_good( format!( "converted file {}", image_filename ).as_str() );
}
pub fn generate( image_filename: &str, output_filename: &str, output_mode: &str ) {
pub fn generate( image_filename: &str, output_filename: &str, output_mode: &str, tile_order: &str ) {
let img = image::open( image_filename );
if let Ok( img ) = img {
let ( mut max_x, mut max_y ) = img.dimensions();
@ -124,19 +124,49 @@ pub fn generate( image_filename: &str, output_filename: &str, output_mode: &str
let mut palette: [u16; 16] = [ 0; 16 ];
let mut body: Vec< u8 > = Vec::new();
for y in ( 0..max_y ).step_by( 8 ) {
for x in ( 0..max_x ).step_by( 8 ) {
for cell_y in 0..8 {
let mut series: u32 = 0;
if tile_order == "sprite" {
/*
* Tile order:
* 1 3
* 2 4
*/
for x in ( 0..max_x ).step_by( 8 ) {
for y in ( 0..max_y ).step_by( 8 ) {
for cell_y in 0..8 {
let mut series: u32 = 0;
for cell_x in 0..8 {
let nibble: u32 = get_pixel( &img, &mut palette, cell_x + x, cell_y + y ) << ( ( 7 - cell_x ) * 4 );
series = series | nibble;
for cell_x in 0..8 {
let nibble: u32 = get_pixel( &img, &mut palette, cell_x + x, cell_y + y ) << ( ( 7 - cell_x ) * 4 );
series = series | nibble;
}
let bytes = series.to_be_bytes();
for i in 0..4 {
body.push( bytes[ i ] );
}
}
}
}
} else {
/*
* Tile order:
* 1 2
* 3 4
*/
for y in ( 0..max_y ).step_by( 8 ) {
for x in ( 0..max_x ).step_by( 8 ) {
for cell_y in 0..8 {
let mut series: u32 = 0;
let bytes = series.to_be_bytes();
for i in 0..4 {
body.push( bytes[ i ] );
for cell_x in 0..8 {
let nibble: u32 = get_pixel( &img, &mut palette, cell_x + x, cell_y + y ) << ( ( 7 - cell_x ) * 4 );
series = series | nibble;
}
let bytes = series.to_be_bytes();
for i in 0..4 {
body.push( bytes[ i ] );
}
}
}
}