2 unstable releases
0.2.0 | Jan 26, 2019 |
---|---|
0.1.0 | Jan 12, 2019 |
#48 in #roblox
17KB
280 lines
rbx_tree
Weakly-typed implementation of Roblox's DOM, used for representing instances in external tools.
Coverage
Because rbx_tree is weakly-typed, it doesn't need to be updated when new instances are added to Roblox. It does, however, have to be updated when new datatypes like Vector3int16
are added.
Data type coverage:
- BinaryString
- Bool
- CFrame
- Color3
- Color3uint8
- Enum
- Float32
- Int32
- String
- Vector2
- Vector2int16
- Vector3
- Vector3int16
- Content
- PhysicalProperties (currently stubbed)
- Ref
lib.rs
:
rbx_tree is a common representation of the Roblox DOM for Rust. It's designed to play nicely with the borrow checker and allows accessing instances by ID in constant time.
rbx_tree's APIs are not completely stable, but most of the design is locked in. It is definitely a 0.x.y quality library.
Constructing a new tree of instances is accomplished by first creating an
RbxInstanceProperties
object that describes the root instance of the
tree, and then wrapping it with an RbxTree
:
use std::collections::HashMap;
use rbx_tree::{RbxInstanceProperties, RbxTree};
let props = RbxInstanceProperties {
name: "My Cool Game".to_owned(),
class_name: "DataModel".to_owned(),
properties: HashMap::new(),
};
let mut tree = RbxTree::new(props);
println!("ID of instance we just inserted is {}", tree.get_root_id());
Note that the maplit crate is incredibly useful for defining properties inline.
Once we have a tree, we can use RbxTree::insert_instance
and
RbxTree::get_instance
to add instances to the tree and retrieve them.
use rbx_tree::RbxValue;
use maplit::hashmap;
#
#
#
let http_service = RbxInstanceProperties {
name: "HttpService".to_owned(),
class_name: "HttpService".to_owned(),
properties: hashmap! {
"HttpEnabled".to_owned() => RbxValue::Bool {
value: true,
},
},
};
let datamodel_id = tree.get_root_id();
let http_service_id = tree.insert_instance(http_service, datamodel_id);
println!("HttpService has ID {}", http_service_id);
To change properties on an instance that's already present in the tree, use
RbxTree::get_instance_mut
. Note that it isn't possible to add or remove
children through this method, use RbxTree::insert_instance
instead.
Dependencies
~1.2–2MB
~36K SLoC