diff --git a/src/vvedit/s_editor_ui.rs b/src/vvedit/s_editor_ui.rs index 67df208..323cd11 100644 --- a/src/vvedit/s_editor_ui.rs +++ b/src/vvedit/s_editor_ui.rs @@ -613,6 +613,19 @@ pub fn edit_window_ui( } } } + for each in &mut shared_ui_state.structures { + if each.has_changed_since_last_save { + let handle = each.id.clone(); + let path = each.path.clone(); + let asset = structure_assets.get(handle); + if asset.is_some() { + let result = crate::vvlib::s_structure_asset::serialization::structures::write_latest_version(&path, asset.unwrap()); + if result { + each.has_changed_since_last_save = false; + } + } + } + } } }); }); diff --git a/src/vvedit/s_string_tree.rs b/src/vvedit/s_string_tree.rs index 8cdd0b3..7a37ca7 100644 --- a/src/vvedit/s_string_tree.rs +++ b/src/vvedit/s_string_tree.rs @@ -413,6 +413,34 @@ impl StringTree { } return list; } + pub fn depth_of(&self, subject: &String) -> Option { + fn recursive_depth_search(el: &StringTreeElement, subject: &String, depth: i32) -> i32 { + match el { + StringTreeElement::None => {} + StringTreeElement::Element(name, children) => { + for each in children.as_ref() { + if subject == name { + return depth; + } else { + let res = recursive_depth_search(each, subject, depth + 1); + if res != -1 { + return res; + } + } + } + } + } + + -1 + } + for each in &self.root { + let res = recursive_depth_search(each, subject, 0); + if res != -1 { + return Some(res); + } + } + None + } } #[test] diff --git a/src/vvlib/s_structure_asset.rs b/src/vvlib/s_structure_asset.rs index 42ee527..3614c51 100644 --- a/src/vvlib/s_structure_asset.rs +++ b/src/vvlib/s_structure_asset.rs @@ -482,7 +482,8 @@ pub mod serialization { data += NEWLINE; let mut to_process = Vec::::new(); for each in &asset.layout.root { - if let Some(name) = each.name_of() { + to_process.push(each.name_of().unwrap().clone()); + /*if let Some(name) = each.name_of() { // if !is_first { data += "|"; @@ -492,7 +493,7 @@ pub mod serialization { data += name.clone().as_str(); } else { return None; - } + }*/ if let Some(children) = each.children() { for each in children { to_process.push(each); @@ -515,12 +516,11 @@ pub mod serialization { } // ^ HELPER FUNCTION while !to_process.is_empty() { - if let Some(next) = to_process.pop() { - save_child(&next, &asset.layout, &mut data); - if let Some(children) = asset.layout.children_of(&next) { - for each in children { - to_process.push(each); - } + let next = to_process.remove(0); + save_child(&next, &asset.layout, &mut data); + if let Some(children) = asset.layout.children_of(&next) { + for each in children { + to_process.push(each); } } }