Skip to content

Commit a39f6eb

Browse files
authored
Add code format check as GitHub workflow. (#31)
* Add code format check as GitHub workflow. * Run format_code.sh. * Rename workflow to "ci".
1 parent d975f25 commit a39f6eb

File tree

6 files changed

+58
-5
lines changed

6 files changed

+58
-5
lines changed

.github/format_check_diff.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
[[ ! $(git --version) ]] && exit 1
4+
5+
output=$(git diff)
6+
7+
if [[ "$output" != "" ]]; then
8+
echo "One or more source files are not formatted!"
9+
exit 1
10+
fi
11+
12+
echo "All source files are formatted"
13+
exit

.github/workflows/format_check.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: ci
2+
on: [push]
3+
jobs:
4+
format-check:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- name: format code
9+
run: tools/format_code.sh
10+
- name: check diff
11+
run: .github/format_check_diff.sh

DogTales/src/components/physics.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ namespace component {
55
void Physics::tick(bave::Seconds dt) {
66
static constexpr bave::Seconds ft{0.005}; // 5ms
77

8-
if (dt.count() > tick_limit_v.count()) { return; } // return for unexpected dt values, particularly during the beginning of the state
8+
if (dt.count() > tick_limit_v.count()) {
9+
return;
10+
} // return for unexpected dt values, particularly during the beginning of the state
911

1012
for (dt += m_residue; dt > ft; dt -= ft) { integrate(ft); }
1113
m_residue = dt;

DogTales/src/components/physics.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class Physics {
1616
bave::Seconds m_residue{};
1717

1818
public:
19-
20-
Physics(glm::vec2 friction = default_friction, float gravity = default_gravity, float mass = default_mass) : friction(friction), gravity(gravity), mass(mass) {}
19+
Physics(glm::vec2 friction = default_friction, float gravity = default_gravity, float mass = default_mass)
20+
: friction(friction), gravity(gravity), mass(mass) {}
2121

2222
glm::vec2 position{};
2323
glm::vec2 velocity{};

DogTales/src/player.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ void Player::handle_wall_collision() {
2121
auto const bounce_rect = bave::Rect<>::from_size(m_world_space - m_sprite.get_size(), glm::vec2{0.0f});
2222

2323
// if the sprite's position exceeds the play area, the corresponding velocity component needs to flip.
24-
if (position.x < bounce_rect.top_left().x || position.x > bounce_rect.bottom_right().x) { m_physics.velocity.x *= -0.9f; }
25-
if (position.y > bounce_rect.top_left().y || position.y < bounce_rect.bottom_right().y) { m_physics.velocity.y *= -0.9f; }
24+
if (position.x < bounce_rect.top_left().x || position.x > bounce_rect.bottom_right().x) {
25+
m_physics.velocity.x *= -0.9f;
26+
}
27+
if (position.y > bounce_rect.top_left().y || position.y < bounce_rect.bottom_right().y) {
28+
m_physics.velocity.y *= -0.9f;
29+
}
2630

2731
// clamp the position to the play area.
2832
// bottom_left() gives us the minimum x and y whereas top_right() gives us the maximum.

tools/format_code.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
[[ ! $(clang-format --version) ]] && exit 1
4+
5+
script_path=${0%/*}
6+
tools_root=${script_path%/*}
7+
project_root=$tools_root/..
8+
9+
if [[ "$0" != "$project_root" ]] && [[ "$project_root" != "" ]]; then
10+
cd "$project_root" || exit 1
11+
echo "-- Changed pwd to $(pwd)"
12+
fi
13+
14+
files=$(find DogTales -name "*.?pp")
15+
if [[ "$files" == "" ]]; then
16+
echo "-- No source files found"
17+
exit
18+
fi
19+
20+
clang-format -i $files
21+
echo -e "-- Formatted Files:\n$files\n"
22+
23+
exit

0 commit comments

Comments
 (0)