Add from_str for GuiSnippet
This commit is contained in:
parent
cc6ff8ab32
commit
70e54664e9
1 changed files with 16 additions and 3 deletions
|
@ -17,13 +17,27 @@ pub struct GuiSnippet {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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(
|
let validator = Validator::new(
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
&gui_handler,
|
&gui_handler,
|
||||||
path,
|
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 root = validator.root();
|
||||||
|
|
||||||
let mut ids = HashMap::new();
|
let mut ids = HashMap::new();
|
||||||
|
@ -31,8 +45,7 @@ impl GuiSnippet {
|
||||||
|
|
||||||
if root.children.len() != 1 {
|
if root.children.len() != 1 {
|
||||||
return Err(anyhow::Error::msg(format!(
|
return Err(anyhow::Error::msg(format!(
|
||||||
"Expected exact 1 root in {}. Found {} roots",
|
"Expected exact 1 root. Found {} roots",
|
||||||
path.full_path(),
|
|
||||||
root.children.len()
|
root.children.len()
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue