Replicate Sounds (#68)

This commit is contained in:
PROMETHIA-27
2025-09-29 14:46:38 -04:00
committed by GitHub
parent a07dfb3840
commit a16ee231cc
47 changed files with 992 additions and 721 deletions

View File

@@ -1,13 +1,7 @@
use crate::{
GameState,
cash::{Cash, CashCollectEvent},
character::{AnimatedCharacter, Character},
global_observer,
head::ActiveHead,
heads::HeadChanged,
heads_database::{HeadControls, HeadsDatabase},
loading_assets::AudioAssets,
sounds::PlaySound,
character::HedzCharacter,
};
use avian3d::prelude::*;
use bevy::{
@@ -18,7 +12,7 @@ use bevy::{
use serde::{Deserialize, Serialize};
#[derive(Component, Default, Serialize, Deserialize, PartialEq)]
#[require(Character)]
#[require(HedzCharacter)]
pub struct Player;
#[derive(Component, Default, Serialize, Deserialize, PartialEq)]
@@ -36,8 +30,6 @@ pub fn plugin(app: &mut App) {
)
.run_if(in_state(GameState::Playing)),
);
global_observer!(app, on_update_head_mesh);
}
fn cursor_recenter(q_windows: Single<&mut Window, With<PrimaryWindow>>) {
@@ -103,48 +95,3 @@ fn setup_animations_marker_for_player(
}
}
}
fn on_update_head_mesh(
trigger: Trigger<HeadChanged>,
mut commands: Commands,
body_mesh: Single<(Entity, &Children), With<PlayerBodyMesh>>,
animated_characters: Query<&AnimatedCharacter>,
mut player: Single<&mut ActiveHead, With<Player>>,
head_db: Res<HeadsDatabase>,
audio_assets: Res<AudioAssets>,
sfx: Query<&AudioPlayer>,
) -> Result {
let (body_mesh, mesh_children) = *body_mesh;
let animated_char = mesh_children
.iter()
.find(|child| animated_characters.contains(*child))
.ok_or("tried to update head mesh before AnimatedCharacter was readded")?;
player.0 = trigger.0;
let head_str = head_db.head_key(trigger.0);
commands.trigger(PlaySound::Head(head_str.to_string()));
commands
.entity(animated_char)
.insert(AnimatedCharacter::new(trigger.0));
//TODO: make part of full character mesh later
for child in mesh_children.iter().filter(|child| sfx.contains(*child)) {
commands.entity(child).despawn();
}
if head_db.head_stats(trigger.0).controls == HeadControls::Plane {
commands.entity(body_mesh).with_child((
Name::new("sfx"),
AudioPlayer::new(audio_assets.jet.clone()),
PlaybackSettings {
mode: bevy::audio::PlaybackMode::Loop,
..Default::default()
},
));
}
Ok(())
}