Fix audio feature

This commit is contained in:
Michael Hübner 2025-03-04 14:37:56 +01:00
parent b09ec887ab
commit c8b0c46d0e
5 changed files with 15 additions and 15 deletions

View file

@ -20,7 +20,7 @@ impl GuiSnippet {
pub fn new(gui_handler: &mut GuiHandler, path: &AssetPath) -> Result<Arc<Self>> { pub fn new(gui_handler: &mut GuiHandler, path: &AssetPath) -> Result<Arc<Self>> {
let validator = Validator::new( let validator = Validator::new(
#[cfg(feature = "audio")] #[cfg(feature = "audio")]
&gui_handler, gui_handler,
path, path,
)?; )?;

View file

@ -80,7 +80,7 @@ pub struct ButtonInfo {
impl ButtonInfo { impl ButtonInfo {
pub fn new<'a>( pub fn new<'a>(
#[cfg(feature = "audio")] gui_handler: &Arc<GuiHandler>, #[cfg(feature = "audio")] gui_handler: &GuiHandler,
attributes: quick_xml::events::attributes::Attributes<'a>, attributes: quick_xml::events::attributes::Attributes<'a>,
grid: &Arc<GridInfo>, grid: &Arc<GridInfo>,
) -> Result<ButtonInfo> { ) -> Result<ButtonInfo> {

View file

@ -6,11 +6,11 @@ use assetpath::AssetPath;
use serde_json::from_str; use serde_json::from_str;
use utilities::prelude::*; use utilities::prelude::*;
use quick_xml::{events::Event, Reader}; use quick_xml::{Reader, events::Event};
use std::borrow::Cow; use std::borrow::Cow;
use std::str::from_utf8;
use std::str::FromStr; use std::str::FromStr;
use std::str::from_utf8;
use std::{convert::TryFrom, io::BufRead, sync::Arc}; use std::{convert::TryFrom, io::BufRead, sync::Arc};
use super::buttoninfo::ButtonInfo; use super::buttoninfo::ButtonInfo;
@ -63,7 +63,7 @@ enum CurrentElement {
impl Validator { impl Validator {
pub fn from_str( pub fn from_str(
#[cfg(feature = "audio")] gui_handler: &Arc<GuiHandler>, #[cfg(feature = "audio")] gui_handler: &GuiHandler,
s: &str, s: &str,
) -> Result<Validator> { ) -> Result<Validator> {
Self::_new( Self::_new(
@ -74,7 +74,7 @@ impl Validator {
} }
pub fn new( pub fn new(
#[cfg(feature = "audio")] gui_handler: &Arc<GuiHandler>, #[cfg(feature = "audio")] gui_handler: &GuiHandler,
path: &AssetPath, path: &AssetPath,
) -> Result<Validator> { ) -> Result<Validator> {
Self::_new( Self::_new(
@ -86,7 +86,7 @@ impl Validator {
#[inline] #[inline]
fn _new<T: BufRead>( fn _new<T: BufRead>(
#[cfg(feature = "audio")] gui_handler: &Arc<GuiHandler>, #[cfg(feature = "audio")] gui_handler: &GuiHandler,
mut reader: Reader<T>, mut reader: Reader<T>,
) -> Result<Validator> { ) -> Result<Validator> {
// removes white spaces in texts // removes white spaces in texts
@ -312,13 +312,13 @@ impl Validator {
} }
Ok(Event::Text(ref e)) => match current_element { Ok(Event::Text(ref e)) => match current_element {
CurrentElement::Root => { CurrentElement::Root => {
return Err(anyhow::Error::msg("Text inside root not allowed")) return Err(anyhow::Error::msg("Text inside root not allowed"));
} }
CurrentElement::None => { CurrentElement::None => {
return Err(anyhow::Error::msg("Text outside root not allowed")) return Err(anyhow::Error::msg("Text outside root not allowed"));
} }
CurrentElement::Grid(_) => { 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) => { CurrentElement::Icon(ref icon) => {
*icon.text.write().unwrap() = e.unescape()?.to_string(); *icon.text.write().unwrap() = e.unescape()?.to_string();
@ -365,7 +365,7 @@ impl Validator {
} }
fn process_start<'a>( fn process_start<'a>(
#[cfg(feature = "audio")] gui_handler: &Arc<GuiHandler>, #[cfg(feature = "audio")] gui_handler: &GuiHandler,
element: &quick_xml::events::BytesStart<'a>, element: &quick_xml::events::BytesStart<'a>,
handle: &CurrentElement, handle: &CurrentElement,
) -> Result<StartResult> { ) -> Result<StartResult> {
@ -479,7 +479,7 @@ impl Validator {
return Err(anyhow::Error::msg(format!( return Err(anyhow::Error::msg(format!(
"Unexpected tag: {}", "Unexpected tag: {}",
from_utf8(element.name().into_inner())? from_utf8(element.name().into_inner())?
))) )));
} }
}) })
} }

View file

@ -140,13 +140,13 @@ impl ButtonBuilder {
#[cfg(feature = "audio")] #[cfg(feature = "audio")]
let click_sound = self let click_sound = self
.click_sound .click_sound
.map(|path| Audible::new(gui_handler.clone(), path)) .map(|path| Audible::new(gui_handler, path))
.transpose()?; .transpose()?;
#[cfg(feature = "audio")] #[cfg(feature = "audio")]
let hover_sound = self let hover_sound = self
.hover_sound .hover_sound
.map(|path| Audible::new(gui_handler.clone(), path)) .map(|path| Audible::new(gui_handler, path))
.transpose()?; .transpose()?;
let clickable = Clickable::new(framable.clone(), click_executable.clone()); let clickable = Clickable::new(framable.clone(), click_executable.clone());

View file

@ -16,7 +16,7 @@ pub struct Audible {
} }
impl Audible { impl Audible {
pub fn new(gui_handler: Arc<GuiHandler>, mut path: AssetPath) -> Result<Arc<Self>> { pub fn new(gui_handler: &GuiHandler, mut path: AssetPath) -> Result<Arc<Self>> {
if !path.has_prefix() { if !path.has_prefix() {
path.set_prefix( path.set_prefix(
&gui_handler &gui_handler