Skip to main content

forge/
constants.rs

1//! Shared numeric constants and well-known paths used across forge subcommands.
2
3use wowlab_common::output;
4use wowlab_fs::{
5    directory::{self, EntryKind},
6    path::{Path, PathBuf},
7};
8
9pub(crate) const DEFAULT_SEED: u64 = 12345;
10
11/// Protobuf scale factor: DPS and damage values are stored as 10x integers.
12pub(crate) const DPS_SCALE: f64 = 10.0;
13
14/// `forge` -> `crates` -> `wowlab` -> parent.
15const WORKSPACE_PARENT_DEPTH: usize = 3;
16
17pub(crate) fn workspace_parent() -> &'static Path {
18    Path::new(env!("CARGO_MANIFEST_DIR"))
19        .ancestors()
20        .nth(WORKSPACE_PARENT_DEPTH)
21        .expect("forge crate lives at <parent>/wowlab/crates/forge")
22}
23
24pub(crate) fn default_data_dir() -> String {
25    workspace_parent()
26        .join("wowlab-data")
27        .to_string_lossy()
28        .into_owned()
29}
30
31pub(crate) fn engine_dir() -> PathBuf {
32    let dir = Path::new(env!("CARGO_MANIFEST_DIR"))
33        .parent()
34        .expect("forge parent")
35        .join("engine");
36
37    match directory::inspect(&dir) {
38        Ok(Some(entry)) if entry.kind() == EntryKind::Directory => return dir,
39        Ok(Some(_)) => output::error(&format!(
40            "forge requires the workspace layout, but the expected engine crate is not a \
41             directory: {}",
42            dir.display(),
43        )),
44        Ok(None) => output::error(&format!(
45            "forge requires the workspace layout; run via 'cargo forge' from the repo root \
46             (expected engine crate at {})",
47            dir.display(),
48        )),
49        Err(error) => output::error(&error.to_string()),
50    }
51
52    // #t(rust_deep_exit) top-level fatal error path in the forge CLI binary.
53    std::process::exit(1);
54}