From e50b53e7a08d8b5e3393e477b890da95c4c8ef2a Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 08:50:33 +0400 Subject: feat(ui): install turrets and weapons in designer sockets Read the chassis and turret mount families from MSH Res10 and the attached devices from CTLD. Preserve the parent and mount node in Unit DAT, including separate ammunition subtrees for matching weapons. Verified from the stock Field Camp start: install a turret, mount two identical guns, remove one with its ammunition, and order the edited project through the factory panel. --- crates/fparkan-assets/src/designer_sockets.rs | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 crates/fparkan-assets/src/designer_sockets.rs (limited to 'crates/fparkan-assets/src/designer_sockets.rs') diff --git a/crates/fparkan-assets/src/designer_sockets.rs b/crates/fparkan-assets/src/designer_sockets.rs new file mode 100644 index 00000000..44ccf7c8 --- /dev/null +++ b/crates/fparkan-assets/src/designer_sockets.rs @@ -0,0 +1,74 @@ +//! Named model sockets exposed by the original constructor. + +use crate::{designer_categories::DesignerCategory, MissionAssets}; +use fparkan_prototype::{unit_component_tree, UnitComponentRecord}; + +/// One external mounting point, identified by its parent record and MSH node. +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct DesignerSocket { + /// Category of part the socket accepts. + pub category: DesignerCategory, + /// Parent construction record. + pub parent: usize, + /// Socket node in the parent's model. + pub node: usize, + /// Original socket label from MSH Res10. + pub family: String, + /// Installed Unit DAT record, if occupied. + pub part: Option, +} + +/// Finds the chassis's turret mounts and every installed turret's weapon mounts. +pub fn designer_sockets( + assets: &MissionAssets, + object: usize, + records: &[UnitComponentRecord], +) -> Vec { + let Ok(tree) = unit_component_tree(records) else { + return Vec::new(); + }; + let mut sockets = Vec::new(); + for (parent, visual) in assets.visuals_for_object(object).iter().enumerate() { + let Some(record) = records.get(parent).filter(|record| record.kind != 0) else { + continue; + }; + let category = match DesignerCategory::from_record(record) { + Some(DesignerCategory::Chassis) => DesignerCategory::Turret, + Some(DesignerCategory::Turret) => DesignerCategory::Weapon, + _ => continue, + }; + let Some(names) = assets + .visual_by_id(*visual) + .and_then(|visual| assets.model_by_id(visual.model_id?)) + .and_then(|model| model.validated.node_names.as_ref()) + else { + continue; + }; + for (node, family) in names.iter().enumerate() { + let Some(family) = family.as_ref() else { + continue; + }; + let canonical = family.to_ascii_lowercase(); + let usable = match category { + DesignerCategory::Turret => canonical.starts_with("e_tur_"), + _ => canonical.starts_with("universal_") || canonical.starts_with("central_"), + }; + if !usable { + continue; + } + let part = tree[parent].children.iter().copied().find(|&index| { + records[index].kind != 0 + && records[index].parent_or_link == node as i32 + && DesignerCategory::from_record(&records[index]) == Some(category) + }); + sockets.push(DesignerSocket { + category, + parent, + node, + family: canonical, + part, + }); + } + } + sockets +} -- cgit v1.2.3