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