use crate::components::{ChunkPosition, Position, Rotation};
#[derive(Debug, Clone)]
pub struct PlayerMovedEvent {
pub position: Position,
pub rotation: Rotation,
pub on_ground: bool,
pub old_chunk: ChunkPosition,
}
crate::game_event!(PlayerMovedEvent);
#[derive(Debug, Clone)]
pub struct PlayerJoinedEvent;
crate::game_event!(PlayerJoinedEvent);
#[derive(Debug, Clone)]
pub struct PlayerLeftEvent;
crate::game_event!(PlayerLeftEvent);
#[cfg(test)]
mod tests {
use crate::events::Event;
use super::*;
#[test]
fn player_moved_not_cancellable() {
let mut event = PlayerMovedEvent {
position: Position {
x: 0.0,
y: 64.0,
z: 0.0,
},
rotation: Rotation {
yaw: 0.0,
pitch: 0.0,
},
on_ground: true,
old_chunk: ChunkPosition { x: 0, z: 0 },
};
event.cancel(); assert!(!event.is_cancelled());
}
#[test]
fn event_routing() {
use crate::events::{BusKind, EventRouting};
assert_eq!(PlayerMovedEvent::BUS, BusKind::Game);
assert_eq!(PlayerJoinedEvent::BUS, BusKind::Game);
assert_eq!(PlayerLeftEvent::BUS, BusKind::Game);
}
}