From 517b014fffe70c2107965dd6b0e976b610e817e3 Mon Sep 17 00:00:00 2001 From: Orchaldir Date: Wed, 1 Nov 2023 20:07:53 +0100 Subject: [PATCH] [#46] Fix bridge --- resources/characters/characters.yaml | 2 +- .../src/rendering/config/equipment/eyewear.rs | 7 +++---- .../src/rendering/config/example.rs | 4 ++-- .../src/rendering/equipment/eyewear.rs | 15 +++++++-------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/resources/characters/characters.yaml b/resources/characters/characters.yaml index a1629cf7..32513dc0 100644 --- a/resources/characters/characters.yaml +++ b/resources/characters/characters.yaml @@ -51,7 +51,7 @@ type: Glasses style: frame_color: Black - frame_type: Wire + frame_type: FullRimmed lens_color: Aqua lens_shape: Oval lens_transparency: High diff --git a/rpg_tools_rendering/src/rendering/config/equipment/eyewear.rs b/rpg_tools_rendering/src/rendering/config/equipment/eyewear.rs index 5ed0b2c0..20236590 100644 --- a/rpg_tools_rendering/src/rendering/config/equipment/eyewear.rs +++ b/rpg_tools_rendering/src/rendering/config/equipment/eyewear.rs @@ -20,12 +20,11 @@ impl EyewearConfig { (radius_x as f32 * self.radius_y_factor) as u32 } - pub fn get_bridge_height(&self, width: u32, frame_type: FrameType) -> u32 { - let thickness = match frame_type { + pub fn get_bridge_thickness(&self, frame_type: FrameType) -> f32 { + match frame_type { FrameType::Rimless => self.thickness_wire, _ => self.get_frame_thickness(frame_type), - }; - (width as f32 * self.bridge_factor * thickness) as u32 + } } pub fn get_frame_thickness(&self, frame_type: FrameType) -> f32 { diff --git a/rpg_tools_rendering/src/rendering/config/example.rs b/rpg_tools_rendering/src/rendering/config/example.rs index 555fa58e..835ad852 100644 --- a/rpg_tools_rendering/src/rendering/config/example.rs +++ b/rpg_tools_rendering/src/rendering/config/example.rs @@ -147,8 +147,8 @@ pub fn create_config() -> RenderConfig { bridge_factor: 0.1, radius_factor: 1.4, radius_y_factor: 0.8, - thickness_horn: 5.0, - thickness_rimmed: 3.0, + thickness_horn: 3.0, + thickness_rimmed: 2.0, thickness_wire: 1.0, }, footwear: FootwearConfig { diff --git a/rpg_tools_rendering/src/rendering/equipment/eyewear.rs b/rpg_tools_rendering/src/rendering/equipment/eyewear.rs index 110ff97d..43cddf1f 100644 --- a/rpg_tools_rendering/src/rendering/equipment/eyewear.rs +++ b/rpg_tools_rendering/src/rendering/equipment/eyewear.rs @@ -1,12 +1,10 @@ use crate::math::aabb2d::AABB; use crate::math::point2d::Point2d; -use crate::math::size2d::Size2d; use crate::renderer::color::WebColor; use crate::renderer::{RenderOptions, Renderer}; use crate::rendering::config::RenderConfig; use rpg_tools_core::model::equipment::appearance::eyewear::{Eyewear, LensShape, LensStyle}; use rpg_tools_core::model::side::Side; -use std::ops::{Add, Div}; pub fn render_eyewear( renderer: &mut dyn Renderer, @@ -49,13 +47,14 @@ fn render_bridge( right: &Point2d, radius: u32, ) { - let width = left.calculate_distance(right) as u32 - 2 * radius; - let height = config.eyewear.get_bridge_height(width, style.frame_type); - let center = left.add(*right).div(2.0); - let aabb = AABB::with_center(center, Size2d::new(width, height)); - let options = RenderOptions::no_line(WebColor::from_color(style.frame_color)); + let options = config.line_with_color( + style.frame_color, + config.eyewear.get_bridge_thickness(style.frame_type), + ); + let start = Point2d::new(left.x + radius as i32, left.y); + let end = Point2d::new(right.x - radius as i32, right.y); - renderer.render_rectangle(&aabb, &options); + renderer.render_line(&(start, end).into(), &options); } fn render_lens(