mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 12:45:05 +00:00
* Mostly mechanical port bits * Almost there * It builds again! * Turn on all the code again * Tests compiling but not passing * Stub work for value resolution * Implement resolution minus enums and derived properties * Implement property descriptor resolution * Update referent snapshots * Update unions test project Using a place file instead of a model yields better error messages in Roblox Studio. * Add easy shortcut to testing with local rbx-dom * Update rbx-dom * Add enum resolution * Update init.meta.json to use UnresolvedValue * Expand value resolution support, add test * Filter SharedString values from web API * Add 'property' builder method to InstanceSnapshot * Change InstanceSnapshot/InstanceBuilder boundary * Fix remove_file crash * rustfmt * Update to latest rbx_dom_lua * Update dependencies, including rbx_dom_weak * Update to latest rbx-dom * Update dependencies * Update rbx-dom, fixing more bugs * Remove experimental warning on binary place builds * Remove unused imports
79 lines
2.3 KiB
Rust
79 lines
2.3 KiB
Rust
use std::path::Path;
|
|
|
|
use anyhow::Context;
|
|
use memofs::Vfs;
|
|
|
|
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
|
|
|
|
use super::middleware::SnapshotInstanceResult;
|
|
|
|
pub fn snapshot_rbxm(
|
|
context: &InstanceContext,
|
|
vfs: &Vfs,
|
|
path: &Path,
|
|
instance_name: &str,
|
|
) -> SnapshotInstanceResult {
|
|
let temp_tree = rbx_binary::from_reader_default(vfs.read(path)?.as_slice())
|
|
.with_context(|| format!("Malformed rbxm file: {}", path.display()))?;
|
|
|
|
let root_instance = temp_tree.root();
|
|
let children = root_instance.children();
|
|
|
|
if children.len() == 1 {
|
|
let snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0])
|
|
.name(instance_name)
|
|
.metadata(
|
|
InstanceMetadata::new()
|
|
.instigating_source(path)
|
|
.relevant_paths(vec![path.to_path_buf()])
|
|
.context(context),
|
|
);
|
|
|
|
Ok(Some(snapshot))
|
|
} else {
|
|
anyhow::bail!(
|
|
"Rojo doesn't have support for model files with zero or more than one top-level instances yet.\n\n \
|
|
Check the model file at path {}",
|
|
path.display()
|
|
);
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use super::*;
|
|
|
|
use memofs::{InMemoryFs, VfsSnapshot};
|
|
|
|
#[test]
|
|
fn model_from_vfs() {
|
|
let mut imfs = InMemoryFs::new();
|
|
imfs.load_snapshot(
|
|
"/foo.rbxm",
|
|
VfsSnapshot::file(include_bytes!("../../assets/test-folder.rbxm").to_vec()),
|
|
)
|
|
.unwrap();
|
|
|
|
let mut vfs = Vfs::new(imfs);
|
|
|
|
let instance_snapshot = snapshot_rbxm(
|
|
&InstanceContext::default(),
|
|
&mut vfs,
|
|
Path::new("/foo.rbxm"),
|
|
"foo",
|
|
)
|
|
.unwrap()
|
|
.unwrap();
|
|
|
|
assert_eq!(instance_snapshot.name, "foo");
|
|
assert_eq!(instance_snapshot.class_name, "Folder");
|
|
assert_eq!(instance_snapshot.children, Vec::new());
|
|
|
|
// We intentionally don't assert on properties. rbx_binary does not
|
|
// distinguish between String and BinaryString. The sample model was
|
|
// created by Roblox Studio and has an empty BinaryString "Tags"
|
|
// property that currently deserializes incorrectly.
|
|
// See: https://github.com/Roblox/rbx-dom/issues/49
|
|
}
|
|
}
|