Sprite order for tileset plugin
parent
81a1888f6d
commit
9799226e80
15
src/main.rs
15
src/main.rs
|
@ -27,6 +27,14 @@ fn main() {
|
||||||
.default_value( "bin" )
|
.default_value( "bin" )
|
||||||
.takes_value( true )
|
.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();
|
.get_matches();
|
||||||
|
|
||||||
|
@ -35,7 +43,12 @@ fn main() {
|
||||||
// Get input and output filenames
|
// Get input and output filenames
|
||||||
if let Some( input_filename ) = matches.value_of( "input" ) {
|
if let Some( input_filename ) = matches.value_of( "input" ) {
|
||||||
if let Some( output_filename ) = matches.value_of( "output" ) {
|
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 {
|
} else {
|
||||||
utility::print_error( "expected: output_filename (-o,--output)" );
|
utility::print_error( "expected: output_filename (-o,--output)" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -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() );
|
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 );
|
let img = image::open( image_filename );
|
||||||
if let Ok( img ) = img {
|
if let Ok( img ) = img {
|
||||||
let ( mut max_x, mut max_y ) = img.dimensions();
|
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 palette: [u16; 16] = [ 0; 16 ];
|
||||||
let mut body: Vec< u8 > = Vec::new();
|
let mut body: Vec< u8 > = Vec::new();
|
||||||
|
|
||||||
for y in ( 0..max_y ).step_by( 8 ) {
|
if tile_order == "sprite" {
|
||||||
for x in ( 0..max_x ).step_by( 8 ) {
|
/*
|
||||||
for cell_y in 0..8 {
|
* Tile order:
|
||||||
let mut series: u32 = 0;
|
* 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 {
|
for cell_x in 0..8 {
|
||||||
let nibble: u32 = get_pixel( &img, &mut palette, cell_x + x, cell_y + y ) << ( ( 7 - cell_x ) * 4 );
|
let nibble: u32 = get_pixel( &img, &mut palette, cell_x + x, cell_y + y ) << ( ( 7 - cell_x ) * 4 );
|
||||||
series = series | nibble;
|
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 cell_x in 0..8 {
|
||||||
for i in 0..4 {
|
let nibble: u32 = get_pixel( &img, &mut palette, cell_x + x, cell_y + y ) << ( ( 7 - cell_x ) * 4 );
|
||||||
body.push( bytes[ i ] );
|
series = series | nibble;
|
||||||
|
}
|
||||||
|
|
||||||
|
let bytes = series.to_be_bytes();
|
||||||
|
for i in 0..4 {
|
||||||
|
body.push( bytes[ i ] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue