Skip to content

Commit

Permalink
feat: more detailed game info: build time of app (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovebaihezi authored Oct 10, 2024
1 parent adc276b commit fdfd87a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: install wasm-bindgen-cli
run: |
rustup component add rustc-codegen-cranelift-preview --toolchain nightly
cargo install wasm-bindgen-cli
cargo install -f wasm-bindgen-cli --version 0.2.93
- name: install wasm-opt
run: |
cargo install wasm-opt
Expand All @@ -48,7 +48,7 @@ jobs:
- name: Prepare package
run: |
# Gen Wasm and js loader
wasm-bindgen --no-typescript --out-name ${{ env.binary }} --out-dir wasm --target web target/wasm32-unknown-unknown/release/${{ env.binary }}.wasm
wasm-bindgen --out-name ${{ env.binary }} --out-dir wasm --target web target/wasm32-unknown-unknown/release/${{ env.binary }}.wasm
wasm-opt -O wasm/${{ env.binary }}_bg.wasm -o ${{ env.binary }}.wasm
# Compress Wasm using brotli
brotli wasm/${{ env.binary }}_bg.wasm -o web/${{ env.binary }}_bg.wasm
Expand Down
26 changes: 23 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
use std::process::Command;

fn main() {
fn get_version() {
let version_output = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.unwrap();

let git_hash = String::from_utf8(version_output.stdout).unwrap();

println!("cargo:rustc-env=GIT_HASH={}", git_hash);
}

fn get_branch() {
let branch_output = Command::new("git")
.args(["rev-parse", "--abbrev-ref", "HEAD"])
.output()
.unwrap();

let git_branch = String::from_utf8(branch_output.stdout).unwrap();

println!("cargo:rustc-env=GIT_HASH={}", git_hash);

println!("cargo:rustc-env=GIT_BRANCH={}", git_branch);
}

fn get_build_date() {
let build_date = Command::new("date")
.args(["+%Y-%m-%d %H:%M:%S"])
.output()
.unwrap();

let date = String::from_utf8(build_date.stdout).unwrap();

println!("cargo:rustc-env=BUILD_DATE={}", date);
}

fn main() {
get_version();
get_branch();
get_build_date();
}
10 changes: 7 additions & 3 deletions src/game_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,25 @@ fn base_node() -> NodeBundle {
}
}

fn version_bundle() -> TextBundle {
fn game_info_bundle() -> TextBundle {
const GAME_VERSION: &str = concat!(
"game_version: ",
env!("CARGO_PKG_VERSION"),
"-",
env!("GIT_HASH")
);

const BUILD_DATE: &str = concat!("build on ", env!("BUILD_DATE"));

let game_info = format!("{}\n{}", BUILD_DATE, GAME_VERSION);

TextBundle {
style: Style {
align_self: bevy::ui::AlignSelf::Center,
..default()
},
text: Text::from_section(
GAME_VERSION,
game_info,
TextStyle {
color: Color::srgba(0.0, 0.0, 0.0, 1.0),
font_size: 12.0,
Expand Down Expand Up @@ -136,7 +140,7 @@ pub fn setup_game_control(mut commands: Commands, mut time: ResMut<Time<Virtual>
parent.spawn(score_bundle());
});
parent.spawn(banner()).with_children(|parent| {
parent.spawn(version_bundle());
parent.spawn(game_info_bundle());
parent.spawn(branch_boundle());
});
});
Expand Down
7 changes: 3 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use bevy::{diagnostic::FrameTimeDiagnosticsPlugin, prelude::*};
use dinosaur::{
dino_jump_animation, dino_jump_system, dino_pos_fix_system, game_info,
game_logic::{dino_touched_tree, reset_game},
reset_tree, setup_camera, setup_dino, setup_game_control, setup_ground, setup_tree,
tree_move_animation, update_ground, user_control,
setup_camera, setup_dino, setup_game_control, setup_ground, setup_tree, tree_move_animation,
update_ground, user_control,
};

fn main() {
Expand All @@ -28,8 +28,7 @@ fn main() {
(user_control, game_info).chain(),
(dino_pos_fix_system, dino_jump_animation).chain(),
tree_move_animation,
dino_touched_tree,
(reset_game, reset_tree).chain(),
(dino_touched_tree, reset_game).chain(),
),
)
.run();
Expand Down
18 changes: 2 additions & 16 deletions src/tree.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use bevy::{
color::Color,
math::{Vec2, Vec3},
prelude::{default, Commands, Query, Res, Transform, With},
prelude::{default, Commands, Query, Res, Transform},
sprite::{Sprite, SpriteBundle},
time::{Time, Virtual},
window::Window,
};

use crate::components::{Dino, Tree, TREE_WIDTH};
use crate::components::{Tree, TREE_WIDTH};

pub fn setup_tree(mut commands: Commands, window: Query<&Window>) {
let window = window.single();
Expand All @@ -31,20 +31,6 @@ pub fn setup_tree(mut commands: Commands, window: Query<&Window>) {
));
}

pub fn reset_tree(
dino_query: Query<&Dino>,
mut query: Query<&mut Transform, With<Tree>>,
window: Query<&Window>,
) {
let window = window.single();
let window_width = window.width();
for (dino, mut transform) in dino_query.iter().zip(query.iter_mut()) {
if dino.is_ready() {
transform.translation.x = window_width - TREE_WIDTH;
}
}
}

pub fn tree_move_animation(
mut tree_query: Query<(&mut Transform, &mut Tree)>,
time: Res<Time<Virtual>>,
Expand Down

0 comments on commit fdfd87a

Please sign in to comment.