diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-01 21:32:55 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-01 21:32:55 +0300 |
| commit | b48fb2caccc7a72b85f07e6ab652081af57c7855 (patch) | |
| tree | 851858e8881e9c0ba1892b1173212092b53ff86c /crates/fparkan-assets/src/ui_configuration.rs | |
| parent | 6954eb74b535341bed234091e67f62ed13266c25 (diff) | |
| download | fparkan-b48fb2caccc7a72b85f07e6ab652081af57c7855.tar.xz fparkan-b48fb2caccc7a72b85f07e6ab652081af57c7855.zip | |
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.
Diffstat (limited to 'crates/fparkan-assets/src/ui_configuration.rs')
| -rw-r--r-- | crates/fparkan-assets/src/ui_configuration.rs | 54 |
1 files changed, 54 insertions, 0 deletions
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<Arc<[u8]>, 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<BTreeMap<String, &'a str>> { + 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<String, &'a str>, 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<String, &str>, key: &str) -> Result<u32, String> { + field(fields, key)? + .parse() + .map_err(|_| format!("invalid number for {key}")) +} |
