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

Fix event struct type names #643

Merged
merged 1 commit into from
Jul 24, 2023
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
14 changes: 7 additions & 7 deletions crates/controller/src/commands/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use crate::{
draft::{DiscardDraftsEvent, DraftSet, NewDraftEvent, SpawnDraftsEvent},
hud::{GameMenuSet, ToggleGameMenu, UpdateSelectionBoxEvent},
mouse::{
DragUpdateType, MouseClicked, MouseDoubleClicked, MouseDragged, MouseSet, Pointer,
PointerSet,
DragUpdateType, MouseClickedEvent, MouseDoubleClickedEvent, MouseDraggedEvent, MouseSet,
Pointer, PointerSet,
},
selection::{
AreaSelectSet, SelectEvent, SelectInRectEvent, Selected, SelectionMode, SelectionSet,
Expand Down Expand Up @@ -172,16 +172,16 @@ pub(crate) enum HandlersSet {
LeftClick,
}

fn on_click(button: MouseButton) -> impl Fn(EventReader<MouseClicked>) -> bool {
move |mut events: EventReader<MouseClicked>| {
fn on_click(button: MouseButton) -> impl Fn(EventReader<MouseClickedEvent>) -> bool {
move |mut events: EventReader<MouseClickedEvent>| {
// It is desirable to exhaust the iterator, thus .filter().count() is
// used instead of .any()
events.iter().filter(|e| e.button() == button).count() > 0
}
}

fn on_double_click(button: MouseButton) -> impl Fn(EventReader<MouseDoubleClicked>) -> bool {
move |mut events: EventReader<MouseDoubleClicked>| {
fn on_double_click(button: MouseButton) -> impl Fn(EventReader<MouseDoubleClickedEvent>) -> bool {
move |mut events: EventReader<MouseDoubleClickedEvent>| {
// It is desirable to exhaust the iterator, thus .filter().count() is
// used instead of .any()
events.iter().filter(|e| e.button() == button).count() > 0
Expand Down Expand Up @@ -425,7 +425,7 @@ fn select_all_visible(mut events: EventWriter<SelectInRectEvent>) {

fn update_drags(
keys: Res<Input<KeyCode>>,
mut drag_events: EventReader<MouseDragged>,
mut drag_events: EventReader<MouseDraggedEvent>,
mut ui_events: EventWriter<UpdateSelectionBoxEvent>,
mut select_events: EventWriter<SelectInRectEvent>,
) {
Expand Down
36 changes: 18 additions & 18 deletions crates/controller/src/mouse/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pub(super) struct InputPlugin;

impl Plugin for InputPlugin {
fn build(&self, app: &mut App) {
app.add_event::<MouseClicked>()
.add_event::<MouseDoubleClicked>()
.add_event::<MouseDragged>()
app.add_event::<MouseClickedEvent>()
.add_event::<MouseDoubleClickedEvent>()
.add_event::<MouseDraggedEvent>()
.add_system(setup.in_schedule(OnEnter(AppState::InGame)))
.add_system(cleanup.in_schedule(OnExit(AppState::InGame)))
.add_system(
Expand Down Expand Up @@ -59,12 +59,12 @@ pub(crate) enum MouseSet {
Buttons,
}

pub(crate) struct MouseClicked {
pub(crate) struct MouseClickedEvent {
button: MouseButton,
position: Vec2,
}

impl MouseClicked {
impl MouseClickedEvent {
fn new(button: MouseButton, position: Vec2) -> Self {
Self { button, position }
}
Expand All @@ -78,11 +78,11 @@ impl MouseClicked {
}
}

pub(crate) struct MouseDoubleClicked {
pub(crate) struct MouseDoubleClickedEvent {
button: MouseButton,
}

impl MouseDoubleClicked {
impl MouseDoubleClickedEvent {
fn new(button: MouseButton) -> Self {
Self { button }
}
Expand All @@ -92,13 +92,13 @@ impl MouseDoubleClicked {
}
}

pub(crate) struct MouseDragged {
pub(crate) struct MouseDraggedEvent {
button: MouseButton,
rect: Option<ScreenRect>,
update_type: DragUpdateType,
}

impl MouseDragged {
impl MouseDraggedEvent {
fn new(button: MouseButton, rect: Option<ScreenRect>, update_type: DragUpdateType) -> Self {
Self {
button,
Expand Down Expand Up @@ -263,31 +263,31 @@ fn update_position(
fn update_drags(
mouse_position: Res<MousePosition>,
mut mouse_state: ResMut<MouseDragStates>,
mut drags: EventWriter<MouseDragged>,
mut drags: EventWriter<MouseDraggedEvent>,
) {
let resolutions = mouse_state.update(mouse_position.ndc());
for (&button, &rect) in resolutions.iter() {
drags.send(MouseDragged::new(button, rect, DragUpdateType::Moved));
drags.send(MouseDraggedEvent::new(button, rect, DragUpdateType::Moved));
}
}

fn update_buttons(
mouse_position: Res<MousePosition>,
mut mouse_state: ResMut<MouseDragStates>,
mut input_events: EventReader<MouseButtonInput>,
mut clicks: EventWriter<MouseClicked>,
mut drags: EventWriter<MouseDragged>,
mut clicks: EventWriter<MouseClickedEvent>,
mut drags: EventWriter<MouseDraggedEvent>,
) {
for event in input_events.iter() {
match event.state {
ButtonState::Released => {
if let Some(drag_resolution) = mouse_state.resolve(event.button) {
match drag_resolution {
DragResolution::Point(position) => {
clicks.send(MouseClicked::new(event.button, position));
clicks.send(MouseClickedEvent::new(event.button, position));
}
DragResolution::Rect(rect) => {
drags.send(MouseDragged::new(
drags.send(MouseDraggedEvent::new(
event.button,
rect,
DragUpdateType::Released,
Expand All @@ -304,8 +304,8 @@ fn update_buttons(
}

fn check_double_click(
mut clicks: EventReader<MouseClicked>,
mut double_clicks: EventWriter<MouseDoubleClicked>,
mut clicks: EventReader<MouseClickedEvent>,
mut double_clicks: EventWriter<MouseDoubleClickedEvent>,
mut last_click_position: Local<Option<Vec2>>,
mut last_click_time: Local<f64>,
time: Res<Time>,
Expand All @@ -318,7 +318,7 @@ fn check_double_click(
}) {
// Check if double click using timer
if (current_time - *last_click_time) < DOUBLE_CLICK_TIME {
double_clicks.send(MouseDoubleClicked::new(mouse_clicked.button()));
double_clicks.send(MouseDoubleClickedEvent::new(mouse_clicked.button()));
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/controller/src/mouse/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use bevy::prelude::*;
use input::InputPlugin;
pub(crate) use input::{
DragUpdateType, MouseClicked, MouseDoubleClicked, MouseDragged, MousePosition, MouseSet,
DragUpdateType, MouseClickedEvent, MouseDoubleClickedEvent, MouseDraggedEvent, MousePosition,
MouseSet,
};
use pointer::PointerPlugin;
pub(crate) use pointer::{Pointer, PointerSet};
Expand Down