forked from rojo-rbx/rojo
Implement Syncback to support converting Roblox files to a Rojo project (#937)
This is a very large commit. Consider checking the linked PR for more information.
This commit is contained in:
@@ -2,8 +2,12 @@ use std::path::Path;
|
||||
|
||||
use anyhow::Context;
|
||||
use memofs::Vfs;
|
||||
use rbx_xml::EncodeOptions;
|
||||
|
||||
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
|
||||
use crate::{
|
||||
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
|
||||
syncback::{FsSnapshot, SyncbackReturn, SyncbackSnapshot},
|
||||
};
|
||||
|
||||
pub fn snapshot_rbxmx(
|
||||
context: &InstanceContext,
|
||||
@@ -15,7 +19,7 @@ pub fn snapshot_rbxmx(
|
||||
.property_behavior(rbx_xml::DecodePropertyBehavior::ReadUnknown);
|
||||
|
||||
let temp_tree = rbx_xml::from_reader(vfs.read(path)?.as_slice(), options)
|
||||
.with_context(|| format!("Malformed rbxm file: {}", path.display()))?;
|
||||
.with_context(|| format!("Malformed rbxmx file: {}", path.display()))?;
|
||||
|
||||
let root_instance = temp_tree.root();
|
||||
let children = root_instance.children();
|
||||
@@ -41,6 +45,32 @@ pub fn snapshot_rbxmx(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn syncback_rbxmx<'sync>(
|
||||
snapshot: &SyncbackSnapshot<'sync>,
|
||||
) -> anyhow::Result<SyncbackReturn<'sync>> {
|
||||
let inst = snapshot.new_inst();
|
||||
|
||||
let options =
|
||||
EncodeOptions::new().property_behavior(rbx_xml::EncodePropertyBehavior::WriteUnknown);
|
||||
|
||||
// Long-term, we probably want to have some logic for if this contains a
|
||||
// script. That's a future endeavor though.
|
||||
let mut serialized = Vec::new();
|
||||
rbx_xml::to_writer(
|
||||
&mut serialized,
|
||||
snapshot.new_tree(),
|
||||
&[inst.referent()],
|
||||
options,
|
||||
)
|
||||
.context("failed to serialize new rbxmx")?;
|
||||
|
||||
Ok(SyncbackReturn {
|
||||
fs_snapshot: FsSnapshot::new().with_added_file(&snapshot.path, serialized),
|
||||
children: Vec::new(),
|
||||
removed_children: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user