bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Add extension method for `App` in `bevy_audio` that register custom `Decodable` types

Open harudagondi opened this issue 3 years ago • 1 comments

What problem does this solve or what need does it fill?

Related to #6362. Creating custom Decodable types requires boilerplate.

What solution would you like?

Create an extension trait for App.

trait AddAudioSource {
	fn add_audio_source<Au>(&mut self) -> &mut Self
	where
		Au: Decodable + Asset;
}

impl AddAudioSource for App {
	fn add_audio_source<Au>(&mut self) -> &mut Self
	where
		Au: Decodable + Asset
	{
		self.add_asset::<Au>
			.init_resource::<Audio<Au>>()
			.init_non_send_resource::<AudioOutput<Au>>()
			.add_system_to_stage(CoreStage::PostUpdate, play_queued_audio_system::<Au>)
	}
}

What alternative(s) have you considered?

Simply do not do this. Manually register audio sources.

Additional context

See harudagondi/bevy_fundsp#6, especially in lib.rs and backend/bevy_audio.rs.

Also see bevy_oddio's implementation.

harudagondi avatar Oct 25 '22 02:10 harudagondi

I am working on this.

dis-da-mor avatar Nov 16 '22 13:11 dis-da-mor