aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs79
1 files changed, 65 insertions, 14 deletions
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<BuildTemplat
.expect("clap handles missing argument");
let profession = find_profession(api, requested_profession)?;
+ let prof_enum = profession
+ .name
+ .parse()
+ .expect("Profession object has unparseable name");
- let skills = matches
- .values_of("skill")
+ let legends = matches
+ .values_of("legend")
.map(Iterator::collect::<Vec<_>>)
.unwrap_or_default()
.into_iter()
- .map(|s| resolve_skill(api, &profession, s))
- .collect::<Result<Vec<_>, _>>()?;
+ .map(str::parse)
+ .map(Result::unwrap)
+ .collect::<Vec<_>>();
+
+ 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::<Vec<_>>)
+ .unwrap_or_default()
+ .into_iter()
+ .map(|s| resolve_skill(api, &profession, s))
+ .collect::<Result<Vec<_>, _>>()?
+ } 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<BuildTemplat
"got too many traitlines"
);
- let build = BuildTemplate::new(
- profession
- .name
- .parse()
- .expect("Profession object has unparseable name"),
- &skills,
- &traitlines,
- )
- .expect("BuildTemplate could not be constructed");
+ let build = BuildTemplate::new(prof_enum, &skills, &traitlines, extra_data)
+ .expect("BuildTemplate could not be constructed");
Ok(build)
}
@@ -176,6 +207,13 @@ fn validate_traitline_format(input: String) -> Result<(), String> {
Ok(())
}
+fn validate_legend(input: String) -> Result<(), String> {
+ input
+ .parse::<Legend>()
+ .map(|_| ())
+ .map_err(|_| "invalid legend name".to_owned())
+}
+
fn run() -> MainResult<()> {
let matches = App::new(APP_NAME)
.version("0.1")
@@ -208,6 +246,17 @@ fn run() -> MainResult<()> {
.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.")
.short("c")
@@ -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();