Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Mar 11, 2024
1 parent 52bdaa1 commit 9860468
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 108 deletions.
14 changes: 7 additions & 7 deletions crates/client/input/src/cursor_movement.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// Represents the movement of a cursor.
#[derive(Debug)]
pub enum CursorMovement {
/// Represents an absolute cursor movement.
Absolute,
/// Represents a relative cursor movement.
Relative,
/// Represents the end of cursor movement.
End,
}
/// Represents an absolute cursor movement.
Absolute,
/// Represents a relative cursor movement.
Relative,
/// Represents the end of cursor movement.
End,
}
68 changes: 35 additions & 33 deletions crates/client/input/src/keyboard_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,48 @@ use super::{Input, SlowDown};
pub struct KeyboardInput;

impl KeyboardInput {
/// Creates a new instance of `KeyboardInput`.
pub fn new_input() -> Input<KeyboardInput> {
Input::new(Self {})
}
/// Creates a new instance of `KeyboardInput`.
pub fn new_input() -> Input<KeyboardInput> {
Input::new(Self {})
}
}

impl Input<KeyboardInput> {
/// Returns the movement modifier based on the positive and negative flags.
pub fn get_movement_modifier(positive: bool, negative: bool) -> f32 {
if positive == negative {
0.0
} else {
if positive {
1.0
} else {
-1.0
}
}
}
/// Returns the movement modifier based on the positive and negative flags.
pub fn get_movement_modifier(positive: bool, negative: bool) -> f32 {
if positive == negative {
0.0
} else {
if positive {
1.0
} else {
-1.0
}
}
}
}

impl Input<KeyboardInput> {
fn tick(&mut self, slow_down: SlowDown) {
self.pressing_forward = false;
self.pressing_backward = false;
self.pressing_left = false;
self.pressing_right = false;
fn tick(&mut self, slow_down: SlowDown) {
self.pressing_forward = false;
self.pressing_backward = false;
self.pressing_left = false;
self.pressing_right = false;

self.movement_forward = Self::get_movement_modifier(self.pressing_forward, self.pressing_backward);
self.movement_sideways = Self::get_movement_modifier(self.pressing_left, self.pressing_right);
self.movement_forward =
Self::get_movement_modifier(self.pressing_forward, self.pressing_backward);
self.movement_sideways =
Self::get_movement_modifier(self.pressing_left, self.pressing_right);

self.jumping = false;
self.sneaking = false;
self.jumping = false;
self.sneaking = false;

match slow_down {
SlowDown::Yes(factor) => {
self.movement_forward *= factor;
self.movement_sideways *= factor;
}
SlowDown::No => (),
}
}
match slow_down {
SlowDown::Yes(factor) => {
self.movement_forward *= factor;
self.movement_sideways *= factor;
}
SlowDown::No => (),
}
}
}
4 changes: 1 addition & 3 deletions crates/client/input/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ pub enum SlowDown {
}

impl<T> SlowDownTickable for Input<T> {
fn tick(&mut self, _slow_down: SlowDown) {

}
fn tick(&mut self, _slow_down: SlowDown) {}
}

impl<T> Input<T> {
Expand Down
32 changes: 18 additions & 14 deletions crates/client/option/src/enums/cloud_render_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@ use super::ByUSizeId;
/// This type represents `net.minecraft.client.option.CloudRenderMode` (yarn).
#[derive(Debug, Sequence)]
pub enum CloudRenderMode {
/// Doesn't render clouds.
Off,
/// Render clouds faster.
Fast,
/// Render clouds fancier.
Fancy
/// Doesn't render clouds.
Off,
/// Render clouds faster.
Fast,
/// Render clouds fancier.
Fancy,
}

impl ByUSizeId for CloudRenderMode {}

impl Display for CloudRenderMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
CloudRenderMode::Off => "off",
CloudRenderMode::Fast => "fast",
CloudRenderMode::Fancy => "fancy",
})
}
}
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
CloudRenderMode::Off => "off",
CloudRenderMode::Fast => "fast",
CloudRenderMode::Fancy => "fancy",
}
)
}
}
7 changes: 5 additions & 2 deletions crates/client/option/src/enums/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ pub mod perspective;

/// If a [`Sequence`], often enums, implements this, it will be allowed to get items directly through [`usize`] indexes. Wrapping behavior is configurable.
pub trait ByUSizeId: Sequence {
/// Gets the [`usize`] id.
fn get_usize_id(&self) -> Option<usize> where Self: PartialEq {
/// Gets the [`usize`] id.
fn get_usize_id(&self) -> Option<usize>
where
Self: PartialEq,
{
let all = enum_iterator::all::<Self>().collect::<Vec<_>>();
all.iter().position(|value| value == self)
}
Expand Down
58 changes: 31 additions & 27 deletions crates/client/option/src/enums/perspective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,42 @@ use super::ByUSizeId;
/// This type represents `net.minecraft.client.option.Perspective` (yarn).
#[derive(Debug, Sequence, PartialEq)]
pub enum Perspective {
/// 1st person perspective.
FirstPerson,
/// 3rd person perspective, camera behind player.
ThirdPersonBack,
/// 3rd person perspective, camera in front of player.
ThirdPersonFront
/// 1st person perspective.
FirstPerson,
/// 3rd person perspective, camera behind player.
ThirdPersonBack,
/// 3rd person perspective, camera in front of player.
ThirdPersonFront,
}

impl ByUSizeId for Perspective {}

impl Display for Perspective {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
Perspective::FirstPerson => "first_person",
Perspective::ThirdPersonBack => "third_person_back",
Perspective::ThirdPersonFront => "third_person_front",
})
}
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Perspective::FirstPerson => "first_person",
Perspective::ThirdPersonBack => "third_person_back",
Perspective::ThirdPersonFront => "third_person_front",
}
)
}
}

