From c09d449902f529db6fe390b22307a237124410de Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 7 Dec 2019 03:16:43 +0100 Subject: add chatlink + revenant legends support --- src/main.rs | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 14 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 9ffa1eb..36d7a21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +extern crate base64; extern crate clap; extern crate image; extern crate imageproc; @@ -20,7 +21,7 @@ mod render; use clap::{App, Arg, ArgMatches}; use api::{Api, Profession, Skill}; -use bt::{BuildTemplate, TraitChoice, Traitline}; +use bt::{BuildTemplate, ExtraData, Legend, TraitChoice, Traitline}; const APP_NAME: &str = "kondou"; @@ -121,14 +122,51 @@ fn run_searching(api: &mut Api, matches: &ArgMatches) -> MainResult>) .unwrap_or_default() .into_iter() - .map(|s| resolve_skill(api, &profession, s)) - .collect::, _>>()?; + .map(str::parse) + .map(Result::unwrap) + .collect::>(); + + let extra_data = if prof_enum == bt::Profession::Revenant { + let mut array_legends = [Legend::None; 4]; + for (i, l) in legends.iter().enumerate() { + array_legends[i] = *l; + } + ExtraData::Legends(array_legends) + } else { + ExtraData::None + }; + + let skills = if prof_enum != bt::Profession::Revenant { + matches + .values_of("skill") + .map(Iterator::collect::>) + .unwrap_or_default() + .into_iter() + .map(|s| resolve_skill(api, &profession, s)) + .collect::, _>>()? + } else { + if let Some(l) = legends.first() { + let l = api.get_legends(&[l.get_api_id().unwrap()])?.remove(0); + let mut result = Vec::new(); + for skill_id in (&[l.heal]).iter().chain(&l.utilities).chain(&[l.elite]) { + let skill = api.get_skills(&[*skill_id])?.remove(0); + result.push(skill); + } + result + } else { + Vec::new() + } + }; let traitlines = matches .values_of("traitline") @@ -144,15 +182,8 @@ fn run_searching(api: &mut Api, matches: &ArgMatches) -> MainResult Result<(), String> { Ok(()) } +fn validate_legend(input: String) -> Result<(), String> { + input + .parse::() + .map(|_| ()) + .map_err(|_| "invalid legend name".to_owned()) +} + fn run() -> MainResult<()> { let matches = App::new(APP_NAME) .version("0.1") @@ -207,6 +245,17 @@ fn run() -> MainResult<()> { .validator(validate_traitline_format) .max_values(bt::TRAITLINE_COUNT as u64), ) + .arg( + Arg::with_name("legend") + .help("Selects a revenant legend.") + .takes_value(true) + .number_of_values(1) + .long("legend") + .short("l") + .multiple(true) + .max_values(bt::LEGEND_COUNT as u64) + .validator(validate_legend), + ) .arg( Arg::with_name("chatlink") .help("Specifies a chat link to parse.") @@ -231,6 +280,8 @@ fn run() -> MainResult<()> { true => unimplemented!(), }; + println!("Chat code: {}", build.chatlink()); + let mut renderer = render::Renderer::new(&mut api, Default::default()); let img = renderer.render_buildtemplate(&build).unwrap(); let filename = matches.value_of("outfile").unwrap(); -- cgit v1.2.3