From 5ccb569b9e13d222836b786cce76795548f094dd Mon Sep 17 00:00:00 2001 From: ne0ndrag0n Date: Fri, 12 Feb 2021 22:12:52 -0500 Subject: [PATCH] stuff --- Cargo.toml | 3 +- src/main.rs | 78 ++++++++++++++++--------------------------- src/reskit/mod.rs | 3 +- src/reskit/tileset.rs | 15 +++++++-- src/reskit/utility.rs | 3 ++ 5 files changed, 48 insertions(+), 54 deletions(-) create mode 100644 src/reskit/utility.rs diff --git a/Cargo.toml b/Cargo.toml index fab5a24..9fdcc42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ edition = "2018" [dependencies] image = "^0.23" -colour = "^0.5" \ No newline at end of file +colour = "^0.5" +clap = "^2.33" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 1074e7f..f81422b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,62 +1,40 @@ extern crate image; +extern crate clap; #[macro_use] extern crate colour; -use std::env::{ Args, args }; -use std::process::exit; +use clap::{App, SubCommand}; mod reskit; +use reskit::utility; use reskit::tileset; -struct ArgumentOption { - pub key: String, - pub value: String -} +fn main() { + let matches = App::new( "reskit" ) + .version( "0.0.1a" ) + .author( "(c) 2021 Ashley N. " ) + .about( "Sega Megadrive resource kit and format converter" ) + .subcommand( + SubCommand::with_name( "tileset" ) + .about( "Generate a Sega Megadrive VDP tileset + palette from a 15-colour image" ) + .arg_from_usage( "-i, --input= 'Specify input image'" ) + .arg_from_usage( "-o, --output= 'Specify output file'") + ) + .get_matches(); -fn print_help() { - println!( "Usage:" ); - println!( "reskit [plugin] options" ); - println!( "" ); - println!( "Available Plugins:" ); - println!( " tileset - Convert 15-colour PNG to Sega Genesis VDP format" ); - println!( " Output as .bin containing palette, then tiles"); - println!( "" ); - println!( "Options:" ); - println!( "--input Specify input file for plugin" ); - println!( "--output Specify output file/path for plugin" ); -} - -fn get_option( arguments: &mut Args ) -> Option< ArgumentOption > { - Some( ArgumentOption{ key: arguments.next()?, value: arguments.next()? } ) -} - -fn load_module( module: String, arguments: Args ) -> i32 { - // Discriminate module - match module.as_str() { - "reskit" => { - 42 - }, - _ => { - red!( "fatal: " ); println!( "invalid module: {}", module ); - 2 + // Get arguments for tileset + if let Some( matches ) = matches.subcommand_matches( "tileset" ) { + // 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 ); + } else { + utility::print_error( "expected: output_filename (-o,--output)" ); + } + } else { + utility::print_error( "expected: input filename (-i,--input)" ); } } -} - -fn main() { - cyan!( "reskit" ); println!( " - Sega Genesis Resource Kit (v0.0.1a)" ); - println!( "(c) 2021 Ashley N. (ne0ndrag0n)" ); - - let mut args = args(); - args.next(); // Burn arg1 - - let mode = match args.next() { - Some( mode ) => mode, - None => { - print_help(); - exit( 1 ); - } - }; - - exit( load_module( mode, args ) ); + + utility::print_error( "no plugin provided (try --help)" ); } diff --git a/src/reskit/mod.rs b/src/reskit/mod.rs index ca8ca15..fcabdd3 100644 --- a/src/reskit/mod.rs +++ b/src/reskit/mod.rs @@ -1 +1,2 @@ -pub mod tileset; \ No newline at end of file +pub mod tileset; +pub mod utility; \ No newline at end of file diff --git a/src/reskit/tileset.rs b/src/reskit/tileset.rs index eec8c0a..c4237ee 100644 --- a/src/reskit/tileset.rs +++ b/src/reskit/tileset.rs @@ -1,3 +1,14 @@ -pub fn load_tileset() -> i32 { - 3 +use crate::reskit::utility; +use image::GenericImageView; + +pub fn generate( image_filename: &str, output_filename: &str ) { + let img = image::open( image_filename ); + if let Ok( img ) = img { + // Image must be multiple of 8 in both dimensions + let x = img.dimensions().0; + let y = img.dimensions().1; + + } else { + + } } \ No newline at end of file diff --git a/src/reskit/utility.rs b/src/reskit/utility.rs new file mode 100644 index 0000000..a24b593 --- /dev/null +++ b/src/reskit/utility.rs @@ -0,0 +1,3 @@ +pub fn print_error( error_msg: &'static str ) { + red!( "fatal: " ); println!( "{}", error_msg ); +} \ No newline at end of file