load head sounds via asset_loader
This commit is contained in:
@@ -18,6 +18,8 @@ pub struct AudioAssets {
|
|||||||
pub cash: Handle<AudioSource>,
|
pub cash: Handle<AudioSource>,
|
||||||
#[asset(path = "sfx/hit", collection(typed))]
|
#[asset(path = "sfx/hit", collection(typed))]
|
||||||
pub hit: Vec<Handle<AudioSource>>,
|
pub hit: Vec<Handle<AudioSource>>,
|
||||||
|
#[asset(path = "sfx/heads", collection(mapped, typed))]
|
||||||
|
pub head: HashMap<AssetFileName, Handle<AudioSource>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(AssetCollection, Resource)]
|
#[derive(AssetCollection, Resource)]
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use crate::{
|
|||||||
heads_ui::HeadChanged,
|
heads_ui::HeadChanged,
|
||||||
loading_assets::GameAssets,
|
loading_assets::GameAssets,
|
||||||
physics_layers::GameLayer,
|
physics_layers::GameLayer,
|
||||||
|
sounds::PlaySound,
|
||||||
tb_entities::SpawnPoint,
|
tb_entities::SpawnPoint,
|
||||||
};
|
};
|
||||||
use avian3d::{
|
use avian3d::{
|
||||||
@@ -266,11 +267,7 @@ fn update_head(
|
|||||||
|
|
||||||
let head_str = head_id_to_str(trigger.0);
|
let head_str = head_id_to_str(trigger.0);
|
||||||
|
|
||||||
//TODO: use asset loader
|
commands.trigger(PlaySound::Head(head_str.to_string()));
|
||||||
commands.spawn((
|
|
||||||
AudioPlayer::new(asset_server.load(format!("sfx/heads/{}.ogg", head_str))),
|
|
||||||
PlaybackSettings::DESPAWN,
|
|
||||||
));
|
|
||||||
|
|
||||||
let mesh = asset_server
|
let mesh = asset_server
|
||||||
.load(GltfAssetLabel::Scene(0).from_asset(format!("models/heads/{}.glb", head_str)));
|
.load(GltfAssetLabel::Scene(0).from_asset(format!("models/heads/{}.glb", head_str)));
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
|
use crate::loading_assets::AudioAssets;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::loading_assets::AudioAssets;
|
#[derive(Event, Clone, Debug)]
|
||||||
|
|
||||||
#[derive(Event, Copy, Clone, Debug)]
|
|
||||||
pub enum PlaySound {
|
pub enum PlaySound {
|
||||||
Hit,
|
Hit,
|
||||||
KeyCollect,
|
KeyCollect,
|
||||||
Gun,
|
Gun,
|
||||||
Gate,
|
Gate,
|
||||||
CashCollect,
|
CashCollect,
|
||||||
|
Head(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn plugin(app: &mut App) {
|
pub fn plugin(app: &mut App) {
|
||||||
@@ -37,6 +37,14 @@ fn spawn_sounds(
|
|||||||
PlaySound::Gun => assets.gun.clone(),
|
PlaySound::Gun => assets.gun.clone(),
|
||||||
PlaySound::Gate => assets.gate.clone(),
|
PlaySound::Gate => assets.gate.clone(),
|
||||||
PlaySound::CashCollect => assets.cash.clone(),
|
PlaySound::CashCollect => assets.cash.clone(),
|
||||||
|
PlaySound::Head(name) => {
|
||||||
|
let filename = format!("{}.ogg", name);
|
||||||
|
assets
|
||||||
|
.head
|
||||||
|
.get(filename.as_str())
|
||||||
|
.expect(format!("invalid head '{}'", filename).as_str())
|
||||||
|
.clone()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
|||||||
Reference in New Issue
Block a user