single global observers root node (#25)
plus auto name observer macro `global_observer`
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use super::{Projectile, TriggerGun};
|
||||
use crate::{
|
||||
GameState, billboards::Billboard, loading_assets::GameAssets, physics_layers::GameLayer,
|
||||
sounds::PlaySound, utils::sprite_3d_animation::AnimationTimer,
|
||||
GameState, billboards::Billboard, global_observer, loading_assets::GameAssets,
|
||||
physics_layers::GameLayer, sounds::PlaySound, utils::sprite_3d_animation::AnimationTimer,
|
||||
};
|
||||
use avian3d::prelude::{
|
||||
Collider, CollisionLayers, CollisionStarted, LayerMask, PhysicsLayer, Sensor,
|
||||
@@ -30,7 +30,8 @@ pub fn plugin(app: &mut App) {
|
||||
Update,
|
||||
(update, shot_collision, timeout).run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
app.add_observer(on_trigger_state);
|
||||
|
||||
global_observer!(app, on_trigger_gun);
|
||||
}
|
||||
|
||||
fn setup(mut commands: Commands, assets: Res<GameAssets>, mut sprite_params: Sprite3dParams) {
|
||||
@@ -43,7 +44,7 @@ fn setup(mut commands: Commands, assets: Res<GameAssets>, mut sprite_params: Spr
|
||||
});
|
||||
}
|
||||
|
||||
fn on_trigger_state(
|
||||
fn on_trigger_gun(
|
||||
trigger: Trigger<TriggerGun>,
|
||||
mut commands: Commands,
|
||||
query_transform: Query<&Transform>,
|
||||
|
||||
@@ -4,6 +4,7 @@ mod thrown;
|
||||
use crate::{
|
||||
GameState,
|
||||
aim::AimTarget,
|
||||
global_observer,
|
||||
heads::ActiveHeads,
|
||||
hitpoints::Hit,
|
||||
physics_layers::GameLayer,
|
||||
@@ -74,7 +75,7 @@ pub fn plugin(app: &mut App) {
|
||||
|
||||
app.add_systems(Update, enemy_hit.run_if(in_state(GameState::Playing)));
|
||||
|
||||
app.add_observer(on_trigger_state);
|
||||
global_observer!(app, on_trigger_state);
|
||||
}
|
||||
|
||||
fn enemy_hit(
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
use super::TriggerThrow;
|
||||
use crate::{
|
||||
GameState, billboards::Billboard, hitpoints::Hit, loading_assets::GameAssets,
|
||||
physics_layers::GameLayer, sounds::PlaySound, utils::sprite_3d_animation::AnimationTimer,
|
||||
GameState,
|
||||
billboards::Billboard,
|
||||
hitpoints::Hit,
|
||||
loading_assets::GameAssets,
|
||||
physics_layers::GameLayer,
|
||||
sounds::PlaySound,
|
||||
utils::{global_observer, sprite_3d_animation::AnimationTimer},
|
||||
};
|
||||
use avian3d::prelude::*;
|
||||
use bevy::{pbr::NotShadowCaster, prelude::*};
|
||||
@@ -35,8 +40,9 @@ pub fn plugin(app: &mut App) {
|
||||
app.add_systems(OnEnter(GameState::Playing), setup);
|
||||
app.add_systems(Update, shot_collision.run_if(in_state(GameState::Playing)));
|
||||
app.add_systems(FixedUpdate, update_auto_rotation);
|
||||
app.add_observer(on_trigger_state);
|
||||
app.add_observer(on_explosion);
|
||||
|
||||
global_observer!(app, on_trigger_thrown);
|
||||
global_observer!(app, on_explosion);
|
||||
}
|
||||
|
||||
fn on_explosion(
|
||||
@@ -75,7 +81,7 @@ fn setup(mut commands: Commands, assets: Res<GameAssets>, mut sprite_params: Spr
|
||||
});
|
||||
}
|
||||
|
||||
fn on_trigger_state(
|
||||
fn on_trigger_thrown(
|
||||
trigger: Trigger<TriggerThrow>,
|
||||
mut commands: Commands,
|
||||
query_transform: Query<&Transform>,
|
||||
|
||||
Reference in New Issue
Block a user