Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting and Linting #73

Merged
merged 5 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ on: [push, pull_request]
name: Compilation check

jobs:

fmt:
runs-on: ubuntu-latest
name: Formatting
steps:
- uses: actions/checkout@v2
- name: Check Rust formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
runs-on: ubuntu-latest
name: Linting
steps:
- uses: actions/checkout@v2
- name: Install Clippy
run: rustup component add clippy

- name: Run Clippy
run: cargo clippy -- -W clippy::pedantic

build:
name: Build
runs-on: ${{ matrix.config.os }}
Expand Down
8 changes: 6 additions & 2 deletions gamepad-rs/src/platform/linux/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub const DIRMASK: u32 = (1 << DIRBITS) - 1;
pub const fn ioc(dir: u64, ty: u64, nr: u64, sz: u64) -> u64 {
(((dir as u32) << DIRSHIFT)
| ((ty as u32) << TYPESHIFT)
| ((nr as u32) << NRSHIFT)
| ((nr as u32) << NRSHIFT)
| ((sz as u32) << SIZESHIFT)) as u64
}

Expand Down Expand Up @@ -131,5 +131,9 @@ impl ::std::default::Default for input_absinfo {
}

pub const fn eviocgabs(abs: u32) -> ::libc::c_ulong {
ior(b'E' as _, (0x40 + abs) as _, std::mem::size_of::<input_absinfo>() as _) as ::libc::c_ulong
ior(
b'E' as _,
(0x40 + abs) as _,
std::mem::size_of::<input_absinfo>() as _,
) as ::libc::c_ulong
}
11 changes: 7 additions & 4 deletions gamepad-rs/src/platform/macos/hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use core_foundation::array::{CFArray, CFArrayRef};
use core_foundation::base::{CFGetTypeID, CFRetain, TCFType};
use core_foundation::dictionary::CFDictionary;
use core_foundation::number::{kCFNumberSInt32Type, CFNumber, CFNumberGetValue};
use core_foundation::runloop::{kCFRunLoopRunHandledSource, CFRunLoopGetCurrent, CFRunLoopRunInMode};
use core_foundation::runloop::{
kCFRunLoopRunHandledSource, CFRunLoopGetCurrent, CFRunLoopRunInMode,
};
use core_foundation::string::CFString;

