From 6d2e80ef33fba4e1e16a283fca83b2b949907282 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 3 Dec 2026 12:09:57 +0400 Subject: feat(cli): default game data to the working directory --- apps/fparkan-game/src/main.rs | 8 ++++++-- apps/fparkan-game/src/mission_startup.rs | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'apps/fparkan-game') diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index cfae3ffb..2129f82c 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -11557,7 +11557,11 @@ impl Args { _ => return Err(usage()), } } - let root = root.ok_or_else(|| "missing --root".to_string())?; + let root = match root { + Some(root) => root, + None => std::env::current_dir() + .map_err(|error| format!("cannot resolve the game data directory: {error}"))?, + }; let mission = match (list_missions, mission) { (true, None) if sim_report_ms.is_none() => String::new(), (true, _) => { @@ -11612,7 +11616,7 @@ impl Args { } fn usage() -> String { - "usage: fparkan-game --root --list-missions\n fparkan-game --root --mission --sim-report \n fparkan-game --root --mission [--build-scheme [--build-part OLD=NEW]...] [--viewer] [--frames ] [--atmosphere-seconds ] [--control-clock-ms ] [--validation] [--preview-roots ] [--legacy-camera-capture ] [--static-animation-frame ] [--static-material-phase ] [--readback-out ] [--readback-sequence-out ]\n--viewer skips mission simulation. Capture, static pose/material and root-limit options select viewer mode. --control-clock-ms replays the scene clock from zero to the selected time over the requested frames; --readback-sequence-out captures each submitted frame and requires that clock.".to_string() + "usage: fparkan-game [--root ] --list-missions\n fparkan-game [--root ] --mission --sim-report \n fparkan-game [--root ] --mission [--build-scheme [--build-part OLD=NEW]...] [--viewer] [--frames ] [--atmosphere-seconds ] [--control-clock-ms ] [--validation] [--preview-roots ] [--legacy-camera-capture ] [--static-animation-frame ] [--static-material-phase ] [--readback-out ] [--readback-sequence-out ]\nWithout --root, game data is read from the working directory.\n--viewer skips mission simulation. Capture, static pose/material and root-limit options select viewer mode. --control-clock-ms replays the scene clock from zero to the selected time over the requested frames; --readback-sequence-out captures each submitted frame and requires that clock.".to_string() } #[cfg(test)] diff --git a/apps/fparkan-game/src/mission_startup.rs b/apps/fparkan-game/src/mission_startup.rs index f0841da5..2b3f47ef 100644 --- a/apps/fparkan-game/src/mission_startup.rs +++ b/apps/fparkan-game/src/mission_startup.rs @@ -24,6 +24,20 @@ use std::{ use mission_loading::Stage; +#[cfg(test)] +#[test] +fn omitted_game_root_uses_the_working_directory() { + let args = Args::parse(&["--list-missions".into()]).unwrap(); + assert_eq!(args.root, std::env::current_dir().unwrap()); + let args = Args::parse(&[ + "--root".into(), + "other-root".into(), + "--list-missions".into(), + ]) + .unwrap(); + assert_eq!(args.root, std::path::Path::new("other-root")); +} + pub(super) fn run(args: &[String]) -> Result { let mut args = Args::parse(args)?; let vfs = Arc::new(DirectoryVfs::new(&args.root)); -- cgit v1.2.3