diff --git a/src/reskit/cli/evaluator.rs b/src/reskit/cli/evaluator.rs index 3688f6a..f11943a 100644 --- a/src/reskit/cli/evaluator.rs +++ b/src/reskit/cli/evaluator.rs @@ -1,6 +1,6 @@ use std::{error::Error, fs::File, io::Write, path::Path}; use clap::Parser; -use crate::reskit::{tileset, soundtrack::{formats::dmf::DmfModule, engines::echo::engine::{EchoFormat, EchoArtifact}}, utility::{print_good, print_error, print_info}, level::converter::get_tiled_tilemap}; +use crate::reskit::{tileset, soundtrack::{formats::dmf::DmfModule, engines::echo::engine::{EchoFormat, EchoArtifact}}, utility::{print_good, print_error, print_info}, level::{converter::get_tiled_tilemap, system::{get_tiles, get_code}}}; use super::settings::{Args, Tools, TileOutputFormat, TileOrder}; pub fn run_command() -> Result<(), Box> { @@ -67,9 +67,21 @@ pub fn run_command() -> Result<(), Box> { } Tools::Level { input_file, output_directory, console, tile_size } => { let tiled_file = get_tiled_tilemap( &input_file )?; - //print_info( &format!( "{:#?}", tiled_file ) ); - print_good( "file opened without errors" ); - print_error( "unimplemented" ); + + // Get tile and palette files + let ( all_tiles, palettes ) = get_tiles( &tiled_file )?; + + let mut tiles_bin = File::create( format!( "{}tiles.bin", output_directory ) )?; + tiles_bin.write_all( &all_tiles )?; + print_good( "exported tiles.bin" ); + + let mut palettes_bin = File::create( format!( "{}palettes.pal", output_directory ) )?; + palettes_bin.write_all( &palettes )?; + print_good( "exported palettes.pal" ); + + let mut code_asm = File::create( format!( "{}level.asm", output_directory ) )?; + code_asm.write_all( &get_code( "testlevel", "levels/" )?.as_bytes() )?; + print_good( "exported level.asm" ); } }; diff --git a/src/reskit/level/system.rs b/src/reskit/level/system.rs index 927c99e..0ef7981 100644 --- a/src/reskit/level/system.rs +++ b/src/reskit/level/system.rs @@ -1,6 +1,6 @@ use std::{error::Error, convert::TryInto}; use image::GenericImageView; -use crate::reskit::tileset::image_to_tiles; +use crate::reskit::{tileset::image_to_tiles, utility::symbol_to_pascal}; use super::converter::{TiledTilemap, Layer, SystemPlane}; /** @@ -163,4 +163,24 @@ pub fn get_collision_map( tilemap: &TiledTilemap ) -> Result, Box Result> { + let version = env!( "CARGO_PKG_VERSION" ); + let level_label = symbol_to_pascal( level_name ); + let file = format!( r#"; Level definition file +; Generated by reskit v{version} + +{level_label}Tiles: + incbin '{path_prefix}{level_name}/tiles.bin' + +{level_label}Palettes: + incbin '{path_prefix}{level_name}/palettes.pal' + + "# ); + + Ok( file ) } \ No newline at end of file