Start fixing room2

This commit is contained in:
Kirill Bulatov
2023-10-26 11:27:12 +02:00
committed by Antonio Scandurra
parent 6185c935a6
commit 483ac9491a
10 changed files with 2277 additions and 15 deletions
+15 -4
View File
@@ -78,12 +78,17 @@ impl Audio {
Self { tx }
}
pub fn play_sound(&self, sound: Sound, cx: &mut AppContext) {
pub fn play_sound(sound: Sound, cx: &mut AppContext) {
if !cx.has_global::<Self>() {
return;
}
let Some(source) = SoundRegistry::global(cx).get(sound.file()).log_err() else {
return;
};
self.tx
let this = cx.global::<Self>();
this.tx
.unbounded_send(Box::new(move |state| {
if let Some(output_handle) = state.ensure_output_exists() {
output_handle.play_raw(source).log_err();
@@ -92,8 +97,14 @@ impl Audio {
.ok();
}
pub fn end_call(&self) {
self.tx
pub fn end_call(cx: &AppContext) {
if !cx.has_global::<Self>() {
return;
}
let this = cx.global::<Self>();
this.tx
.unbounded_send(Box::new(move |state| state.take()))
.ok();
}