basalt_api/events/
player.rs1use crate::components::{ChunkPosition, Position, Rotation};
4
5#[derive(Debug, Clone)]
11pub struct PlayerMovedEvent {
12 pub position: Position,
14 pub rotation: Rotation,
16 pub on_ground: bool,
18 pub old_chunk: ChunkPosition,
20}
21crate::game_event!(PlayerMovedEvent);
22
23#[derive(Debug, Clone)]
28pub struct PlayerJoinedEvent;
29crate::game_event!(PlayerJoinedEvent);
30
31#[derive(Debug, Clone)]
36pub struct PlayerLeftEvent;
37crate::game_event!(PlayerLeftEvent);
38
39#[cfg(test)]
40mod tests {
41 use crate::events::Event;
42
43 use super::*;
44
45 #[test]
46 fn player_moved_not_cancellable() {
47 let mut event = PlayerMovedEvent {
48 position: Position {
49 x: 0.0,
50 y: 64.0,
51 z: 0.0,
52 },
53 rotation: Rotation {
54 yaw: 0.0,
55 pitch: 0.0,
56 },
57 on_ground: true,
58 old_chunk: ChunkPosition { x: 0, z: 0 },
59 };
60 event.cancel(); assert!(!event.is_cancelled());
62 }
63
64 #[test]
65 fn event_routing() {
66 use crate::events::{BusKind, EventRouting};
67 assert_eq!(PlayerMovedEvent::BUS, BusKind::Game);
68 assert_eq!(PlayerJoinedEvent::BUS, BusKind::Game);
69 assert_eq!(PlayerLeftEvent::BUS, BusKind::Game);
70 }
71}