Skip to content

Commit db4750b

Browse files
committed
refactor:pass linter
1 parent 998cd3e commit db4750b

File tree

17 files changed

+29
-32
lines changed

17 files changed

+29
-32
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ If you want to commit changes,please obey the following steps:
2626

2727
## Tests
2828

29-
For your code,your should write necessary tests to cover your code in both GDScript and Rust.We use Github Action to run the tests
29+
For your code,you should write necessary tests to cover your code in both GDScript and Rust.We use Github Action to run the tests
3030

3131
[Rust Test Guide](./docs/rust_test.md)
3232

docs/rust_test.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ impl xxx {
2626
}
2727
```
2828

29-
Like this,the function marked by `#[debug]` will be ran in debug mode at the place of `debug_check!()` macro.
29+
Like this,the function marked by `#[debug]` will be running in debug mode at the place of `debug_check!()` macro.

gdrust/server/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,21 @@ impl Connection {
4646
let sz = self.stream.read_buf(&mut self.buffer).await?;
4747
log::info!("Received:{}", sz);
4848
if 0 == sz {
49-
if self.buffer.is_empty() {
49+
return if self.buffer.is_empty() {
5050
log::info!("Join exiting(empty)...");
51-
return Ok(None);
51+
Ok(None)
5252
} else {
5353
let msg = "Connection reset by peer";
5454
log::info!("{}", msg);
55-
return Err(anyhow!(msg));
56-
}
55+
Err(anyhow!(msg))
56+
};
5757
}
5858
}
5959
}
6060

