Refactor SoundIcon
and Footstep
to new Audio
type.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
6eddde886e
commit
6f025d49aa
|
@ -1,15 +1,14 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use bevy::{prelude::*, transform::TransformSystem};
|
||||
use bevy_synthizer::{Buffer, Sound};
|
||||
use bevy_synthizer::{Audio, Sound};
|
||||
use rand::random;
|
||||
|
||||
use crate::core::PointLike;
|
||||
|
||||
#[derive(Component, Clone, Debug, Reflect)]
|
||||
#[reflect(Component)]
|
||||
#[derive(Component, Clone, Debug)]
|
||||
pub struct Footstep {
|
||||
pub buffer: Handle<Buffer>,
|
||||
pub audio: Audio,
|
||||
pub step_length: f32,
|
||||
pub gain: f64,
|
||||
pub pitch: Option<f64>,
|
||||
|
@ -19,7 +18,7 @@ pub struct Footstep {
|
|||
impl Default for Footstep {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
buffer: default(),
|
||||
audio: default(),
|
||||
step_length: 0.8,
|
||||
gain: 1.,
|
||||
pitch: None,
|
||||
|
@ -30,7 +29,7 @@ impl Default for Footstep {
|
|||
|
||||
fn added(mut commands: Commands, footsteps: Query<(Entity, &Footstep), Added<Footstep>>) {
|
||||
for (entity, footstep) in &footsteps {
|
||||
let buffer = footstep.buffer.clone();
|
||||
let buffer = footstep.audio.clone();
|
||||
commands.entity(entity).insert(Sound {
|
||||
audio: buffer.into(),
|
||||
paused: true,
|
||||
|
@ -73,8 +72,7 @@ pub struct FootstepPlugin;
|
|||
|
||||
impl Plugin for FootstepPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.register_type::<Footstep>()
|
||||
.add_system(added.in_base_set(CoreSet::PreUpdate))
|
||||
app.add_system(added.in_base_set(CoreSet::PreUpdate))
|
||||
.add_system(
|
||||
update
|
||||
.after(TransformSystem::TransformPropagate)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{fmt::Debug, time::Duration};
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_synthizer::{Audio, Buffer, Sound};
|
||||
use bevy_synthizer::{Audio, Sound};
|
||||
|
||||
use rand::random;
|
||||
|
||||
|
@ -11,10 +11,9 @@ use crate::{
|
|||
visibility::{VisibilityChanged, Visible, VisibleEntities},
|
||||
};
|
||||
|
||||
#[derive(Component, Clone, Debug, Reflect)]
|
||||
#[reflect(Component)]
|
||||
#[derive(Component, Clone, Debug)]
|
||||
pub struct SoundIcon {
|
||||
pub buffer: Handle<Buffer>,
|
||||
pub audio: Audio,
|
||||
pub gain: f64,
|
||||
pub pitch: f64,
|
||||
pub interval: Option<Timer>,
|
||||
|
@ -24,7 +23,7 @@ impl Default for SoundIcon {
|
|||
fn default() -> Self {
|
||||
let seconds = random::<f32>() + 4.5;
|
||||
let mut icon = Self {
|
||||
buffer: default(),
|
||||
audio: default(),
|
||||
gain: 1.,
|
||||
pitch: 1.,
|
||||
interval: Some(Timer::from_seconds(seconds, TimerMode::Repeating)),
|
||||
|
@ -39,7 +38,7 @@ impl Default for SoundIcon {
|
|||
|
||||
fn added(mut commands: Commands, icons: Query<(Entity, &SoundIcon), Added<SoundIcon>>) {
|
||||
for (entity, icon) in &icons {
|
||||
let buffer = icon.buffer.clone();
|
||||
let buffer = icon.audio.clone();
|
||||
let gain = icon.gain;
|
||||
let pitch = icon.pitch;
|
||||
let looping = icon.interval.is_none();
|
||||
|
@ -93,7 +92,7 @@ fn update<S>(
|
|||
interval.reset();
|
||||
}
|
||||
}
|
||||
let buffer = icon.buffer.clone();
|
||||
let buffer = icon.audio.clone();
|
||||
let audio: Audio = buffer.into();
|
||||
if sound.audio != audio {
|
||||
sound.audio = audio;
|
||||
|
@ -198,7 +197,6 @@ where
|
|||
{
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(self.clone())
|
||||
.register_type::<SoundIcon>()
|
||||
.add_systems((added, reset_timer_on_visibility_gain).in_base_set(CoreSet::PreUpdate))
|
||||
.add_systems(
|
||||
(exploration_focus_changed, update::<S>)
|
||||
|
|
Loading…
Reference in New Issue
Block a user