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/satellite_map.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/satellite_map.rs')
| -rw-r--r-- | crates/fparkan-assets/src/satellite_map.rs | 53 |
1 files changed, 1 insertions, 52 deletions
diff --git a/crates/fparkan-assets/src/satellite_map.rs b/crates/fparkan-assets/src/satellite_map.rs index 49f8894e..9a18f2bd 100644 --- a/crates/fparkan-assets/src/satellite_map.rs +++ b/crates/fparkan-assets/src/satellite_map.rs @@ -1,11 +1,11 @@ //! Resources used by the satellite map overlay. +use crate::ui_configuration::{field, number, object, read}; use fparkan_nres::{decode, EntryId, ReadProfile}; use fparkan_path::{normalize_relative, PathPolicy}; use fparkan_resource::{resource_name, CachedResourceRepository, ResourceRepository}; use fparkan_texm::{decode_mip_rgba8, decode_texm, RgbaImage}; use fparkan_vfs::Vfs; -use std::collections::BTreeMap; use std::sync::Arc; /// The mission map and compass cut from the original interface texture atlas. @@ -69,57 +69,6 @@ pub fn load_satellite_map( })) } -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()) -} - -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 -} - -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) -} - -fn number(fields: &BTreeMap<String, &str>, key: &str) -> Result<u32, String> { - field(fields, key)? - .parse() - .map_err(|_| format!("invalid number for {key}")) -} - fn texture(bytes: &[u8]) -> Result<RgbaImage, String> { let document = decode_texm(Arc::from(bytes)).map_err(|error| error.to_string())?; decode_mip_rgba8(&document, 0).map_err(|error| error.to_string()) |
