Initial level export functionality
parent
c62573e1ed
commit
de5868305d
|
@ -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<dyn Error>> {
|
||||
|
@ -67,9 +67,21 @@ pub fn run_command() -> Result<(), Box<dyn Error>> {
|
|||
}
|
||||
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" );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
||||
/**
|
||||
|
@ -164,3 +164,23 @@ pub fn get_collision_map( tilemap: &TiledTilemap ) -> Result<Vec<u8>, Box<dyn Er
|
|||
|
||||
Ok( result )
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>> {
|
||||
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 )
|
||||
}
|
Loading…
Reference in New Issue