From 6c9fe794cda795b101825091aee4644efd9422f8 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 01:39:12 +0400 Subject: feat(ui): show installed warbot weapons in the cockpit Resolve each selected mount through the original objects.dlb short name and render the live weapon bank after boarding. On a stock Fireline start the medium warbot shows the laser and both separate missile racks. Firing the selected rack reduces its ammunition from 18 to 17 while the other still reads 18. --- crates/fparkan-assets/src/object_descriptions.rs | 63 ++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 crates/fparkan-assets/src/object_descriptions.rs (limited to 'crates/fparkan-assets/src/object_descriptions.rs') diff --git a/crates/fparkan-assets/src/object_descriptions.rs b/crates/fparkan-assets/src/object_descriptions.rs new file mode 100644 index 00000000..59c4e88e --- /dev/null +++ b/crates/fparkan-assets/src/object_descriptions.rs @@ -0,0 +1,63 @@ +//! Short names from the original object's description library. + +use crate::ui_configuration::read; +use fparkan_nres::{decode, NresDocument, ReadProfile}; +use fparkan_vfs::Vfs; + +const DESCRIPTION: u32 = u32::from_le_bytes(*b"DSCR"); + +pub struct ObjectDescriptions(NresDocument); + +impl ObjectDescriptions { + pub fn load(vfs: &dyn Vfs) -> Result { + decode(read(vfs, "objects.dlb")?, ReadProfile::Strict) + .map(Self) + .map_err(|error| error.to_string()) + } + + /// The catalogue's `#1` field, kept in the game's text encoding. + #[must_use] + pub fn short_name(&self, prototype: &[u8]) -> Option<&[u8]> { + let id = self.0.find_bytes(prototype)?; + if self.0.entry(id)?.meta().type_id != DESCRIPTION { + return None; + } + short_name(self.0.payload(id).ok()?) + } +} + +fn short_name(description: &[u8]) -> Option<&[u8]> { + description + .split(|&byte| matches!(byte, b'\n' | b'\r' | 0)) + .find_map(|line| line.strip_prefix(b"#1").filter(|name| !name.is_empty())) +} + +#[cfg(test)] +mod tests { + use super::*; + use fparkan_vfs::DirectoryVfs; + + #[test] + fn keeps_the_short_name_bytes_and_ignores_the_long_name() { + assert_eq!( + short_name(b"//catalogue\r\n#1MRL 1\r\n#2long name\0"), + Some(b"MRL 1".as_slice()) + ); + assert_eq!(short_name(b"#2long name only\r\n"), None); + } + + #[test] + #[ignore = "requires licensed corpus"] + fn original_flying_warbot_prototypes_use_the_native_short_names() { + let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed corpus"); + let descriptions = ObjectDescriptions::load(&DirectoryVfs::new(root)).unwrap(); + assert_eq!( + descriptions.short_name(b"E_GUN_MC_21"), + Some(b"MDRLas".as_slice()) + ); + assert_eq!( + descriptions.short_name(b"e_gun_ml_10"), + Some(b"MML9S".as_slice()) + ); + } +} -- cgit v1.2.3