Promote shipped IMB profile fields

This commit is contained in:
Jan Petykiewicz 2026-04-21 23:11:22 -07:00
commit d45a84038e
3 changed files with 51 additions and 6 deletions

View file

@ -25,8 +25,10 @@ pub struct ImbInspectionReport {
pub target_screen_width: Option<i64>,
pub target_screen_height: Option<i64>,
pub scaleable: Option<bool>,
pub horizontal_scale_modifier: Option<f64>,
pub max_percent_of_interface_vram: Option<f64>,
pub image_rect: Option<[i64; 4]>,
pub image_rect_scaled: Option<[i64; 4]>,
pub notes: Vec<String>,
pub entries: Vec<ImbInspectionEntry>,
pub malformed_lines: Vec<String>,
@ -78,8 +80,10 @@ pub fn inspect_imb_bytes(bytes: &[u8]) -> Result<ImbInspectionReport, Box<dyn st
let target_screen_width = find_scalar_i64(&entries, "TGATargetScreenWidth");
let target_screen_height = find_scalar_i64(&entries, "TGATargetScreenHeight");
let scaleable = find_scalar_i64(&entries, "Scaleable").map(|value| value != 0);
let horizontal_scale_modifier = find_scalar_f64(&entries, "HorizontalScaleModifier");
let max_percent_of_interface_vram = find_scalar_f64(&entries, "MaxPercentOfInterfaceVRAM");
let image_rect = find_i64_quad(&entries, "ImageWH");
let image_rect_scaled = find_i64_quad(&entries, "ImageWHScaled");
Ok(ImbInspectionReport {
line_count: text.lines().count(),
@ -92,12 +96,14 @@ pub fn inspect_imb_bytes(bytes: &[u8]) -> Result<ImbInspectionReport, Box<dyn st
target_screen_width,
target_screen_height,
scaleable,
horizontal_scale_modifier,
max_percent_of_interface_vram,
image_rect,
image_rect_scaled,
notes: vec![
"The current .imb parser preserves one whitespace-delimited key plus the remaining token list per line.".to_string(),
"Integer and float projections are only populated when every token in the value lane parses cleanly.".to_string(),
"Known profile-style keys such as `TGAName`, `TGAWidth`, `TGAHeight`, `TGATargetScreenWidth`, `TGATargetScreenHeight`, `Scaleable`, `MaxPercentOfInterfaceVRAM`, and `ImageWH` are promoted into typed report fields when present.".to_string(),
"Integer and float projections stop at an inline semicolon comment token, so shipped comment-suffixed numeric rows still decode into typed values.".to_string(),
"Known profile-style keys such as `TGAName`, `TGAWidth`, `TGAHeight`, `TGATargetScreenWidth`, `TGATargetScreenHeight`, `Scaleable`, `HorizontalScaleModifier`, `MaxPercentOfInterfaceVRAM`, `ImageWH`, and `ImageWHScaled` are promoted into typed report fields when present.".to_string(),
],
entries,
malformed_lines,
@ -105,19 +111,31 @@ pub fn inspect_imb_bytes(bytes: &[u8]) -> Result<ImbInspectionReport, Box<dyn st
}
fn parse_i64_tokens(tokens: &[String]) -> Option<Vec<i64>> {
tokens
let numeric_tokens = numeric_prefix_tokens(tokens);
(!numeric_tokens.is_empty())
.then_some(numeric_tokens)?
.iter()
.map(|token| token.parse::<i64>().ok())
.collect::<Option<Vec<_>>>()
}
fn parse_f64_tokens(tokens: &[String]) -> Option<Vec<f64>> {
tokens
let numeric_tokens = numeric_prefix_tokens(tokens);
(!numeric_tokens.is_empty())
.then_some(numeric_tokens)?
.iter()
.map(|token| token.parse::<f64>().ok())
.collect::<Option<Vec<_>>>()
}
fn numeric_prefix_tokens(tokens: &[String]) -> Vec<&str> {
tokens
.iter()
.take_while(|token| !token.starts_with(';'))
.map(|token| token.as_str())
.collect()
}
fn find_scalar_string(entries: &[ImbInspectionEntry], key: &str) -> Option<String> {
entries
.iter()
@ -220,4 +238,20 @@ mod tests {
assert_eq!(report.scaleable, Some(true));
assert_eq!(report.max_percent_of_interface_vram, Some(0.06));
}
#[test]
fn parses_comment_suffixed_numeric_rows_and_ne_profile_fields() {
let report = inspect_imb_bytes(
b"TGAName GP7L_NE\nHorizontalScaleModifier 0.75 ;384/512\nMaxPercentOfInterfaceVRAM 0.09 ;comment\nImageWHScaled 0 0 384 128\nImageWH 56 0 216 32 ;# 1 BigBoy\n",
)
.expect("imb should parse");
assert_eq!(report.horizontal_scale_modifier, Some(0.75));
assert_eq!(report.max_percent_of_interface_vram, Some(0.09));
assert_eq!(report.image_rect_scaled, Some([0, 0, 384, 128]));
assert_eq!(report.image_rect, Some([56, 0, 216, 32]));
assert_eq!(report.entries[1].float_values, Some(vec![0.75]));
assert_eq!(report.entries[2].float_values, Some(vec![0.09]));
assert_eq!(report.entries[3].integer_values, Some(vec![0, 0, 384, 128]));
}
}