From c8b0c46d0efc67d56e7d1fb9f02bf1c0d7af7b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20H=C3=BCbner?= Date: Tue, 4 Mar 2025 14:37:56 +0100 Subject: [PATCH] Fix audio feature --- src/builder/snippet.rs | 2 +- src/builder/validator/buttoninfo.rs | 2 +- src/builder/validator/validator.rs | 20 ++++++++++---------- src/elements/button.rs | 4 ++-- src/gui_handler/gui/audible.rs | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/builder/snippet.rs b/src/builder/snippet.rs index 2272fdf..720f37c 100644 --- a/src/builder/snippet.rs +++ b/src/builder/snippet.rs @@ -20,7 +20,7 @@ impl GuiSnippet { pub fn new(gui_handler: &mut GuiHandler, path: &AssetPath) -> Result> { let validator = Validator::new( #[cfg(feature = "audio")] - &gui_handler, + gui_handler, path, )?; diff --git a/src/builder/validator/buttoninfo.rs b/src/builder/validator/buttoninfo.rs index d32dd59..58aa28c 100644 --- a/src/builder/validator/buttoninfo.rs +++ b/src/builder/validator/buttoninfo.rs @@ -80,7 +80,7 @@ pub struct ButtonInfo { impl ButtonInfo { pub fn new<'a>( - #[cfg(feature = "audio")] gui_handler: &Arc, + #[cfg(feature = "audio")] gui_handler: &GuiHandler, attributes: quick_xml::events::attributes::Attributes<'a>, grid: &Arc, ) -> Result { diff --git a/src/builder/validator/validator.rs b/src/builder/validator/validator.rs index e6b0c8d..9a145df 100644 --- a/src/builder/validator/validator.rs +++ b/src/builder/validator/validator.rs @@ -6,11 +6,11 @@ use assetpath::AssetPath; use serde_json::from_str; use utilities::prelude::*; -use quick_xml::{events::Event, Reader}; +use quick_xml::{Reader, events::Event}; use std::borrow::Cow; -use std::str::from_utf8; use std::str::FromStr; +use std::str::from_utf8; use std::{convert::TryFrom, io::BufRead, sync::Arc}; use super::buttoninfo::ButtonInfo; @@ -63,7 +63,7 @@ enum CurrentElement { impl Validator { pub fn from_str( - #[cfg(feature = "audio")] gui_handler: &Arc, + #[cfg(feature = "audio")] gui_handler: &GuiHandler, s: &str, ) -> Result { Self::_new( @@ -74,7 +74,7 @@ impl Validator { } pub fn new( - #[cfg(feature = "audio")] gui_handler: &Arc, + #[cfg(feature = "audio")] gui_handler: &GuiHandler, path: &AssetPath, ) -> Result { Self::_new( @@ -86,7 +86,7 @@ impl Validator { #[inline] fn _new( - #[cfg(feature = "audio")] gui_handler: &Arc, + #[cfg(feature = "audio")] gui_handler: &GuiHandler, mut reader: Reader, ) -> Result { // removes white spaces in texts @@ -312,13 +312,13 @@ impl Validator { } Ok(Event::Text(ref e)) => match current_element { CurrentElement::Root => { - return Err(anyhow::Error::msg("Text inside root not allowed")) + return Err(anyhow::Error::msg("Text inside root not allowed")); } CurrentElement::None => { - return Err(anyhow::Error::msg("Text outside root not allowed")) + return Err(anyhow::Error::msg("Text outside root not allowed")); } CurrentElement::Grid(_) => { - return Err(anyhow::Error::msg("Text inside grid not allowed")) + return Err(anyhow::Error::msg("Text inside grid not allowed")); } CurrentElement::Icon(ref icon) => { *icon.text.write().unwrap() = e.unescape()?.to_string(); @@ -365,7 +365,7 @@ impl Validator { } fn process_start<'a>( - #[cfg(feature = "audio")] gui_handler: &Arc, + #[cfg(feature = "audio")] gui_handler: &GuiHandler, element: &quick_xml::events::BytesStart<'a>, handle: &CurrentElement, ) -> Result { @@ -479,7 +479,7 @@ impl Validator { return Err(anyhow::Error::msg(format!( "Unexpected tag: {}", from_utf8(element.name().into_inner())? - ))) + ))); } }) } diff --git a/src/elements/button.rs b/src/elements/button.rs index 7864a53..1c315ff 100644 --- a/src/elements/button.rs +++ b/src/elements/button.rs @@ -140,13 +140,13 @@ impl ButtonBuilder { #[cfg(feature = "audio")] let click_sound = self .click_sound - .map(|path| Audible::new(gui_handler.clone(), path)) + .map(|path| Audible::new(gui_handler, path)) .transpose()?; #[cfg(feature = "audio")] let hover_sound = self .hover_sound - .map(|path| Audible::new(gui_handler.clone(), path)) + .map(|path| Audible::new(gui_handler, path)) .transpose()?; let clickable = Clickable::new(framable.clone(), click_executable.clone()); diff --git a/src/gui_handler/gui/audible.rs b/src/gui_handler/gui/audible.rs index 15eec0f..abdf606 100644 --- a/src/gui_handler/gui/audible.rs +++ b/src/gui_handler/gui/audible.rs @@ -16,7 +16,7 @@ pub struct Audible { } impl Audible { - pub fn new(gui_handler: Arc, mut path: AssetPath) -> Result> { + pub fn new(gui_handler: &GuiHandler, mut path: AssetPath) -> Result> { if !path.has_prefix() { path.set_prefix( &gui_handler