First pass converting snapshot code over to RojoTree from RbxTree

This commit is contained in:
Lucien Greathouse
2019-09-09 13:50:39 -07:00
parent 618185a52d
commit 824b984a64
6 changed files with 143 additions and 88 deletions

View File

@@ -6,11 +6,11 @@ use std::{
};
use failure::Fail;
use rbx_dom_weak::{RbxInstanceProperties, RbxTree};
use rbx_dom_weak::RbxInstanceProperties;
use crate::{
imfs::new::{FsError, Imfs, RealFetcher, WatchMode},
snapshot::{apply_patch_set, compute_patch_set},
snapshot::{apply_patch_set, compute_patch_set, InstancePropertiesWithMeta, RojoTree},
snapshot_middleware::snapshot_from_imfs,
};
@@ -78,10 +78,13 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
log::info!("Hoping to generate file of type {:?}", output_kind);
let mut tree = RbxTree::new(RbxInstanceProperties {
name: "ROOT".to_owned(),
class_name: "Folder".to_owned(),
properties: HashMap::new(),
let mut tree = RojoTree::new(InstancePropertiesWithMeta {
properties: RbxInstanceProperties {
name: "ROOT".to_owned(),
class_name: "Folder".to_owned(),
properties: HashMap::new(),
},
metadata: Default::default(),
});
let root_id = tree.get_root_id();
@@ -112,25 +115,35 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
// Model files include the root instance of the tree and all its
// descendants.
rbx_xml::to_writer(&mut file, &tree, &[root_id], xml_encode_config())?;
rbx_xml::to_writer(&mut file, tree.inner(), &[root_id], xml_encode_config())?;
}
OutputKind::Rbxlx => {
// Place files don't contain an entry for the DataModel, but our
// RbxTree representation does.
let top_level_ids = tree.get_instance(root_id).unwrap().get_children_ids();
rbx_xml::to_writer(&mut file, &tree, top_level_ids, xml_encode_config())?;
let top_level_ids = tree
.get_instance(root_id)
.unwrap()
.instance
.get_children_ids();
rbx_xml::to_writer(&mut file, tree.inner(), top_level_ids, xml_encode_config())?;
}
OutputKind::Rbxm => {
rbx_binary::encode(&tree, &[root_id], &mut file)?;
rbx_binary::encode(tree.inner(), &[root_id], &mut file)?;
}
OutputKind::Rbxl => {
log::warn!("Support for building binary places (rbxl) is still experimental.");
log::warn!("Using the XML place format (rbxlx) is recommended instead.");
log::warn!("For more info, see https://github.com/LPGhatguy/rojo/issues/180");
let top_level_ids = tree.get_instance(root_id).unwrap().get_children_ids();
rbx_binary::encode(&tree, top_level_ids, &mut file)?;
let top_level_ids = tree
.get_instance(root_id)
.unwrap()
.instance
.get_children_ids();
rbx_binary::encode(tree.inner(), top_level_ids, &mut file)?;
}
}

View File

@@ -1,13 +1,13 @@
use std::{collections::HashMap, path::PathBuf, sync::Arc};
use failure::Fail;
use rbx_dom_weak::{RbxInstanceProperties, RbxTree};
use rbx_dom_weak::RbxInstanceProperties;
use crate::{
imfs::new::{Imfs, RealFetcher, WatchMode},
project::{Project, ProjectLoadError},
serve_session::ServeSession,
snapshot::{apply_patch_set, compute_patch_set},
snapshot::{apply_patch_set, compute_patch_set, InstancePropertiesWithMeta, RojoTree},
snapshot_middleware::snapshot_from_imfs,
web::LiveServer,
};
@@ -48,10 +48,13 @@ pub fn serve(options: &ServeOptions) -> Result<(), ServeError> {
println!("Rojo server listening on port {}", port);
let mut tree = RbxTree::new(RbxInstanceProperties {
name: "ROOT".to_owned(),
class_name: "Folder".to_owned(),
properties: HashMap::new(),
let mut tree = RojoTree::new(InstancePropertiesWithMeta {
properties: RbxInstanceProperties {
name: "ROOT".to_owned(),
class_name: "Folder".to_owned(),
properties: HashMap::new(),
},
metadata: Default::default(),
});
let root_id = tree.get_root_id();

View File

@@ -1,13 +1,13 @@
use std::{collections::HashMap, path::PathBuf};
use failure::Fail;
use rbx_dom_weak::{RbxInstanceProperties, RbxTree};
use rbx_dom_weak::RbxInstanceProperties;
use reqwest::header::{ACCEPT, CONTENT_TYPE, COOKIE, USER_AGENT};
use crate::{
auth_cookie::get_auth_cookie,
imfs::new::{Imfs, RealFetcher, WatchMode},
snapshot::{apply_patch_set, compute_patch_set},
snapshot::{apply_patch_set, compute_patch_set, InstancePropertiesWithMeta, RojoTree},
snapshot_middleware::snapshot_from_imfs,
};
@@ -45,10 +45,13 @@ pub fn upload(options: UploadOptions) -> Result<(), UploadError> {
.or_else(get_auth_cookie)
.ok_or(UploadError::NeedAuthCookie)?;
let mut tree = RbxTree::new(RbxInstanceProperties {
name: "ROOT".to_owned(),
class_name: "Folder".to_owned(),
properties: HashMap::new(),
let mut tree = RojoTree::new(InstancePropertiesWithMeta {
properties: RbxInstanceProperties {
name: "ROOT".to_owned(),
class_name: "Folder".to_owned(),
properties: HashMap::new(),
},
metadata: Default::default(),
});
let root_id = tree.get_root_id();
@@ -77,7 +80,7 @@ pub fn upload(options: UploadOptions) -> Result<(), UploadError> {
let config = rbx_xml::EncodeOptions::new()
.property_behavior(rbx_xml::EncodePropertyBehavior::WriteUnknown);
rbx_xml::to_writer(&mut buffer, &tree, &[root_id], config)?;
rbx_xml::to_writer(&mut buffer, tree.inner(), &[root_id], config)?;
let url = format!(
"https://data.roblox.com/Data/Upload.ashx?assetid={}",