Replicate explosion effects (#56)

This commit is contained in:
PROMETHIA-27
2025-07-13 18:24:34 -04:00
committed by GitHub
parent d4bea5a7ac
commit 0e8b0bb677
8 changed files with 196 additions and 159 deletions

View File

@@ -1,21 +1,49 @@
use bevy::ecs::{
bundle::Bundle, resource::Resource, system::EntityCommands, world::EntityWorldMut,
bundle::Bundle,
event::Event,
resource::Resource,
system::{Commands, EntityCommands},
world::{EntityWorldMut, World},
};
#[derive(Default, Resource)]
pub struct IsServer;
pub trait CommandExt {
fn insert_server(&mut self, bundle: impl Bundle) -> &mut Self;
fn trigger_server(&mut self, event: impl Event) -> &mut Self;
}
impl<'w> CommandExt for EntityCommands<'w> {
fn insert_server(&mut self, bundle: impl Bundle) -> &mut Self {
self.queue(|mut entity: EntityWorldMut| {
if entity.world().contains_resource::<IsServer>() {
entity.insert(bundle);
impl<'w, 's> CommandExt for Commands<'w, 's> {
fn trigger_server(&mut self, event: impl Event) -> &mut Self {
self.queue(|world: &mut World| {
if world.contains_resource::<IsServer>() {
world.trigger(event);
}
});
self
}
}
pub trait EntityCommandExt {
fn insert_server(&mut self, bundle: impl Bundle) -> &mut Self;
fn trigger_server(&mut self, event: impl Event) -> &mut Self;
}
impl<'w> EntityCommandExt for EntityCommands<'w> {
fn insert_server(&mut self, bundle: impl Bundle) -> &mut Self {
self.queue(|mut entity: EntityWorldMut| {
if entity.world().contains_resource::<IsServer>() {
entity.insert(bundle);
}
})
}
fn trigger_server(&mut self, event: impl Event) -> &mut Self {
self.queue(|mut entity: EntityWorldMut| {
if entity.world().contains_resource::<IsServer>() {
entity.trigger(event);
}
})
}
}