master
ne0ndrag0n 2021-02-12 22:12:52 -05:00
parent bd8c217adc
commit 5ccb569b9e
5 changed files with 48 additions and 54 deletions

View File

@ -9,3 +9,4 @@ edition = "2018"
[dependencies] [dependencies]
image = "^0.23" image = "^0.23"
colour = "^0.5" colour = "^0.5"
clap = "^2.33"

View File

@ -1,62 +1,40 @@
extern crate image; extern crate image;
extern crate clap;
#[macro_use] #[macro_use]
extern crate colour; extern crate colour;
use std::env::{ Args, args }; use clap::{App, SubCommand};
use std::process::exit;
mod reskit; mod reskit;
use reskit::utility;
use reskit::tileset; use reskit::tileset;
struct ArgumentOption {
pub key: String,
pub value: String
}
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
}
}
}
fn main() { fn main() {
cyan!( "reskit" ); println!( " - Sega Genesis Resource Kit (v0.0.1a)" ); let matches = App::new( "reskit" )
println!( "(c) 2021 Ashley N. (ne0ndrag0n)" ); .version( "0.0.1a" )
.author( "(c) 2021 Ashley N. <ne0ndrag0n@ne0ndrag0n.com>" )
.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=<FILE> 'Specify input image'" )
.arg_from_usage( "-o, --output=<FILE> 'Specify output file'")
)
.get_matches();
let mut args = args(); // Get arguments for tileset
args.next(); // Burn arg1 if let Some( matches ) = matches.subcommand_matches( "tileset" ) {
// Get input and output filenames
let mode = match args.next() { if let Some( input_filename ) = matches.value_of( "input" ) {
Some( mode ) => mode, if let Some( output_filename ) = matches.value_of( "output" ) {
None => { return tileset::generate( input_filename, output_filename );
print_help(); } else {
exit( 1 ); utility::print_error( "expected: output_filename (-o,--output)" );
} }
}; } else {
utility::print_error( "expected: input filename (-i,--input)" );
exit( load_module( mode, args ) ); }
}
utility::print_error( "no plugin provided (try --help)" );
} }

View File

@ -1 +1,2 @@
pub mod tileset; pub mod tileset;
pub mod utility;

View File

@ -1,3 +1,14 @@
pub fn load_tileset() -> i32 { use crate::reskit::utility;
3 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 {
}
} }

3
src/reskit/utility.rs Normal file
View File

@ -0,0 +1,3 @@
pub fn print_error( error_msg: &'static str ) {
red!( "fatal: " ); println!( "{}", error_msg );
}