Rename crate::events to crate::messages

Bevy 0.17 introduces this idea of "Messages" which mostly replace the
previous usage of "Events." The old events still exist, but are meant
more for targetted actions -- something happening and immediately
triggering a function call on an observer.
This commit is contained in:
2025-10-02 17:12:14 -05:00
parent 13643f73fb
commit cfe35c61ed
5 changed files with 17 additions and 17 deletions

View File

@@ -3,7 +3,7 @@
//! Compile-time configurables can be found in the [`config`] module. //! Compile-time configurables can be found in the [`config`] module.
pub mod config; pub mod config;
mod events; mod messages;
mod machinery; mod machinery;
mod objects; mod objects;
mod physics; mod physics;
@@ -77,10 +77,10 @@ impl Plugin for AsteroidPlugin {
) )
.run_if(in_state(GameState::Playing)), .run_if(in_state(GameState::Playing)),
) )
.add_event::<events::SpawnAsteroid>() .add_event::<messages::SpawnAsteroid>()
.add_event::<events::AsteroidDestroy>() .add_event::<messages::AsteroidDestroy>()
.add_event::<events::ShipDestroy>() .add_event::<messages::ShipDestroy>()
.add_event::<events::BulletDestroy>(); .add_event::<messages::BulletDestroy>();
app.insert_state(GameState::TitleScreen); app.insert_state(GameState::TitleScreen);
} }
} }

View File

@@ -8,7 +8,7 @@ use std::time::Duration;
use bevy::prelude::*; use bevy::prelude::*;
use crate::{WorldSize, events::{AsteroidDestroy, SpawnAsteroid}, objects::AsteroidSize, resources::Score}; use crate::{WorldSize, messages::{AsteroidDestroy, SpawnAsteroid}, objects::AsteroidSize, resources::Score};
/// Asteroid spawning parameters and state. /// Asteroid spawning parameters and state.
/// ///

View File

@@ -23,7 +23,7 @@ use bevy_rapier2d::prelude::{ActiveCollisionTypes, ActiveEvents, Collider, Senso
use crate::{ use crate::{
AngularVelocity, GameAssets, GameState, Lives, AngularVelocity, GameAssets, GameState, Lives,
config::{ASTEROID_LIFETIME, DEBRIS_LIFETIME, SHIP_FIRE_RATE}, config::{ASTEROID_LIFETIME, DEBRIS_LIFETIME, SHIP_FIRE_RATE},
events::{AsteroidDestroy, BulletDestroy, ShipDestroy, SpawnAsteroid}, messages::{AsteroidDestroy, BulletDestroy, ShipDestroy, SpawnAsteroid},
machinery::{Lifetime, Sparkler}, machinery::{Lifetime, Sparkler},
physics::{Velocity, Wrapping}, physics::{Velocity, Wrapping},
}; };

View File

@@ -16,7 +16,7 @@
//! to detect them for me (so that I don't have to write clipping code). //! to detect them for me (so that I don't have to write clipping code).
use crate::{ use crate::{
WorldSize, events, WorldSize, messages,
objects::{Asteroid, Bullet, Ship}, objects::{Asteroid, Bullet, Ship},
}; };
@@ -90,9 +90,9 @@ pub(crate) fn wrap_entities(
/// | Bullet & Ship | Nothing. The player shouldn't be able to shoot themselves (and the Flying Saucer hasn't been impl.'d, so it's bullets don't count) | /// | Bullet & Ship | Nothing. The player shouldn't be able to shoot themselves (and the Flying Saucer hasn't been impl.'d, so it's bullets don't count) |
pub fn collision_listener( pub fn collision_listener(
mut collisions: EventReader<CollisionEvent>, mut collisions: EventReader<CollisionEvent>,
mut ship_writer: EventWriter<events::ShipDestroy>, mut ship_writer: EventWriter<messages::ShipDestroy>,
mut asteroid_writer: EventWriter<events::AsteroidDestroy>, mut asteroid_writer: EventWriter<messages::AsteroidDestroy>,
mut bullet_writer: EventWriter<events::BulletDestroy>, mut bullet_writer: EventWriter<messages::BulletDestroy>,
player: Single<Entity, With<Ship>>, player: Single<Entity, With<Ship>>,
bullets: Query<&Bullet>, bullets: Query<&Bullet>,
rocks: Query<&Asteroid>, rocks: Query<&Asteroid>,
@@ -112,12 +112,12 @@ pub fn collision_listener(
if rocks.contains(*two) { if rocks.contains(*two) {
// player-asteroid collision // player-asteroid collision
dbg!("Writing ShipDestroy event"); dbg!("Writing ShipDestroy event");
ship_writer.write(events::ShipDestroy); ship_writer.write(messages::ShipDestroy);
} // else, we don't care } // else, we don't care
} else if *two == *player { } else if *two == *player {
if rocks.contains(*one) { if rocks.contains(*one) {
dbg!("Writing ShipDestroy event"); dbg!("Writing ShipDestroy event");
ship_writer.write(events::ShipDestroy); ship_writer.write(messages::ShipDestroy);
} }
} }
@@ -125,14 +125,14 @@ pub fn collision_listener(
if bullets.contains(*one) { if bullets.contains(*one) {
if rocks.contains(*two) { if rocks.contains(*two) {
dbg!("Writing AsteroidDestroy & BulletDestroy events"); dbg!("Writing AsteroidDestroy & BulletDestroy events");
asteroid_writer.write(events::AsteroidDestroy(*two)); asteroid_writer.write(messages::AsteroidDestroy(*two));
bullet_writer.write(events::BulletDestroy(*one)); bullet_writer.write(messages::BulletDestroy(*one));
} }
} else if rocks.contains(*one) { } else if rocks.contains(*one) {
if bullets.contains(*two) { if bullets.contains(*two) {
dbg!("Writing AsteroidDestroy & BulletDestroy events"); dbg!("Writing AsteroidDestroy & BulletDestroy events");
asteroid_writer.write(events::AsteroidDestroy(*one)); asteroid_writer.write(messages::AsteroidDestroy(*one));
bullet_writer.write(events::BulletDestroy(*two)); bullet_writer.write(messages::BulletDestroy(*two));
} }
} }
} }