use bevy::prelude::*; use bevy_synthizer::{Audio, Sound}; use rand::random; use crate::{ core::Player, exploration::ExplorationFocused, visibility::{Visible, VisibleEntities}, }; #[derive(Component, Clone, Debug)] pub struct SoundIcon { pub audio: Audio, pub gain: f64, pub pitch: f64, pub interval: Option, } impl Default for SoundIcon { fn default() -> Self { let seconds = random::() + 4.5; Self { audio: default(), gain: 1., pitch: 1., interval: Some(Timer::from_seconds(seconds, TimerMode::Once)), } } } fn added(mut commands: Commands, icons: Query<(Entity, &SoundIcon), Added>) { for (entity, icon) in &icons { let buffer = icon.audio.clone(); let gain = icon.gain; let pitch = icon.pitch; let looping = icon.interval.is_none(); commands.entity(entity).insert(Sound { audio: buffer, gain, pitch, looping, paused: true, ..default() }); } } fn update( config: Res>, state: Res>, time: Res