Skip to content

Commit 434df72

Browse files
committed
derive common traits, improve documentation
1 parent ac6a841 commit 434df72

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
<!-- next-header -->
22
## [Unreleased] - ReleaseDate
33

4+
### Improved
5+
6+
- Implemented all the [common traits](https://rust-lang.github.io/api-guidelines/interoperability.html) on public `struct`s and `enum`s that made sense.
7+
- Added documentation for a few structs, enums, and methods that were missing it.
8+
49
### Fixed
510

611
- The `collider` example once again properly regenerates the visualization for circle colliders whenever they are created or altered.
12+
- Changed visibility of internal Bevy plugins from `pub` to `pub(crate)`. Technically this is a breaking change, but these wouldn't have been usable to anyone anyway so I'm ignoring the technicality.
713

814
## [5.0.0] - 2022-03-12
915

src/keyboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bevy::{prelude::*, utils::HashMap};
44
// Re-export some Bevy types to use
55
pub use bevy::input::keyboard::{KeyCode, KeyboardInput};
66

7-
pub struct KeyboardPlugin;
7+
pub(crate) struct KeyboardPlugin;
88

99
impl Plugin for KeyboardPlugin {
1010
fn build(&self, app: &mut bevy::prelude::App) {

src/mouse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub use bevy::{
1010
window::CursorMoved,
1111
};
1212

13-
pub struct MousePlugin;
13+
pub(crate) struct MousePlugin;
1414

1515
impl Plugin for MousePlugin {
1616
fn build(&self, app: &mut bevy::prelude::App) {
@@ -41,7 +41,7 @@ pub struct MouseState {
4141
/// the mouse wheel as if scrolling in a direction were equivalent to clicking a mouse button, you
4242
/// probably want to use
4343
/// [`Engine::mouse_wheel_events`](crate::prelude::Engine::mouse_wheel_events) instead.
44-
#[derive(Clone, Copy, Debug, Default)]
44+
#[derive(Clone, Copy, Debug, Default, PartialEq)]
4545
pub struct MouseWheelState {
4646
/// The y component of the mouse wheel movement. This is the "normal" scrolling direction of a
4747
/// typical mouse wheel. This will be either `-1.0`, `0.0`, or `1.0`. For fine-grained

src/physics.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
hash::Hash,
88
};
99

10-
pub struct PhysicsPlugin;
10+
pub(crate) struct PhysicsPlugin;
1111

1212
impl Plugin for PhysicsPlugin {
1313
fn build(&self, app: &mut App) {
@@ -20,13 +20,14 @@ impl Plugin for PhysicsPlugin {
2020
/// [Sprite]s which:
2121
/// - have colliders (you can use the `collider` example to create your own colliders)
2222
/// - have their `collision` flags set to `true`.
23-
#[derive(Debug, Clone)]
23+
#[derive(Clone, Debug, PartialEq)]
2424
pub struct CollisionEvent {
2525
pub state: CollisionState,
2626
pub pair: CollisionPair,
2727
}
2828

29-
#[derive(Debug, Clone, Copy)]
29+
/// Indicates whether a [`CollisionEvent`] is at the beginning or ending of a collision.
30+
#[derive(Clone, Copy, Debug, PartialEq)]
3031
pub enum CollisionState {
3132
Begin,
3233
End,
@@ -47,22 +48,27 @@ impl CollisionState {
4748
}
4849
}
4950

51+
/// Contains the labels of the two sprites involved in the collision. As the labels are unordered,
52+
/// several convenience methods are provided for searching the values.
5053
#[derive(Debug, Default, Eq, Clone)]
5154
pub struct CollisionPair(pub String, pub String);
5255

5356
impl CollisionPair {
54-
pub fn either_contains<T: Into<String>>(&self, label: T) -> bool {
55-
let label = label.into();
56-
(self.0 == label) || (self.1 == label)
57+
/// Whether either of the labels contains the text.
58+
pub fn either_contains<T: Into<String>>(&self, text: T) -> bool {
59+
let text = text.into();
60+
(self.0 == text) || (self.1 == text)
5761
}
58-
pub fn either_starts_with<T: Into<String>>(&self, label: T) -> bool {
59-
let label = label.into();
60-
self.0.starts_with(&label) || self.1.starts_with(&label)
62+
/// Whether either of the labels starts with the text.
63+
pub fn either_starts_with<T: Into<String>>(&self, text: T) -> bool {
64+
let text = text.into();
65+
self.0.starts_with(&text) || self.1.starts_with(&text)
6166
}
62-
pub fn one_starts_with<T: Into<String>>(&self, label: T) -> bool {
63-
let label = label.into();
64-
let a_matches = self.0.starts_with(&label);
65-
let b_matches = self.1.starts_with(&label);
67+
/// Whether exactly one of the labels starts with the text.
68+
pub fn one_starts_with<T: Into<String>>(&self, text: T) -> bool {
69+
let text = text.into();
70+
let a_matches = self.0.starts_with(&text);
71+
let b_matches = self.1.starts_with(&text);
6672
(a_matches && !b_matches) || (!a_matches && b_matches)
6773
}
6874
}

src/sprite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::physics::Collider;
44

55
/// A [`Sprite`] is the basic abstraction for something that can be seen and interacted with.
66
/// Players, obstacles, etc. are all sprites.
7-
#[derive(Clone, Component, Debug)]
7+
#[derive(Clone, Component, Debug, PartialEq)]
88
pub struct Sprite {
99
/// READONLY: A way to identify a sprite.
1010
pub label: String,

src/text.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub const TEXT_DEFAULT_LAYER: f32 = 900.0;
77
pub const TEXT_DEFAULT_FONT_SIZE: f32 = 30.0;
88

99
/// A [`Text`] is a bit of text that exists on the screen.
10-
#[derive(Clone, Component, Debug)]
10+
#[derive(Clone, Component, Debug, PartialEq)]
1111
pub struct Text {
1212
/// READONLY: A label to identify the text. This is not the text that is displayed! This is the
1313
/// label you use to retrieve and modify your text from the

0 commit comments

Comments
 (0)