veloren_common/util/
mod.rs

1mod color;
2pub mod dir;
3pub mod div;
4pub mod find_dist;
5mod grid_hasher;
6pub mod lines;
7mod macros;
8mod option;
9pub mod plane;
10pub mod projection;
11mod ron_recover;
12/// Contains [`SpatialGrid`] which is useful for accelerating queries of nearby
13/// entities
14mod spatial_grid;
15
16pub const VELOREN_VERSION_STAGE: &str = "Pre-Alpha";
17const VELOREN_GIT_VERSION_BUILD: &str = env!("VELOREN_GIT_VERSION");
18
19use std::str::FromStr;
20lazy_static::lazy_static! {
21    static ref VELOREN_GIT_VERSION: String =
22        std::env::var("VELOREN_GIT_VERSION").unwrap_or_else(|_| VELOREN_GIT_VERSION_BUILD.to_string());
23    pub static ref GIT_TAG: &'static str = VELOREN_GIT_VERSION.split('/').next().expect("failed to retrieve git_tag!");
24    /// The first 32 bits of the git hash. We don't need more, the non-collision guarantee isn't
25    /// all that important for our purposes.
26    pub static ref GIT_HASH: u32 = u32::from_str_radix(VELOREN_GIT_VERSION.split('/').nth(1).expect("failed to retrieve git_hash!"), 16).expect("invalid git_hash!");
27    pub static ref GIT_TIMESTAMP: i64 = i64::from_str(VELOREN_GIT_VERSION.split('/').nth(2).expect("failed to retrieve git_timestamp!")).expect("invalid git_timestamp!");
28    pub static ref DISPLAY_VERSION: String = if GIT_TAG.is_empty() {
29        make_display_version(*GIT_HASH, *GIT_TIMESTAMP)
30    } else {
31        append_date(*GIT_TAG, *GIT_TIMESTAMP)
32    };
33}
34
35pub fn make_display_version(hash: u32, timestamp: i64) -> String {
36    append_date(&format!("{:x}", hash), timestamp)
37}
38
39fn append_date(version: &str, timestamp: i64) -> String {
40    use chrono::DateTime;
41    if let Some(datetime) = DateTime::from_timestamp_secs(timestamp) {
42        format!("{} [{}]", version, datetime.format("%F"))
43    } else {
44        version.to_owned()
45    }
46}
47
48pub use color::*;
49pub use dir::*;
50pub use grid_hasher::GridHasher;
51pub use option::either_with;
52pub use plane::Plane;
53pub use projection::Projection;
54pub use ron_recover::ron_from_path_recoverable;
55pub use spatial_grid::SpatialGrid;