From 7b3a106ff7a376b95b3bb9e52d3186ebe1a9bcaa Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 07:04:16 +0400 Subject: feat(ui): open saved warbot projects with distinct geometry Prepare saved Unit DAT geometry alongside factory reserves at mission entry and expose compatible, researched files through the designer. Verified a single-gun assembly in the Field Camp window and after factory release with the ore and power supply established in the test. --- apps/fparkan-game/src/designer_projects.rs | 53 ++++++++++++++---------------- 1 file changed, 24 insertions(+), 29 deletions(-) (limited to 'apps/fparkan-game/src/designer_projects.rs') diff --git a/apps/fparkan-game/src/designer_projects.rs b/apps/fparkan-game/src/designer_projects.rs index 1b73a880..1a485fee 100644 --- a/apps/fparkan-game/src/designer_projects.rs +++ b/apps/fparkan-game/src/designer_projects.rs @@ -1,13 +1,17 @@ //! The original designer's named Unit DAT files under the game root. -use fparkan_runtime::{restore_factory_design, Engine, FactoryPartChange, StartingCockpit}; +use fparkan_runtime::{ + is_saved_factory_project_name, restore_factory_design, Engine, FactoryPartChange, + StartingCockpit, +}; use std::{fs, io, io::Write, path::Path}; pub(super) const NAME_LIMIT: usize = 16; pub(super) struct SavedProject { pub(super) name: String, - pub(super) choice: usize, + pub(super) choice: Option, + pub(super) scheme: usize, pub(super) changes: Vec, } @@ -25,12 +29,6 @@ pub(super) fn name_character(value: char) -> bool { value.is_alphanumeric() || matches!(value, '_' | '-' | ' ') } -fn internal_name(value: &str) -> bool { - ["temp_unit", "bld_unit_", "view_unit_"] - .iter() - .any(|prefix| value.starts_with(prefix)) -} - pub(super) fn save_project(directory: &Path, name: &str, bytes: &[u8]) -> io::Result { let name = name.trim(); let folded = name.to_ascii_lowercase(); @@ -38,18 +36,18 @@ pub(super) fn save_project(directory: &Path, name: &str, bytes: &[u8]) -> io::Re || (folded.len() == 4 && (folded.starts_with("com") || folded.starts_with("lpt")) && folded.as_bytes()[3].is_ascii_digit()); + let filename = format!("{name}.dat"); if name.is_empty() || name.chars().count() > NAME_LIMIT || !name.chars().all(name_character) || device - || internal_name(&folded) + || !is_saved_factory_project_name(&filename) { return Err(io::Error::new( io::ErrorKind::InvalidInput, "invalid Unit DAT name", )); } - let filename = format!("{name}.dat"); let path = directory.join(&filename); let mut file = fs::OpenOptions::new() .write(true) @@ -68,6 +66,7 @@ pub(super) fn browse_projects( engine: &Engine, cockpit: StartingCockpit, choices: &[(usize, usize)], + prepared: &[usize], ) -> io::Result> { let mut projects = Vec::new(); for entry in fs::read_dir(directory)? { @@ -76,12 +75,7 @@ pub(super) fn browse_projects( let Some(name) = path.file_name().and_then(|name| name.to_str()) else { continue; }; - if path - .extension() - .is_none_or(|ext| !ext.eq_ignore_ascii_case("dat")) - || internal_name(&name.to_ascii_lowercase()) - || !entry.file_type()?.is_file() - { + if !is_saved_factory_project_name(name) || !entry.file_type()?.is_file() { continue; } let bytes = match fs::read(&path) { @@ -91,19 +85,20 @@ pub(super) fn browse_projects( continue; } }; - if let Some((scheme, changes)) = restore_factory_design( - engine, - cockpit, - choices.iter().map(|&(_, scheme)| scheme), - &bytes, - ) { - if let Some(&(choice, _)) = choices.iter().find(|&&(_, index)| index == scheme) { - projects.push(SavedProject { - name: name.to_owned(), - choice, - changes, - }); - } + let schemes = choices + .iter() + .map(|&(_, scheme)| scheme) + .chain(prepared.iter().copied()); + if let Some((scheme, changes)) = restore_factory_design(engine, cockpit, schemes, &bytes) { + let choice = choices + .iter() + .find_map(|&(choice, index)| (index == scheme).then_some(choice)); + projects.push(SavedProject { + name: name.to_owned(), + choice, + scheme, + changes, + }); } } projects.sort_by(|left, right| left.name.to_lowercase().cmp(&right.name.to_lowercase())); -- cgit v1.2.3