diff options
-rw-r--r-- | src/api/legends.rs | 1 | ||||
-rw-r--r-- | src/render.rs | 42 | ||||
-rw-r--r-- | src/useropts.rs | 4 |
3 files changed, 44 insertions, 3 deletions
diff --git a/src/api/legends.rs b/src/api/legends.rs index 395d6b9..0c9304c 100644 --- a/src/api/legends.rs +++ b/src/api/legends.rs @@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize}; pub struct Legend { /// The legend id. pub id: String, + pub swap: u32, pub heal: u32, pub elite: u32, pub utilities: Vec<u32>, diff --git a/src/render.rs b/src/render.rs index 5c091d1..0a10eab 100644 --- a/src/render.rs +++ b/src/render.rs @@ -1,5 +1,5 @@ use super::api::{Api, ApiError, Skill, Specialization, Trait}; -use super::bt::{BuildTemplate, TraitChoice, Traitline}; +use super::bt::{self, BuildTemplate, ExtraData, TraitChoice, Traitline}; use image::{ imageops, imageops::FilterType::CatmullRom, DynamicImage, GenericImage, GenericImageView, ImageBuffer, Pixel, Primitive, Rgba, RgbaImage, @@ -46,6 +46,8 @@ pub struct RenderOptions { pub render_specialization_names: bool, pub skill_offset: u32, pub skill_alignment: Alignment, + pub legend_size: u32, + pub legend_alignment: Alignment, pub specialization_name_alignment: Alignment, } @@ -70,6 +72,8 @@ impl Default for RenderOptions { render_specialization_names: true, skill_offset: 30, skill_alignment: Alignment::Center, + legend_size: 130, + legend_alignment: Alignment::Center, specialization_name_alignment: Alignment::Left, } } @@ -147,6 +151,34 @@ impl<'r> Renderer<'r> { Ok(buffer) } + pub fn render_legends(&mut self, legends: &[bt::Legend]) -> Result<RgbaImage, RenderError> { + let legend_ids = legends + .iter() + .filter_map(|l| l.api_id()) + .collect::<Vec<_>>(); + let api_legends = self.api.get_legends(&legend_ids)?; + let mut buffer = ImageBuffer::from_pixel( + api_legends.len() as u32 * self.options.legend_size, + self.options.legend_size, + self.options.background_color, + ); + for (i, legend) in api_legends.iter().enumerate() { + let swapper = self + .api + .get_skills(&[legend.swap])? + .into_iter() + .next() + .unwrap(); + let img = self.api.get_image(&swapper.icon)?.resize( + self.options.legend_size, + self.options.legend_size, + CatmullRom, + ); + buffer.copy_from(&img, i as u32 * self.options.legend_size, 0)?; + } + Ok(buffer) + } + fn render_minor_trait( &mut self, buffer: &mut RgbaImage, @@ -337,7 +369,8 @@ impl<'r> Renderer<'r> { images.push((Alignment::Left, inner)); } - let needs_space = build.skill_count() > 0 && build.traitline_count() > 0; + let is_rev = matches!(build.extra_data(), ExtraData::Legends(_)); + let needs_space = (is_rev || build.skill_count() > 0) && build.traitline_count() > 0; if needs_space { let separator = ImageBuffer::from_pixel( self.options.traitline_width, @@ -347,7 +380,10 @@ impl<'r> Renderer<'r> { images.push((Alignment::Left, separator)); } - if build.skill_count() > 0 { + if let ExtraData::Legends(legends) = build.extra_data() { + let rendered_legends = self.render_legends(legends.as_slice())?; + images.push((self.options.skill_alignment, rendered_legends)); + } else if build.skill_count() > 0 { let skills = self.render_skills(build.skills())?; images.push((self.options.skill_alignment, skills)); } diff --git a/src/useropts.rs b/src/useropts.rs index 2e38f05..413fe03 100644 --- a/src/useropts.rs +++ b/src/useropts.rs @@ -62,6 +62,8 @@ pub struct UserOptions { pub render_specialization_names: Option<bool>, pub skill_offset: Option<u32>, pub skill_alignment: Option<Alignment>, + pub legend_size: Option<u32>, + pub legend_alignment: Option<Alignment>, pub specialization_name_alignment: Option<Alignment>, } @@ -103,6 +105,8 @@ impl UserOptions { skill_offset, skill_alignment, specialization_name_alignment, + legend_size, + legend_alignment, } Ok(result) |