impl Perspective {
pub fn is_first_person(&self) -> bool {
match self {
Perspective::FirstPerson => true,
_ => false
}
}

pub fn is_front_view(&self) -> bool {
match self {
Perspective::ThirdPersonBack => false,
_ => true
}
}
}
pub fn is_first_person(&self) -> bool {
match self {
Perspective::FirstPerson => true,
_ => false,
}
}

pub fn is_front_view(&self) -> bool {
match self {
Perspective::ThirdPersonBack => false,
_ => true,
}
}
}
4 changes: 2 additions & 2 deletions crates/client/option/src/tooltip_factory.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub trait TooltipFactory<T> {
fn apply(&self, value: T) -> Option<()>; // Option<Tooltip>
}
fn apply(&self, value: T) -> Option<()>; // Option<Tooltip>
}
2 changes: 1 addition & 1 deletion crates/flare3d/example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use flare3d::window::Window;

#[allow(unused_variables)]
fn main() {
let window = Window::new();
let window = Window::new();
}
5 changes: 4 additions & 1 deletion crates/flare3d/src/state/camera.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use glam::{Mat4, Quat, Vec3};
use winit::{event::{ElementState, KeyEvent, WindowEvent}, keyboard::{KeyCode, PhysicalKey}};
use winit::{
event::{ElementState, KeyEvent, WindowEvent},
keyboard::{KeyCode, PhysicalKey},
};

pub struct Camera {
pub eye: Vec3,
Expand Down
2 changes: 1 addition & 1 deletion crates/flare3d/src/state/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ impl InstanceRaw {
],
}
}
}
}
6 changes: 3 additions & 3 deletions crates/flare3d/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const INSTANCE_DISPLACEMENT: Vec3 = Vec3::new(
);

pub struct State<'s> {
pub window: Arc<Window>,
pub window: Arc<Window>,
pub size: winit::dpi::PhysicalSize<u32>,

surface: wgpu::Surface<'s>,
Expand All @@ -70,7 +70,7 @@ pub struct State<'s> {

impl<'s> State<'s> {
pub async fn new(event_loop: &EventLoop<()>) -> State<'s> {
let window = Arc::new(Window::new(event_loop).unwrap());
let window = Arc::new(Window::new(event_loop).unwrap());
let size = window.inner_size();

let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
Expand Down Expand Up @@ -285,7 +285,7 @@ impl<'s> State<'s> {
});

Self {
window,
window,
size,
surface,
device,
Expand Down
2 changes: 1 addition & 1 deletion crates/flare3d/src/state/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ impl Vertex {
],
}
}
}
}
10 changes: 3 additions & 7 deletions crates/flare3d/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Window<'w> {
impl<'w> Window<'w> {
pub fn new() -> Window<'w> {
let event_loop = EventLoop::new().unwrap();
let mut state = futures_executor::block_on(State::new(&event_loop));
let mut state = futures_executor::block_on(State::new(&event_loop));

#[cfg(target_os = "macos")]
let (_dl, semaphore) = {
Expand Down Expand Up @@ -52,9 +52,7 @@ impl<'w> Window<'w> {
state.update();
match state.render() {
Ok(_) => {}
Err(wgpu::SurfaceError::Lost) => {
state.resize(state.size)
}
Err(wgpu::SurfaceError::Lost) => state.resize(state.size),
Err(wgpu::SurfaceError::OutOfMemory) => target.exit(),
Err(e) => eprintln!("{:?}", e),
}
Expand Down Expand Up @@ -84,8 +82,6 @@ impl<'w> Window<'w> {
})
.unwrap();

Self {
state
}
Self { state }
}
}
8 changes: 4 additions & 4 deletions crates/util/identifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ pub struct Identifier<N, P> {
/// A generics wrapper for [`Identifier`].
/// The associated types [`Identifiers::N`] and [`Identifiers::P`] should be applied to [`Identifier`] when used.
pub trait Identifiers {
/// Generic `N` that should be applied to [`Identifier`].
type N;
/// Generic `P` that should be applied to [`Identifier`].
type P;
/// Generic `N` that should be applied to [`Identifier`].
type N;
/// Generic `P` that should be applied to [`Identifier`].
type P;
}

impl<N, P> Identifier<N, P> {
Expand Down
3 changes: 1 addition & 2 deletions crates/util/identifier/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn create_identifiers() {
let identifier = Identifier::new(Namespace::new("n"), path);
assert_eq!("n:a_b/42", identifier.to_string());

let identifier =
format_identifier!("namespace".parse().unwrap() => "a", "b"; "c"; "42");
let identifier = format_identifier!("namespace".parse().unwrap() => "a", "b"; "c"; "42");
assert_eq!("namespace:a_b/c/42", identifier.to_string());
}

0 comments on commit 9860468

Please sign in to comment.