aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/factory_menu.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 05:25:19 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 05:25:19 +0300
commit6fde1faa1dfed89007566b3373114a89139390b9 (patch)
tree05fff10a3442ba6304086defcb109c61a5a3410c /apps/fparkan-game/src/factory_menu.rs
parent0ad190894afd8e9592ef182e36e16ee7a61483f6 (diff)
downloadfparkan-6fde1faa1dfed89007566b3373114a89139390b9.tar.xz
fparkan-6fde1faa1dfed89007566b3373114a89139390b9.zip
feat(ui): edit installed warbot equipment
Choose researched internal equipment per mount and build the resulting Unit DAT with the projected Control devices. Verified pointer selection and order in Field Camp with Vulkan validation, and produced the edited two-gun design at the Constructor factory.
Diffstat (limited to 'apps/fparkan-game/src/factory_menu.rs')
-rw-r--r--apps/fparkan-game/src/factory_menu.rs72
1 files changed, 70 insertions, 2 deletions
diff --git a/apps/fparkan-game/src/factory_menu.rs b/apps/fparkan-game/src/factory_menu.rs
index 376b1723..8195aa70 100644
--- a/apps/fparkan-game/src/factory_menu.rs
+++ b/apps/fparkan-game/src/factory_menu.rs
@@ -10,7 +10,9 @@ use fparkan_assets::designer_screen::{self, DesignerAction, PART_ROWS};
use fparkan_assets::factory_projects::{
hit_test, FactoryProjectAction, FactoryProjectImages, EXTENT, ORIGIN, PROJECT_SLOTS,
};
-use fparkan_runtime::{factory_project_components, Engine};
+use fparkan_runtime::{
+ factory_part_variants, factory_project_components, Engine, FactoryPartChange,
+};
use fparkan_world::ObjectHandle;
use std::{ops::Range, path::Path};
use winit::{
@@ -23,6 +25,7 @@ pub(super) struct FactoryChoice {
pub(super) factory: Option<ObjectHandle>,
pub(super) scheme: usize,
pub(super) name: String,
+ pub(super) changes: Vec<FactoryPartChange>,
}
pub(super) struct FactoryMenu {
@@ -40,6 +43,8 @@ pub(super) struct DesignerSession {
pub(super) hover: Option<DesignerAction>,
pub(super) dirty: bool,
pub(super) model_started_ms: u32,
+ pub(super) changes: Vec<FactoryPartChange>,
+ pub(super) variants: Option<(usize, Vec<String>)>,
}
impl DesignerSession {
@@ -95,6 +100,8 @@ impl FactoryMenu {
hover: None,
dirty: true,
model_started_ms: 0,
+ changes: Vec::new(),
+ variants: None,
};
designer.point(self.cursor);
self.designer = Some(designer);
@@ -110,10 +117,15 @@ impl FactoryMenu {
designer.first_part = 0;
designer.dirty = true;
designer.model_started_ms = clock_ms;
+ designer
+ .changes
+ .clone_from(&self.choices[designer.slots.start + slot].changes);
+ designer.variants = None;
}
DesignerAction::Send => {
if let Some(slot) = designer.selected {
self.selected = designer.slots.start + slot;
+ self.choices[self.selected].changes = std::mem::take(&mut designer.changes);
self.designer = None;
}
}
@@ -363,7 +375,61 @@ impl StaticVulkanApp {
&& !self.mission_paused
{
if let Some(designer) = &menu.designer {
- if let Some(action) = designer.hover {
+ let equipment = designer.selected.and_then(|slot| {
+ let engine = self.mission_engine.as_ref()?;
+ let scheme = menu.choices[designer.slots.start + slot].scheme;
+ let parts = factory_project_components(engine, scheme)?;
+ let variant_count = designer.variants.as_ref().map_or(0, |v| v.1.len());
+ let action = designer_screen::equipment_hit(
+ menu.cursor,
+ designer.first_part,
+ parts.len(),
+ variant_count,
+ )?;
+ Some((engine, scheme, parts, action))
+ });
+ if let Some((engine, scheme, parts, action)) = equipment {
+ let designer = menu.designer.as_mut().expect("the designer is open");
+ match action {
+ DesignerAction::Part(component) => {
+ designer.variants = None;
+ if let Some(cockpit) = self.cockpit {
+ match factory_part_variants(
+ engine, cockpit, scheme, component,
+ ) {
+ Ok(variants) if !variants.is_empty() => {
+ designer.variants = Some((component, variants))
+ }
+ Ok(_) => {}
+ Err(error) => {
+ eprintln!("designer_equipment_unavailable {error}")
+ }
+ }
+ }
+ }
+ DesignerAction::Variant(index) => {
+ if let Some((component, variants)) = &designer.variants {
+ let resource = &variants[index];
+ let base = &parts[*component].resource_raw;
+ let base = base
+ .split(|&byte| byte == 0)
+ .next()
+ .unwrap_or_default();
+ designer
+ .changes
+ .retain(|change| change.component != *component);
+ if !base.eq_ignore_ascii_case(resource.as_bytes()) {
+ designer.changes.push(FactoryPartChange {
+ component: *component,
+ resource: resource.clone(),
+ });
+ }
+ }
+ }
+ _ => {}
+ }
+ designer.dirty = true;
+ } else if let Some(action) = designer.hover {
menu.designer_action(action, self.simulation_time_ms);
self.update_mission_title();
}
@@ -442,6 +508,7 @@ mod tests {
}),
scheme,
name: format!("{scheme}.dat"),
+ changes: Vec::new(),
})
.collect();
let mut menu = FactoryMenu::new(choices);
@@ -460,6 +527,7 @@ mod tests {
factory: None,
scheme,
name: format!("{scheme}.dat"),
+ changes: Vec::new(),
})
.collect(),
);