diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 07:50:33 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 07:50:33 +0300 |
| commit | e50b53e7a08d8b5e3393e477b890da95c4c8ef2a (patch) | |
| tree | 1506b2d9685b562b4b22966c5e16bc574f69fbbc /crates/fparkan-assets/src/designer_sockets.rs | |
| parent | 20491de7c29f56fda9be16d3b56a9633cb71d386 (diff) | |
| download | fparkan-e50b53e7a08d8b5e3393e477b890da95c4c8ef2a.tar.xz fparkan-e50b53e7a08d8b5e3393e477b890da95c4c8ef2a.zip | |
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.
Diffstat (limited to 'crates/fparkan-assets/src/designer_sockets.rs')
| -rw-r--r-- | crates/fparkan-assets/src/designer_sockets.rs | 74 |
1 files changed, 74 insertions, 0 deletions
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<usize>, +} + +/// Finds the chassis's turret mounts and every installed turret's weapon mounts. +pub fn designer_sockets( + assets: &MissionAssets, + object: usize, + records: &[UnitComponentRecord], +) -> Vec<DesignerSocket> { + 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 +} |
