diff options
Diffstat (limited to 'src/render.rs')
-rw-r--r-- | src/render.rs | 42 |
1 files changed, 39 insertions, 3 deletions
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)); } |