Add from_str for GuiSnippet

This commit is contained in:
hodasemi 2023-01-18 06:16:41 +01:00
parent cc6ff8ab32
commit 70e54664e9

View file

@ -17,13 +17,27 @@ pub struct GuiSnippet {
}
impl GuiSnippet {
pub fn new(gui_handler: Arc<GuiHandler>, path: &AssetPath) -> Result<Arc<Self>> {
pub fn new(gui_handler: &Arc<GuiHandler>, path: &AssetPath) -> Result<Arc<Self>> {
let validator = Validator::new(
#[cfg(feature = "audio")]
&gui_handler,
path,
)?;
Self::_new(gui_handler, validator)
}
pub fn from_str(gui_handler: &Arc<GuiHandler>, s: &str) -> Result<Arc<Self>> {
let validator = Validator::from_str(
#[cfg(feature = "audio")]
gui_handler,
s,
)?;
Self::_new(gui_handler, validator)
}
fn _new(gui_handler: &Arc<GuiHandler>, validator: Validator) -> Result<Arc<Self>> {
let root = validator.root();
let mut ids = HashMap::new();
@ -31,8 +45,7 @@ impl GuiSnippet {
if root.children.len() != 1 {
return Err(anyhow::Error::msg(format!(
"Expected exact 1 root in {}. Found {} roots",
path.full_path(),
"Expected exact 1 root. Found {} roots",
root.children.len()
)));
}