diff --git a/fyrox-core/src/visitor/impls.rs b/fyrox-core/src/visitor/impls.rs index e24afba1b..f7d4eb799 100644 --- a/fyrox-core/src/visitor/impls.rs +++ b/fyrox-core/src/visitor/impls.rs @@ -142,21 +142,11 @@ where T: Default + Visit + 'static, { fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult { - const VERSION_VERBOSE: u32 = 0; - const VERSION_CURRENT: u32 = 1; - let mut region = visitor.enter_region(name)?; let mut len = self.len() as u32; len.visit("Length", &mut region)?; - let mut version = VERSION_CURRENT; - if region.is_reading() && version.visit("Version", &mut region).is_err() { - version = VERSION_VERBOSE; - } else { - version.visit("Version", &mut region)?; - } - fn make_name(i: usize) -> String { format!("Item{i}") } @@ -165,22 +155,18 @@ where self.clear(); for index in 0..len as usize { // Backward compatibility with the previous version (verbose, non-flat). - if version == VERSION_VERBOSE { + if region.version == 0 { if let Ok(mut item_region) = region.enter_region(&make_name(index)) { let mut object = T::default(); object.visit("ItemData", &mut item_region)?; self.push(object); continue; } - } else if version == VERSION_CURRENT { + } else { // Try to read the new (flattened) version. let mut object = T::default(); object.visit(&make_name(index), &mut region)?; self.push(object); - } else { - return Err(VisitError::User(format!( - "Unknown vector version {version}!" - ))); } } } else { diff --git a/fyrox-core/src/visitor/mod.rs b/fyrox-core/src/visitor/mod.rs index 7bc019c63..3815c0612 100644 --- a/fyrox-core/src/visitor/mod.rs +++ b/fyrox-core/src/visitor/mod.rs @@ -524,6 +524,11 @@ impl Visitor { self.nodes.borrow_mut(self.current_node) } + /// Returns version number of the visitor. + pub fn version(&self) -> u32 { + self.version + } + /// If [Visitor::is_reading], find a node with the given name that is a child of the current /// node, and return a Visitor for the found node. Return an error if no node with that name exists. ///