veloren_common/util/
mod.rs1mod cardinal_directions;
2mod color;
3pub mod dir;
4pub mod div;
5pub mod find_dist;
6mod grid_hasher;
7pub mod lines;
8mod macros;
9mod option;
10pub mod plane;
11pub mod projection;
12mod ron_recover;
13mod spatial_grid;
16
17pub const VELOREN_VERSION_STAGE: &str = "Pre-Alpha";
18const VELOREN_GIT_VERSION_BUILD: &str = env!("VELOREN_GIT_VERSION");
19
20use std::str::FromStr;
21lazy_static::lazy_static! {
22 static ref VELOREN_GIT_VERSION: String =
23 std::env::var("VELOREN_GIT_VERSION").unwrap_or_else(|_| VELOREN_GIT_VERSION_BUILD.to_string());
24 pub static ref GIT_TAG: &'static str = VELOREN_GIT_VERSION.split('/').next().expect("failed to retrieve git_tag!");
25 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!");
28 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!");
29 pub static ref DISPLAY_VERSION: String = if GIT_TAG.is_empty() {
30 make_display_version(*GIT_HASH, *GIT_TIMESTAMP)
31 } else {
32 append_date(*GIT_TAG, *GIT_TIMESTAMP)
33 };
34}
35
36pub fn make_display_version(hash: u32, timestamp: i64) -> String {
37 append_date(&format!("{:x}", hash), timestamp)
38}
39
40fn append_date(version: &str, timestamp: i64) -> String {
41 use chrono::DateTime;
42 if let Some(datetime) = DateTime::from_timestamp_secs(timestamp) {
43 format!("{} [{}]", version, datetime.format("%F"))
44 } else {
45 version.to_owned()
46 }
47}
48
49pub use cardinal_directions::*;
50pub use color::*;
51pub use dir::*;
52pub use grid_hasher::GridHasher;
53pub use option::either_with;
54pub use plane::Plane;
55pub use projection::Projection;
56pub use ron_recover::ron_from_path_recoverable;
57pub use spatial_grid::SpatialGrid;