From b48fb2caccc7a72b85f07e6ab652081af57c7855 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Tue, 1 Dec 2026 22:32:55 +0400 Subject: feat(ui): render mission hints with the original game font Resolve the witnessed 800x600 GAME_FONT through the installed resource configuration. Draw CP1251 bytes from the Tfnt atlas using the original variable-width metrics. Checked the original measurement routine and the first Constructor hint in the game window. --- crates/fparkan-assets/src/ui_configuration.rs | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 crates/fparkan-assets/src/ui_configuration.rs (limited to 'crates/fparkan-assets/src/ui_configuration.rs') diff --git a/crates/fparkan-assets/src/ui_configuration.rs b/crates/fparkan-assets/src/ui_configuration.rs new file mode 100644 index 00000000..e678d760 --- /dev/null +++ b/crates/fparkan-assets/src/ui_configuration.rs @@ -0,0 +1,54 @@ +use fparkan_path::{normalize_relative, PathPolicy}; +use fparkan_vfs::Vfs; +use std::{collections::BTreeMap, sync::Arc}; + +pub(super) fn read(vfs: &dyn Vfs, path: &str) -> Result, String> { + let path = normalize_relative( + path.replace("\\\\", "\\").as_bytes(), + PathPolicy::StrictLegacy, + ) + .map_err(|error| error.to_string())?; + vfs.read(&path).map_err(|error| error.to_string()) +} + +pub(super) fn object<'a>(text: &'a str, name: &str) -> Option> { + let mut lines = text + .lines() + .map(|line| line.split('#').next().unwrap_or_default().trim()); + for line in lines.by_ref() { + let mut words = line.split_whitespace(); + if words + .next() + .is_some_and(|word| word.eq_ignore_ascii_case("object")) + && words + .next() + .is_some_and(|word| word.eq_ignore_ascii_case(name)) + { + return Some( + lines + .take_while(|line| !line.eq_ignore_ascii_case("end")) + .filter_map(|line| line.split_once('=')) + .map(|(key, value)| (key.trim().to_ascii_uppercase(), value.trim())) + .collect(), + ); + } + } + None +} + +pub(super) fn field<'a>(fields: &BTreeMap, key: &str) -> Result<&'a str, String> { + let raw = fields.get(key).ok_or_else(|| format!("missing {key}"))?; + if let Some(quoted) = raw.strip_prefix('"') { + return quoted + .split_once('"') + .map(|(value, _)| value) + .ok_or_else(|| format!("invalid quoted value for {key}")); + } + Ok(raw) +} + +pub(super) fn number(fields: &BTreeMap, key: &str) -> Result { + field(fields, key)? + .parse() + .map_err(|_| format!("invalid number for {key}")) +} -- cgit v1.2.3