Replicate Sounds (#68)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use super::TriggerArrow;
|
||||
use crate::{
|
||||
GameState, billboards::Billboard, global_observer, heads_database::HeadsDatabase,
|
||||
hitpoints::Hit, loading_assets::GameAssets, physics_layers::GameLayer, sounds::PlaySound,
|
||||
hitpoints::Hit, loading_assets::GameAssets, physics_layers::GameLayer, protocol::PlaySound,
|
||||
utils::sprite_3d_animation::AnimationTimer,
|
||||
};
|
||||
use avian3d::prelude::*;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::TriggerGun;
|
||||
use crate::{
|
||||
GameState, billboards::Billboard, global_observer, heads_database::HeadsDatabase,
|
||||
hitpoints::Hit, loading_assets::GameAssets, physics_layers::GameLayer, sounds::PlaySound,
|
||||
hitpoints::Hit, loading_assets::GameAssets, physics_layers::GameLayer, protocol::PlaySound,
|
||||
tb_entities::EnemySpawn, utils::sprite_3d_animation::AnimationTimer,
|
||||
};
|
||||
use avian3d::prelude::*;
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
use crate::{
|
||||
GameState, global_observer, heads::ActiveHeads, heads_database::HeadsDatabase,
|
||||
hitpoints::Hitpoints, loading_assets::AudioAssets,
|
||||
hitpoints::Hitpoints,
|
||||
};
|
||||
use bevy::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Healing(pub Entity);
|
||||
#[derive(Component, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Healing;
|
||||
|
||||
#[derive(Event, Debug)]
|
||||
#[derive(Clone, Event, Debug, Serialize, Deserialize)]
|
||||
pub enum HealingStateChanged {
|
||||
Started,
|
||||
Stopped,
|
||||
@@ -22,27 +23,21 @@ pub fn plugin(app: &mut App) {
|
||||
fn on_heal_start_stop(
|
||||
trigger: Trigger<HealingStateChanged>,
|
||||
mut cmds: Commands,
|
||||
assets: Res<AudioAssets>,
|
||||
query: Query<&Healing>,
|
||||
) {
|
||||
if matches!(trigger.event(), HealingStateChanged::Started) {
|
||||
let e = cmds
|
||||
.spawn((
|
||||
Name::new("sfx-heal"),
|
||||
AudioPlayer::new(assets.healing.clone()),
|
||||
PlaybackSettings {
|
||||
mode: bevy::audio::PlaybackMode::Loop,
|
||||
..Default::default()
|
||||
},
|
||||
))
|
||||
.id();
|
||||
cmds.entity(trigger.target())
|
||||
.add_child(e)
|
||||
.insert(Healing(e));
|
||||
} else {
|
||||
if let Ok(healing) = query.single() {
|
||||
cmds.entity(healing.0).despawn();
|
||||
if query.contains(trigger.target()) {
|
||||
// already healing, just ignore
|
||||
return;
|
||||
}
|
||||
|
||||
cmds.entity(trigger.target()).insert(Healing);
|
||||
} else {
|
||||
if !query.contains(trigger.target()) {
|
||||
// Not healing, just ignore
|
||||
return;
|
||||
}
|
||||
|
||||
cmds.entity(trigger.target()).remove::<Healing>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ use crate::{
|
||||
abilities::BuildExplosionSprite,
|
||||
heads_database::HeadsDatabase,
|
||||
physics_layers::GameLayer,
|
||||
protocol::GltfSceneRoot,
|
||||
sounds::PlaySound,
|
||||
protocol::{GltfSceneRoot, PlaySound},
|
||||
utils::{commands::CommandExt, explosions::Explosion, global_observer, trail::Trail},
|
||||
};
|
||||
use avian3d::prelude::*;
|
||||
|
||||
@@ -9,25 +9,23 @@ use crate::{
|
||||
GameState,
|
||||
aim::AimTarget,
|
||||
character::CharacterHierarchy,
|
||||
control::ControlState,
|
||||
global_observer,
|
||||
head::ActiveHead,
|
||||
heads::ActiveHeads,
|
||||
heads_database::HeadsDatabase,
|
||||
loading_assets::GameAssets,
|
||||
physics_layers::GameLayer,
|
||||
player::{Player, PlayerBodyMesh},
|
||||
sounds::PlaySound,
|
||||
protocol::PlaySound,
|
||||
utils::{billboards::Billboard, sprite_3d_animation::AnimationTimer},
|
||||
};
|
||||
#[cfg(feature = "server")]
|
||||
use crate::{control::ControlState, head::ActiveHead};
|
||||
use bevy::{pbr::NotShadowCaster, prelude::*};
|
||||
use bevy_sprite3d::{Sprite3dBuilder, Sprite3dParams};
|
||||
pub use healing::Healing;
|
||||
use healing::HealingStateChanged;
|
||||
use lightyear::{
|
||||
connection::client::ClientState,
|
||||
prelude::{Client, input::native::ActionState},
|
||||
};
|
||||
#[cfg(feature = "server")]
|
||||
use lightyear::prelude::input::native::ActionState;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Reflect, Default, Serialize, Deserialize)]
|
||||
@@ -113,6 +111,7 @@ pub fn plugin(app: &mut App) {
|
||||
Update,
|
||||
(update, update_heal_ability).run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
#[cfg(feature = "server")]
|
||||
app.add_systems(
|
||||
FixedUpdate,
|
||||
on_trigger_state.run_if(in_state(GameState::Playing)),
|
||||
@@ -121,19 +120,13 @@ pub fn plugin(app: &mut App) {
|
||||
global_observer!(app, build_explosion_sprite);
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
fn on_trigger_state(
|
||||
mut res: ResMut<TriggerStateRes>,
|
||||
player: Query<(&ActiveHead, &ActionState<ControlState>), With<Player>>,
|
||||
headdb: Res<HeadsDatabase>,
|
||||
time: Res<Time>,
|
||||
client: Query<&Client>,
|
||||
) {
|
||||
if let Ok(client) = client.single()
|
||||
&& (client.state == ClientState::Connected && cfg!(not(feature = "server")))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (player_head, controls) in player.iter() {
|
||||
res.active = controls.trigger;
|
||||
if controls.just_triggered {
|
||||
|
||||
@@ -4,8 +4,7 @@ use crate::{
|
||||
abilities::BuildExplosionSprite,
|
||||
heads_database::HeadsDatabase,
|
||||
physics_layers::GameLayer,
|
||||
protocol::GltfSceneRoot,
|
||||
sounds::PlaySound,
|
||||
protocol::{GltfSceneRoot, PlaySound},
|
||||
utils::{
|
||||
auto_rotate::AutoRotation, commands::CommandExt, explosions::Explosion, global_observer,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user