Skip to content

Commit

Permalink
Use the background size field NOT the hud size field
Browse files Browse the repository at this point in the history
when deciding how large to draw the background. Headdesk.

Also, rearranged some tests so they're next to the code they're
testing.
  • Loading branch information
ceejbot committed Dec 3, 2023
1 parent c6d0190 commit 279d1d1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 38 deletions.
7 changes: 2 additions & 5 deletions src/layouts/layout_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,9 @@ mod tests {
use super::*;
use crate::layouts::{resolutionHeight, Layout};

/*
#[test]
fn default_layout_valid() {
// The github runner compilation step can't find this file. I have no idea why not.
let buf = include_str!("../../data/SKSE/plugins/SoulsyHUD_layout.toml");
let buf = include_str!("../../data/SKSE/plugins/SoulsyHUD_Layout.toml");
match toml::from_str::<HudLayout2>(buf) {
Ok(v) => {
assert_eq!(v.anchor_point().x, 150.0);
Expand All @@ -313,7 +311,7 @@ mod tests {
.expect("the right slot should have a poison indicator");
assert_eq!(
right_poison.indicator.svg,
"icons/indicator_poison.svg".to_string()
"../icons/indicator_poison.svg".to_string()
);
let _left_poison = v
.left
Expand Down Expand Up @@ -342,7 +340,6 @@ mod tests {
}
}
}
*/

#[test]
fn centered_layout_valid() {
Expand Down
35 changes: 4 additions & 31 deletions src/layouts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ impl Point {
#[cfg(not(test))]
use crate::plugin::{resolutionHeight, resolutionWidth};

// mocked screen resolution numbers, because these functions are provided by
// C++ and require imgui etc.
// Mocked screen resolution numbers, because these functions are provided by
// C++ and require imgui etc. The names come from C++ and are not snake case.
#[cfg(test)]
#[allow(non_snake_case)]
fn resolutionWidth() -> f32 {
Expand Down Expand Up @@ -290,40 +290,13 @@ mod tests {

#[test]
fn default_layout_exists() {
// TODO
let fpath = std::path::Path::new("data/SKSE/plugins/SoulsyHUD_Layout.toml");
assert!(fpath.exists());
}

#[derive(Deserialize, Serialize, Debug, Clone)]
struct TestAnchor {
#[serde(default, deserialize_with = "super::shared::deserialize_named_anchor")]
anchor: NamedAnchor,
}

#[test]
fn deserde_anchor_names() {
let input = r#"anchor = "center""#;
let parsed: TestAnchor = toml::from_str(input).expect("this should be parseable");
assert_eq!(parsed.anchor, NamedAnchor::Center);

let input = r#"anchor = "bottom_center""#;
let parsed: TestAnchor = toml::from_str(input).expect("this should be parseable");
assert_eq!(parsed.anchor, NamedAnchor::CenterBottom);
}

#[test]
fn parses_named_anchors() {
let data = std::fs::read_to_string("layouts/hexagons/SoulsyHUD_hexagons_lr.toml")
.expect("file not found?");
let hexa1: HudLayout1 = toml::from_str(data.as_str()).expect("layout should be valid toml");
assert_eq!(hexa1.anchor_name, NamedAnchor::TopRight);
assert_eq!(hexa1.anchor_point().x, 3290.0);
assert_eq!(hexa1.anchor_point().y, 150.0);

let data = std::fs::read_to_string("layouts/hexagons/SoulsyHUD_hexagons_tb.toml")
.expect("file not found?");
let hexa2: HudLayout1 = toml::from_str(data.as_str()).expect("layout should be valid toml");
assert_eq!(hexa2.anchor_name, NamedAnchor::BottomRight);
assert_eq!(hexa2.anchor_point().x, 3290.0);
assert_eq!(hexa2.anchor_point().y, 1290.0);
}
}
21 changes: 21 additions & 0 deletions src/layouts/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ impl Display for HudElement {

#[cfg(test)]
mod tests {
use crate::layouts::layout_v1;

use super::*;

#[derive(Deserialize, Serialize, Debug, Clone)]
Expand All @@ -180,4 +182,23 @@ mod tests {
let parsed: TestAnchor = toml::from_str(input).expect("this should be parseable");
assert_eq!(parsed.anchor, NamedAnchor::CenterBottom);
}

#[test]
fn parses_named_anchors() {
let data = std::fs::read_to_string("layouts/hexagons/SoulsyHUD_hexagons_lr.toml")
.expect("file not found?");
let hexa1: layout_v1::HudLayout1 =
toml::from_str(data.as_str()).expect("layout should be valid toml");
assert_eq!(hexa1.anchor_name, NamedAnchor::TopRight);
assert_eq!(hexa1.anchor_point().x, 3290.0);
assert_eq!(hexa1.anchor_point().y, 150.0);

let data = std::fs::read_to_string("layouts/hexagons/SoulsyHUD_hexagons_tb.toml")
.expect("file not found?");
let hexa2: layout_v1::HudLayout1 =
toml::from_str(data.as_str()).expect("layout should be valid toml");
assert_eq!(hexa2.anchor_name, NamedAnchor::BottomRight);
assert_eq!(hexa2.anchor_point().x, 3290.0);
assert_eq!(hexa2.anchor_point().y, 1290.0);
}
}
3 changes: 1 addition & 2 deletions src/renderer/ui_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ namespace ui
{
auto topLayout = hud_layout();
auto anchor = topLayout.anchor;
auto hudsize = topLayout.size;
auto hudsize = topLayout.bg_size;
bool rangedEquipped = player::hasRangedEquipped();
const auto settings = user_settings();
const auto screenWidth = resolutionWidth();
Expand Down Expand Up @@ -761,7 +761,6 @@ namespace ui
{
if ((gHudAlpha < 1.0f && !gIsFading) || (gIsFading && !doFadeIn)) { startAlphaTransition(true, 1.0f); }
}

}

float easeInCubic(float progress)
Expand Down

0 comments on commit 279d1d1

Please sign in to comment.