Skip to content

Commit

Permalink
[#42] Boots over pants
Browse files Browse the repository at this point in the history
  • Loading branch information
Orchaldir committed Sep 23, 2023
1 parent 331f6b8 commit cb02e97
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
22 changes: 22 additions & 0 deletions rpg_tools_rendering/src/rendering/config/equipment/footwear.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use crate::rendering::config::body::BodyConfig;
use rpg_tools_core::model::character::appearance::body::Body;
use rpg_tools_core::model::equipment::appearance::footwear::FootwearStyle;

/// The rendering config of the [`footwear`](rpg_tools_core::model::equipment::appearance::footwear::Footwear).
#[derive(Debug, PartialEq)]
pub struct FootwearConfig {
Expand All @@ -7,3 +11,21 @@ pub struct FootwearConfig {
pub width_shaft: f32,
pub width_sole: f32,
}

impl FootwearConfig {
pub fn get_shaft_y(
&self,
config: &BodyConfig,
body: &Body,
style: FootwearStyle,
) -> Option<f32> {
match style {
FootwearStyle::KneeHighBoots => Some(self.to_y(config, body, self.height_knee)),
_ => None,
}
}

pub fn to_y(&self, config: &BodyConfig, body: &Body, height: f32) -> f32 {
config.y_foot - height - config.get_foot_radius_factor(body)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ impl PantsConfig {
}

pub fn get_bottom_y(&self, config: &BodyConfig, body: &Body) -> f32 {
1.0 - config.get_foot_radius_factor(body) - self.offset_bottom
config.y_foot - config.get_foot_radius_factor(body) - self.offset_bottom
}
}
2 changes: 1 addition & 1 deletion rpg_tools_rendering/src/rendering/equipment/footwear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn render_shaft(
) {
let width = config.body.get_leg_width(body) * config.footwear.width_shaft;
let y_end = config.body.y_foot;
let y_start = y_end - height - config.body.get_foot_radius_factor(body);
let y_start = config.footwear.to_y(&config.body, body, height);
let mut builder = Polygon2dBuilder::new();

builder.add_horizontal_pair(aabb, width, center_x, y_start, true);
Expand Down
7 changes: 5 additions & 2 deletions rpg_tools_rendering/src/rendering/equipment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ pub fn render_clothing(
render_shirt(renderer, config, aabb, body, shirt, from_front);

if footwear.style.is_over_pants() {
render_pants(renderer, config, aabb, body, pants);
let shaft_y = config
.footwear
.get_shaft_y(&config.body, body, footwear.style);
render_pants(renderer, config, aabb, body, pants, shaft_y);
render_footwear(renderer, config, aabb, body, footwear, from_front);
} else {
render_footwear(renderer, config, aabb, body, footwear, from_front);
render_pants(renderer, config, aabb, body, pants);
render_pants(renderer, config, aabb, body, pants, None);
}
}
}
15 changes: 12 additions & 3 deletions rpg_tools_rendering/src/rendering/equipment/pants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ pub fn render_pants(
aabb: &AABB,
body: &Body,
pants: &Pants,
shaft_y: Option<f32>,
) {
let options = config.get_options(pants.color);
let polygon = match pants.style {
PantsStyle::Balloon => get_balloon(config, aabb, body),
PantsStyle::Bermuda => get_bermuda(config, aabb, body),
PantsStyle::HotPants => get_hot_pants(config, aabb, body),
PantsStyle::Regular => get_regular_pants(config, aabb, body),
PantsStyle::Regular => get_regular_pants(config, aabb, body, shaft_y),
PantsStyle::Shorts => get_shorts(config, aabb, body),
};

Expand All @@ -38,8 +39,16 @@ fn get_hot_pants(config: &RenderConfig, aabb: &AABB, body: &Body) -> Polygon2d {
get_base(config, aabb, body).build()
}

fn get_regular_pants(config: &RenderConfig, aabb: &AABB, body: &Body) -> Polygon2d {
let bottom_y = config.pants.get_bottom_y(&config.body, body);
fn get_regular_pants(
config: &RenderConfig,
aabb: &AABB,
body: &Body,
shaft_y: Option<f32>,
) -> Polygon2d {
let bottom_y = config
.pants
.get_bottom_y(&config.body, body)
.min(shaft_y.unwrap_or(1.0));
get_pants(config, aabb, body, bottom_y, false)
}

Expand Down

0 comments on commit cb02e97

Please sign in to comment.