Export levels with width, height, and number of tiles

stinkhead7ds
Ashley N. 2023-09-17 22:48:50 -04:00
parent de5868305d
commit 62a762515d
3 changed files with 10 additions and 9 deletions

View File

@ -65,7 +65,7 @@ pub fn run_command() -> Result<(), Box<dyn Error>> {
print_good( "all files converted successfully" ); print_good( "all files converted successfully" );
} }
Tools::Level { input_file, output_directory, console, tile_size } => { Tools::Level { input_file, output_directory, console: _ } => {
let tiled_file = get_tiled_tilemap( &input_file )?; let tiled_file = get_tiled_tilemap( &input_file )?;
// Get tile and palette files // Get tile and palette files
@ -80,7 +80,7 @@ pub fn run_command() -> Result<(), Box<dyn Error>> {
print_good( "exported palettes.pal" ); print_good( "exported palettes.pal" );
let mut code_asm = File::create( format!( "{}level.asm", output_directory ) )?; let mut code_asm = File::create( format!( "{}level.asm", output_directory ) )?;
code_asm.write_all( &get_code( "testlevel", "levels/" )?.as_bytes() )?; code_asm.write_all( &get_code( &tiled_file, "testlevel", "levels/" )?.as_bytes() )?;
print_good( "exported level.asm" ); print_good( "exported level.asm" );
} }
}; };

View File

@ -111,10 +111,6 @@ pub enum Tools {
/// Console system type /// Console system type
#[arg(short, long, value_enum, default_value_t=SystemType::Md)] #[arg(short, long, value_enum, default_value_t=SystemType::Md)]
console: SystemType, console: SystemType
/// Tile Size ("WxH" format)
#[arg(long, default_value_t=String::from( "2x2" ))]
tile_size: String
} }
} }

View File

@ -168,9 +168,11 @@ pub fn get_collision_map( tilemap: &TiledTilemap ) -> Result<Vec<u8>, Box<dyn Er
/** /**
* Get a helper .asm or .c file that ties all the level components together * Get a helper .asm or .c file that ties all the level components together
*/ */
pub fn get_code( level_name: &str, path_prefix: &str ) -> Result<String, Box<dyn Error>> { pub fn get_code( tilemap: &TiledTilemap, level_name: &str, path_prefix: &str ) -> Result<String, Box<dyn Error>> {
let version = env!( "CARGO_PKG_VERSION" ); let version = env!( "CARGO_PKG_VERSION" );
let level_label = symbol_to_pascal( level_name ); let level_label = symbol_to_pascal( level_name );
let ( width, height ) = ( tilemap.width, tilemap.height );
let num_tiles = ( tilemap.tileset.image.width() / 8 ) * ( tilemap.tileset.image.height() / 8 ); // --system md
let file = format!( r#"; Level definition file let file = format!( r#"; Level definition file
; Generated by reskit v{version} ; Generated by reskit v{version}
@ -180,7 +182,10 @@ pub fn get_code( level_name: &str, path_prefix: &str ) -> Result<String, Box<dyn
{level_label}Palettes: {level_label}Palettes:
incbin '{path_prefix}{level_name}/palettes.pal' incbin '{path_prefix}{level_name}/palettes.pal'
"# ); {level_label}:
dc.w {width}, {height}, {num_tiles}
dc.l {level_label}Tiles
dc.l {level_label}Palettes"# );
Ok( file ) Ok( file )
} }