6161
pub fn parse_join(&mut self) -> anyhow::Result<Option<Join>> {
6262
let buf = Cursor::new(&self.buffer[..]);
63-
match proto::connect::Join::decode(buf) {
63+
match Join::decode(buf) {
6464
Ok(val) => Ok(Some(val)),
6565
Err(_) => Err(anyhow!("Not a join message")),
6666
}
@@ -74,13 +74,13 @@ impl Connection {
7474
if let Some(request) = self.parse_request()? {}
7575
let sz = self.stream.read_buf(&mut self.buffer).await?;
7676
if 0 == sz {
77-
if self.buffer.is_empty() {
78-
return Ok(());
77+
return if self.buffer.is_empty() {
78+
Ok(())
7979
} else {
8080
let msg = "Connection reset by peer";
8181
log::info!("{}", msg);
82-
return Err(anyhow!(msg));
83-
}
82+
Err(anyhow!(msg))
83+
};
8484
}
8585
}
8686
}

gdrust/src/bullets/star_wrath_bullet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use godot::engine::{Area2D, IArea2D};
1+
use godot::classes::{Area2D, IArea2D};
22
use godot::obj::WithBaseField;
33
use godot::prelude::*;
44
use rand::{thread_rng, Rng};
@@ -47,7 +47,7 @@ impl StarWrathBullet {
4747
}
4848

4949
fn random_speed(&mut self) {
50-
self.speed = rand::thread_rng().gen_range(SPEED_MIN..=SPEED_MAX);
50+
self.speed = thread_rng().gen_range(SPEED_MIN..=SPEED_MAX);
5151
}
5252

5353
fn base_init(&mut self, rad: f32) {

gdrust/src/fight.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::debug_check;
2-
use godot::engine::{Control, IControl, Sprite2D, Timer};
2+
use godot::classes::{Control, IControl, Sprite2D, Timer};
33
use godot::obj::WithBaseField;
44
use godot::prelude::*;
55
use rand::Rng;

gdrust/src/fight_items/bar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use godot::engine::{Control, IControl};
1+
use godot::classes::{Control, IControl};
22
use godot::prelude::*;
33

44
#[derive(GodotClass)]

gdrust/src/fight_items/block_drawer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use godot::engine::{Area2D, CollisionPolygon2D, INode2D, Node2D, StaticBody2D};
1+
use godot::classes::{Area2D, CollisionPolygon2D, INode2D, Node2D, StaticBody2D};
22
use godot::obj::{NewAlloc, WithBaseField};
33
use godot::prelude::*;
44

gdrust/src/fight_items/health_bar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use godot::engine::{INode2D, Node2D};
1+
use godot::classes::{INode2D, Node2D};
22
use godot::obj::WithBaseField;
33
use godot::prelude::*;
44

gdrust/src/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::multi::MultiManager;
2-
use godot::engine::{INode, Node};
2+
use godot::classes::{INode, Node};
33
use godot::prelude::*;
44

55
#[derive(GodotClass)]

gdrust/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod zenith;
1313
use godot::prelude::*;
1414
use multi::{MultiManager, MultiManagerImpl};
1515
use std::{
16-
panic::{set_hook, PanicInfo},
16+
panic::{set_hook, PanicHookInfo},
1717
sync::{Arc, Mutex, OnceLock},
1818
};
1919
use tokio::runtime::{Builder, Runtime};
@@ -31,7 +31,7 @@ fn get_tokio_runtime() -> &'static Runtime {
3131
TMP.get_or_init(|| Builder::new_multi_thread().enable_all().build().unwrap())
3232
}
3333

34-
fn panic_handler(info: &PanicInfo) {
34+
fn panic_handler(info: &PanicHookInfo) {
3535
if let Some(p) = info.location() {
3636
godot_error!(
3737
"Panic occurred in file '{}' at line {}\n",

gdrust/src/multi.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use ::proto::ProtoRequest;
22
use anyhow::anyhow;
33
use bytes::{Bytes, BytesMut};
4-
use godot::engine::{INode, Node};
4+
use godot::classes::{INode, Node};
55
use godot::prelude::*;
66
use prost::Message;
77
use proto::connect::Join;
8-
use proto::proto;
98
use std::collections::HashMap;
109
use tokio::io::{AsyncReadExt, AsyncWriteExt};
1110
use tokio::net::tcp::{OwnedReadHalf, OwnedWriteHalf};
@@ -26,7 +25,7 @@ enum Requests {
2625

2726
pub struct MultiManagerImpl {
2827
clients: HashMap<usize, MultiPlayerConnection>,
29-
socket: Option<mpsc::Sender<bytes::Bytes>>,
28+
socket: Option<mpsc::Sender<Bytes>>,
3029
receiver: Option<std::sync::mpsc::Receiver<Requests>>,
3130
}
3231

@@ -75,7 +74,7 @@ async fn read_loop(
7574
}
7675

7776
fn parse_request(buf: &BytesMut) -> Option<Requests> {
78-
match proto::connect::Join::decode(&buf[..]) {
77+
match Join::decode(&buf[..]) {
7978
Ok(v) => Some(Requests::Proto(ProtoRequest::Join(v))),
8079
Err(_) => None,
8180
}
@@ -114,7 +113,7 @@ impl MultiManagerImpl {
114113
player_name,
115114
version: base::build::COMMIT_HASH.to_string(),
116115
};
117-
let mut buf = bytes::BytesMut::new();
116+
let mut buf = BytesMut::new();
118117
data.encode(&mut buf)?;
119118
let sender = socket.clone();
120119
get_tokio_runtime().spawn(send(sender, buf));

gdrust/src/player.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use core::panic;
22
use derive::gen_debug;
3-
use godot::engine::{Area2D, CharacterBody2D, GpuParticles2D, ICharacterBody2D, Timer};
4-
use godot::global::abs;
3+
use godot::classes::{Area2D, CharacterBody2D, GpuParticles2D, ICharacterBody2D, Timer};
54
use godot::obj::WithBaseField;
65
use godot::prelude::*;
76
use real_consts::PI;

gdrust/src/ui/multi_enter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{debug_check, get_multi_single};
22
use derive::gen_debug;
3-
use godot::engine::{AcceptDialog, Button, IButton};
3+
use godot::classes::{AcceptDialog, Button, IButton};
44
use godot::obj::WithBaseField;
55
use godot::prelude::*;
66
use std::net::TcpStream;

gdrust/src/weapons.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
mod enchanted_sword;
22
mod star_wrath;
3-

gdrust/src/weapons/enchanted_sword.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use godot::{
2-
engine::{ISprite2D, Sprite2D},
2+
classes::{ISprite2D, Sprite2D},
33
prelude::*,
44
};
55
use std::collections::HashMap;

gdrust/src/weapons/star_wrath.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::bullets::star_wrath_bullet::StarWrathBullet;
22
use crate::debug_check;
3-
use godot::engine::{AnimationPlayer, AnimationTree, Area2D, IArea2D, Timer};
3+
use godot::classes::{AnimationTree, Area2D, IArea2D, Timer};
44
use godot::obj::WithBaseField;
55
use godot::prelude::*;
66

gdrust/src/zenith.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use godot::engine::{Area2D, IArea2D};
1+
use godot::classes::{Area2D, IArea2D};
22
use godot::prelude::*;
33

44
#[derive(GodotClass)]

0 commit comments

Comments
 (0)