From 31e1f6154846234a59868a20baa3cbfbde68aa82 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Wed, 31 Oct 2018 18:07:02 -0700 Subject: [PATCH] Start refining RbxTree operations, going to be a new crate --- server/src/rbx.rs | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/server/src/rbx.rs b/server/src/rbx.rs index d3873cb7..29f55072 100644 --- a/server/src/rbx.rs +++ b/server/src/rbx.rs @@ -7,7 +7,19 @@ use id::{Id, get_id}; pub enum RbxValue { String { value: String, - } + }, + Number { + value: f64, + }, + Bool { + value: bool, + }, + Vector3 { + value: [f64; 3], + }, + Color3 { + value: [u8; 3], + }, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -71,6 +83,7 @@ impl<'a> Iterator for Descendants<'a> { pub struct RbxTree { instances: HashMap, + // TODO: Make private pub root_instance_id: Id, } @@ -103,6 +116,30 @@ impl RbxTree { &self.instances } + // TODO: Test this function! + pub fn insert_tree(&mut self, parent_id: Id, tree: &RbxTree) { + let mut to_visit = vec![tree.root_instance_id]; + + loop { + let id = match to_visit.pop() { + Some(id) => id, + None => break, + }; + + let mut new_child = tree.get_instance(id).unwrap().clone(); + + for child in &new_child.children { + to_visit.push(*child); + } + + if id == tree.root_instance_id { + new_child.parent = Some(parent_id); + } + + self.insert_instance(new_child); + } + } + pub fn insert_instance(&mut self, mut instance: RbxInstance) { match instance.parent { Some(parent_id) => {