Skip to content

Commit

Permalink
Add code format check as GitHub workflow. (#31)
Browse files Browse the repository at this point in the history
* Add code format check as GitHub workflow.

* Run format_code.sh.

* Rename workflow to "ci".
  • Loading branch information
karnkaul authored Feb 2, 2024
1 parent d975f25 commit a39f6eb
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
13 changes: 13 additions & 0 deletions .github/format_check_diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

[[ ! $(git --version) ]] && exit 1

output=$(git diff)

if [[ "$output" != "" ]]; then
echo "One or more source files are not formatted!"
exit 1
fi

echo "All source files are formatted"
exit
11 changes: 11 additions & 0 deletions .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: ci
on: [push]
jobs:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: format code
run: tools/format_code.sh
- name: check diff
run: .github/format_check_diff.sh
4 changes: 3 additions & 1 deletion DogTales/src/components/physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace component {
void Physics::tick(bave::Seconds dt) {
static constexpr bave::Seconds ft{0.005}; // 5ms

if (dt.count() > tick_limit_v.count()) { return; } // return for unexpected dt values, particularly during the beginning of the state
if (dt.count() > tick_limit_v.count()) {
return;
} // return for unexpected dt values, particularly during the beginning of the state

for (dt += m_residue; dt > ft; dt -= ft) { integrate(ft); }
m_residue = dt;
Expand Down
4 changes: 2 additions & 2 deletions DogTales/src/components/physics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Physics {
bave::Seconds m_residue{};

public:

Physics(glm::vec2 friction = default_friction, float gravity = default_gravity, float mass = default_mass) : friction(friction), gravity(gravity), mass(mass) {}
Physics(glm::vec2 friction = default_friction, float gravity = default_gravity, float mass = default_mass)
: friction(friction), gravity(gravity), mass(mass) {}

glm::vec2 position{};
glm::vec2 velocity{};
Expand Down
8 changes: 6 additions & 2 deletions DogTales/src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ void Player::handle_wall_collision() {
auto const bounce_rect = bave::Rect<>::from_size(m_world_space - m_sprite.get_size(), glm::vec2{0.0f});

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

// clamp the position to the play area.
// bottom_left() gives us the minimum x and y whereas top_right() gives us the maximum.
Expand Down
23 changes: 23 additions & 0 deletions tools/format_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

[[ ! $(clang-format --version) ]] && exit 1

script_path=${0%/*}
tools_root=${script_path%/*}
project_root=$tools_root/..

if [[ "$0" != "$project_root" ]] && [[ "$project_root" != "" ]]; then
cd "$project_root" || exit 1
echo "-- Changed pwd to $(pwd)"
fi

files=$(find DogTales -name "*.?pp")
if [[ "$files" == "" ]]; then
echo "-- No source files found"
exit
fi

clang-format -i $files
echo -e "-- Formatted Files:\n$files\n"

exit

0 comments on commit a39f6eb

Please sign in to comment.