diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-03 11:09:57 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-03 11:09:57 +0300 |
| commit | 6d2e80ef33fba4e1e16a283fca83b2b949907282 (patch) | |
| tree | 7221f6615f09bbcd9f4f16673378fad52115b29d /apps/fparkan-game/src | |
| parent | 5350c80ff37aea17a2ffccb5b616616d629b43a3 (diff) | |
| download | fparkan-6d2e80ef33fba4e1e16a283fca83b2b949907282.tar.xz fparkan-6d2e80ef33fba4e1e16a283fca83b2b949907282.zip | |
feat(cli): default game data to the working directory
Diffstat (limited to 'apps/fparkan-game/src')
| -rw-r--r-- | apps/fparkan-game/src/main.rs | 8 | ||||
| -rw-r--r-- | apps/fparkan-game/src/mission_startup.rs | 14 |
2 files changed, 20 insertions, 2 deletions
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 <path> --list-missions\n fparkan-game --root <path> --mission <number|path> --sim-report <seconds>\n fparkan-game --root <path> --mission <number|path> [--build-scheme <Unit DAT path> [--build-part OLD=NEW]...] [--viewer] [--frames <n>] [--atmosphere-seconds <seconds>] [--control-clock-ms <u32>] [--validation] [--preview-roots <non-zero n>] [--legacy-camera-capture <path>] [--static-animation-frame <u16>] [--static-material-phase <u16>] [--readback-out <path>] [--readback-sequence-out <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() + "usage: fparkan-game [--root <path>] --list-missions\n fparkan-game [--root <path>] --mission <number|path> --sim-report <seconds>\n fparkan-game [--root <path>] --mission <number|path> [--build-scheme <Unit DAT path> [--build-part OLD=NEW]...] [--viewer] [--frames <n>] [--atmosphere-seconds <seconds>] [--control-clock-ms <u32>] [--validation] [--preview-roots <non-zero n>] [--legacy-camera-capture <path>] [--static-animation-frame <u16>] [--static-material-phase <u16>] [--readback-out <path>] [--readback-sequence-out <directory>]\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<String, String> { let mut args = Args::parse(args)?; let vfs = Arc::new(DirectoryVfs::new(&args.root)); |