use io_kit;
Expand Down Expand Up @@ -363,9 +365,9 @@ impl Device {
}
_ => (),
},
io_kit_const::kHIDPage_Button |
io_kit_const::kHIDPage_Button |
// e.g. 'pause' button on Steelseries MFi gamepads.
io_kit_const::kHIDPage_Consumer => {
io_kit_const::kHIDPage_Consumer => {
if !self.contain_element(cookie) {
self.buttons.push(HIDElement {
usage,
Expand Down Expand Up @@ -422,7 +424,8 @@ impl Device {
};

// Filter device list to non-keyboard/mouse stuff
if usage != kHIDUsage_GD_Joystick as i32 && usage != kHIDUsage_GD_GamePad as i32
if usage != kHIDUsage_GD_Joystick as i32
&& usage != kHIDUsage_GD_GamePad as i32
&& usage != kHIDUsage_GD_MultiAxisController as i32
{
return None;
Expand Down
6 changes: 4 additions & 2 deletions gamepad-rs/src/platform/macos/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod hid;

use super::super::{ControllerInfo, ControllerState, ControllerStatus, DEFAULT_CONTROLLER_INFO,
DEFAULT_CONTROLLER_STATE, MAX_ANALOG, MAX_DEVICES, MAX_DIGITAL};
use super::super::{
ControllerInfo, ControllerState, ControllerStatus, DEFAULT_CONTROLLER_INFO,
DEFAULT_CONTROLLER_STATE, MAX_ANALOG, MAX_DEVICES, MAX_DIGITAL,
};

pub struct ControllerContext {
info: Vec<ControllerInfo>,
Expand Down
20 changes: 11 additions & 9 deletions gamepad-rs/src/platform/windows/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use std::mem;

use winapi::shared::winerror::ERROR_SUCCESS;
use winapi::um::xinput::{self, XINPUT_CAPABILITIES as XCapabilities, XINPUT_STATE as XState,
XINPUT_FLAG_GAMEPAD, XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B,
XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_DPAD_DOWN, XINPUT_GAMEPAD_DPAD_LEFT,
XINPUT_GAMEPAD_DPAD_RIGHT, XINPUT_GAMEPAD_DPAD_UP,
XINPUT_GAMEPAD_LEFT_SHOULDER, XINPUT_GAMEPAD_LEFT_THUMB,
XINPUT_GAMEPAD_RIGHT_SHOULDER, XINPUT_GAMEPAD_RIGHT_THUMB,
XINPUT_GAMEPAD_START, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y};
use winapi::um::xinput::{
self, XINPUT_CAPABILITIES as XCapabilities, XINPUT_FLAG_GAMEPAD, XINPUT_GAMEPAD_A,
XINPUT_GAMEPAD_B, XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_DPAD_DOWN, XINPUT_GAMEPAD_DPAD_LEFT,
XINPUT_GAMEPAD_DPAD_RIGHT, XINPUT_GAMEPAD_DPAD_UP, XINPUT_GAMEPAD_LEFT_SHOULDER,
XINPUT_GAMEPAD_LEFT_THUMB, XINPUT_GAMEPAD_RIGHT_SHOULDER, XINPUT_GAMEPAD_RIGHT_THUMB,
XINPUT_GAMEPAD_START, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y, XINPUT_STATE as XState,
};

use super::super::{ControllerInfo, ControllerState, ControllerStatus, DEFAULT_CONTROLLER_INFO,
DEFAULT_CONTROLLER_STATE, MAX_DEVICES, MAX_DIGITAL};
use super::super::{
ControllerInfo, ControllerState, ControllerStatus, DEFAULT_CONTROLLER_INFO,
DEFAULT_CONTROLLER_STATE, MAX_DEVICES, MAX_DIGITAL,
};

pub struct ControllerContext {
info: Vec<ControllerInfo>,
Expand Down
10 changes: 3 additions & 7 deletions src/circle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use macroquad::math::{Vec2, Rect, vec2};
use macroquad::math::{vec2, Rect, Vec2};

pub struct Circle {
x: f32,
Expand All @@ -8,11 +8,7 @@ pub struct Circle {

impl Circle {
pub fn new(x: f32, y: f32, r: f32) -> Self {
Circle {
x,
y,
r,
}
Circle { x, y, r }
}

pub fn point(&self) -> Vec2 {
Expand Down Expand Up @@ -44,7 +40,7 @@ impl Circle {
pub fn overlaps_rect(&self, rect: &Rect) -> bool {
let dist_x = (self.x - rect.x).abs();
let dist_y = (self.y - rect.y).abs();
if dist_x > rect.w / 2.0 + self.r || dist_y > rect.h / 2.0 + self.r {
if dist_x > rect.w / 2.0 + self.r || dist_y > rect.h / 2.0 + self.r {
return false;
}
if dist_x <= rect.w / 2.0 || dist_y <= rect.h / 2.0 {
Expand Down
4 changes: 2 additions & 2 deletions src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ mod muscet;
pub mod player;
mod raining_shark;
mod score_counter;
mod seaweed;
mod shark;
mod shoes;
mod sproinger;
mod sword;
mod turtleshell;
mod volcano;
mod seaweed;

pub use armed_grenade::ArmedGrenade;
pub use armed_kick_bomb::ArmedKickBomb;
Expand Down Expand Up @@ -62,10 +62,10 @@ pub use muscet::Muscet;
pub use player::Player;
pub use raining_shark::RainingShark;
pub use score_counter::ScoreCounter;
pub use seaweed::Seaweed;
pub use shark::Shark;
pub use shoes::Shoes;
pub use sproinger::Sproinger;
pub use sword::Sword;
pub use turtleshell::TurtleShell;
pub use volcano::Volcano;
pub use seaweed::Seaweed;
66 changes: 33 additions & 33 deletions src/nodes/armed_kick_bomb.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
use macroquad::{
color,
experimental::{
animation::{AnimatedSprite, Animation},
collections::storage,
scene::{
RefMut,
Node,
},
animation::{
AnimatedSprite,
Animation,
},
scene::{Node, RefMut},
},
color,
prelude::*,
};

use crate::circle::Circle;
use crate::{
nodes::player::{
Player,
PhysicsBody,
},
nodes::player::{PhysicsBody, Player},
nodes::sproinger::Sproingable,
Resources,
};
use crate::circle::Circle;

pub struct ArmedKickBomb {
sprite: AnimatedSprite,
Expand All @@ -42,14 +33,12 @@ impl ArmedKickBomb {
let sprite = AnimatedSprite::new(
28,
38,
&[
Animation {
name: "idle".to_string(),
row: 1,
frames: 4,
fps: 8,
},
],
&[Animation {
name: "idle".to_string(),
row: 1,
frames: 4,
fps: 8,
}],
false,
);

Expand All @@ -73,11 +62,11 @@ impl ArmedKickBomb {
vec2(-50., 10.)
};

body.collider = Some(resources.collision_world.add_actor(
body.pos + mount_pos,
30,
30,
));
body.collider = Some(
resources
.collision_world
.add_actor(body.pos + mount_pos, 30, 30),
);

ArmedKickBomb {
sprite,
Expand All @@ -97,15 +86,23 @@ impl Node for ArmedKickBomb {
node.provides::<Sproingable>((
node.handle().untyped(),
node.handle().lens(|node| &mut node.body),
vec2(ArmedKickBomb::COLLIDER_WIDTH, ArmedKickBomb::COLLIDER_HEIGHT),
vec2(
ArmedKickBomb::COLLIDER_WIDTH,
ArmedKickBomb::COLLIDER_HEIGHT,
),
));
}

fn fixed_update(mut node: RefMut<Self>) {
node.body.update();
node.lived += get_frame_time();

let hitbox = Rect::new(node.body.pos.x, node.body.pos.y, ArmedKickBomb::COLLIDER_WIDTH, ArmedKickBomb::COLLIDER_HEIGHT);
let hitbox = Rect::new(
node.body.pos.x,
node.body.pos.y,
ArmedKickBomb::COLLIDER_WIDTH,
ArmedKickBomb::COLLIDER_HEIGHT,
);

for mut player in scene::find_nodes_by_type::<Player>() {
if hitbox.overlaps(&player.get_hitbox()) {
Expand All @@ -118,10 +115,13 @@ impl Node for ArmedKickBomb {

if node.lived < ArmedKickBomb::COUNTDOWN_DURATION {
for player in scene::find_nodes_by_type::<crate::nodes::Player>() {
if player.body.speed.x >= ArmedKickBomb::KICK_SPEED_THRESHOLD || player.body.speed.x <= -ArmedKickBomb::KICK_SPEED_THRESHOLD {
let is_overlapping =
hitbox.overlaps(&player.get_hitbox());
if is_overlapping && hitbox.y + 36.0 >= player.body.pos.y + Player::LEGS_THRESHOLD {
if player.body.speed.x >= ArmedKickBomb::KICK_SPEED_THRESHOLD
|| player.body.speed.x <= -ArmedKickBomb::KICK_SPEED_THRESHOLD
{
let is_overlapping = hitbox.overlaps(&player.get_hitbox());
if is_overlapping
&& hitbox.y + 36.0 >= player.body.pos.y + Player::LEGS_THRESHOLD
{
let direction = node.body.pos.x > (player.body.pos.x + 10.);
if direction == player.body.facing {
node.body.speed.x = if direction {
Expand Down
39 changes: 13 additions & 26 deletions src/nodes/armed_mine.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
use macroquad::{
color,
experimental::{
animation::{AnimatedSprite, Animation},
collections::storage,
scene::RefMut,
animation::{
AnimatedSprite,
Animation,
},
},
color,
prelude::*,
};

use crate::{
nodes::player::{
PhysicsBody,
},
nodes::sproinger::Sproingable,
Resources,
};
use crate::circle::Circle;
use crate::{nodes::player::PhysicsBody, nodes::sproinger::Sproingable, Resources};

pub struct ArmedMine {
mine_sprite: AnimatedSprite,
Expand All @@ -36,14 +27,12 @@ impl ArmedMine {
let mine_sprite = AnimatedSprite::new(
26,
40,
&[
Animation {
name: "idle".to_string(),
row: 1,
frames: 10,
fps: 8,
},
],
&[Animation {
name: "idle".to_string(),
row: 1,
frames: 10,
fps: 8,
}],
false,
);

Expand Down Expand Up @@ -105,7 +94,9 @@ impl scene::Node for ArmedMine {
node.body.update();
node.lived += get_frame_time();

if node.lived >= ArmedMine::ARMED_AFTER_DURATION && node.mine_sprite.current_animation() != 1 {
if node.lived >= ArmedMine::ARMED_AFTER_DURATION
&& node.mine_sprite.current_animation() != 1
{
node.mine_sprite.playing = true;
}

Expand All @@ -115,11 +106,7 @@ impl scene::Node for ArmedMine {

if node.lived >= ArmedMine::ARMED_AFTER_DURATION {
let mut killed = false;
let trigger = Circle::new(
node.body.pos.x,
node.body.pos.y,
ArmedMine::TRIGGER_RADIUS,
);
let trigger = Circle::new(node.body.pos.x, node.body.pos.y, ArmedMine::TRIGGER_RADIUS);
for mut player in scene::find_nodes_by_type::<crate::nodes::Player>() {
let player_hitbox = player.get_hitbox();
if trigger.overlaps_rect(&player_hitbox) {
Expand Down
Loading