Commit b234f6a5 authored by Rahix's avatar Rahix 🦀
Browse files

Merge 'Display version in the bottom left corner'

Closes #18

See merge request !20
parents a948c68e 1780f0f8
......@@ -5,6 +5,7 @@ authors = ["Rahix <rahix@rahix.de>"]
license = "GPL-3.0-or-later"
edition = "2018"
autobins = false
build = "src/build.rs"
[lib]
crate-type = ["cdylib"]
......
//! Get git version to be displayed in-game
use std::fs;
use std::path;
use std::process;
use std::io::Read;
fn get_version_string() -> String {
let output = process::Command::new("git")
.args(&["describe", "--always", "--dirty", "--long"])
.current_dir(env!("CARGO_MANIFEST_DIR"))
.output()
.unwrap();
assert!(output.status.success());
String::from_utf8_lossy(&output.stdout).to_string()
}
fn main() {
println!("cargo:rustc-env=VERSION_INFO={}", get_version_string());
let gitdir = path::PathBuf::from(".git");
if !fs::metadata(&gitdir).map(|m| m.is_dir()).unwrap_or(false) {
println!("cargo:warning=`.git` is not a directory! Version info might be incorrect.");
return;
}
println!("cargo:rerun-if-changed={}", gitdir.join("HEAD").display());
// Parse the ref from .git/HEAD and add it, too
let mut f = fs::File::open(gitdir.join("HEAD")).unwrap();
let mut content = String::new();
f.read_to_string(&mut content).unwrap();
if let Some(refname) = content.split(": ").nth(1).map(|s| s.trim_end_matches("\n")) {
let refpath = gitdir.join(refname);
if !fs::metadata(&refpath).map(|m| m.is_file()).unwrap_or(false) {
println!("cargo:warning=git ref {:?} does not seem to exist", refname);
return;
}
println!("cargo:rerun-if-changed={}", refpath.display());
}
}
......@@ -14,6 +14,7 @@ pub mod utils;
#[wasm_bindgen]
pub fn start() -> Result<(), JsValue> {
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
utils::update_version_info();
gamestate::StateMachine::launch(states::MainMenuState::new());
Ok(())
}
......@@ -138,3 +138,9 @@ impl From<JsValue> for JsError {
JsError(format!("{:?}", js_value))
}
}
pub fn update_version_info() {
const VERSION: &str = env!("VERSION_INFO");
let element: web_sys::Element = get_element_by_id("version-info").unwrap();
element.set_inner_html(VERSION);
}
......@@ -53,6 +53,7 @@
</g>
</svg>
<svg class="game-gui" viewBox="0 0 1920 1080">
<text x="10" y="1070" class="version-info" id="version-info">Unknown version ...</text>
<!-- rc3 logo -->
<g transform="translate(1780, 940) scale(0.2)">
<defs>
......
......@@ -40,6 +40,12 @@ div.game {
fill: transparentize($background, 0.8);
}
text.version-info {
font-family: "Montserrat";
font-size: 12pt;
fill: #ffffff90;
}
text.header {
font-family: "Orbitron";
font-weight: 900;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment