Skip to content

Commit

Permalink
Merge branch 'syncback-tests' into syncback-internal-release
Browse files Browse the repository at this point in the history
  • Loading branch information
Corecii committed Jun 19, 2024
2 parents 8e6f2c9 + a6c206d commit 69a06f7
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: tests/rojo_test/syncback_util.rs
assertion_line: 48
expression: "visualize_fs_snapshot(&fs_snapshot, &output_path)"
---
added_files:
- "OnlyOneCopy\\child_of_one.luau"
- "ReplicatedStorage\\child_replicated_storage.luau"
added_dirs:
- OnlyOneCopy
- ReplicatedStorage
removed_files: []
removed_dirs: []

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- displace personality beam leadership occupy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- skate bottle vain nonsense tablet
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "child_but_not",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"$path": "ReplicatedStorage",
"OnlyOneCopy": {
"$path": "OnlyOneCopy"
}
}
}
}
Binary file added rojo-test/syncback-tests/child_but_not/input.rbxl
Binary file not shown.
12 changes: 12 additions & 0 deletions rojo-test/syncback-tests/child_but_not/output/default.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "child_but_not",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"$path": "ReplicatedStorage",
"OnlyOneCopy": {
"$path": "OnlyOneCopy"
}
}
}
}
11 changes: 10 additions & 1 deletion src/snapshot_middleware/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anyhow::Context;
use memofs::{DirEntry, IoResultExt, Vfs};

use crate::{
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot, InstigatingSource},
syncback::{FsSnapshot, SyncbackReturn, SyncbackSnapshot},
};

Expand Down Expand Up @@ -173,6 +173,15 @@ pub fn syncback_dir_no_meta<'sync>(
old_child.name()
);
continue;
} else if matches!(
old_child.metadata().instigating_source,
Some(InstigatingSource::ProjectNode { .. })
) {
log::debug!(
"Skipping instance {} because it originates in a project file",
old_child.name()
);
continue;
}
// This child exists in both doms. Pass it on.
children.push(snapshot.with_joined_path(*new_child_ref, Some(old_child.id()))?);
Expand Down
15 changes: 12 additions & 3 deletions src/snapshot_middleware/rbxmx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::path::Path;

use anyhow::Context;
use memofs::Vfs;
use rbx_xml::EncodeOptions;

use crate::{
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
Expand All @@ -18,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();
Expand Down Expand Up @@ -49,11 +50,19 @@ pub fn syncback_rbxmx<'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_default(&mut serialized, snapshot.new_tree(), &[inst.referent()])
.context("failed to serialize new rbxmx")?;
rbx_xml::to_writer(
&mut serialized,
snapshot.new_tree(),
&[inst.referent()],
options,
)
.context("failed to serialize new rbxmx")?;

Ok(SyncbackReturn {
inst_snapshot: InstanceSnapshot::from_instance(inst),
Expand Down
20 changes: 10 additions & 10 deletions src/variant_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ pub fn variant_eq(variant_a: &Variant, variant_b: &Variant) -> bool {
}
true
}
(Variant::OptionalCFrame(a), Variant::OptionalCFrame(b)) => {
if let (Some(a2), Some(b2)) = (a, b) {
vector_eq(&a2.position, &b2.position)
&& vector_eq(&a2.orientation.x, &b2.orientation.x)
&& vector_eq(&a2.orientation.y, &b2.orientation.y)
&& vector_eq(&a2.orientation.z, &b2.orientation.z)
} else {
false
(Variant::OptionalCFrame(a), Variant::OptionalCFrame(b)) => match (a, b) {
(Some(a), Some(b)) => {
vector_eq(&a.position, &b.position)
&& vector_eq(&a.orientation.x, &b.orientation.x)
&& vector_eq(&a.orientation.y, &b.orientation.y)
&& vector_eq(&a.orientation.z, &b.orientation.z)
}
}
(None, None) => true,
_ => false,
},
(Variant::PhysicalProperties(a), Variant::PhysicalProperties(b)) => match (a, b) {
(PhysicalProperties::Default, PhysicalProperties::Default) => true,
(PhysicalProperties::Custom(a2), PhysicalProperties::Custom(b2)) => {
Expand All @@ -143,7 +143,7 @@ pub fn variant_eq(variant_a: &Variant, variant_b: &Variant) -> bool {
&& approx_eq!(f32, a2.elasticity_weight, b2.elasticity_weight)
&& approx_eq!(f32, a2.friction_weight, b2.friction_weight)
}
(_, _) => false,
_ => false,
},
(Variant::Ray(a), Variant::Ray(b)) => {
vector_eq(&a.direction, &b.direction) && vector_eq(&a.origin, &b.origin)
Expand Down
1 change: 1 addition & 0 deletions tests/tests/syncback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ syncback_basic_test! {
project_all_middleware,
duplicate_rojo_id,
string_value_project,
child_but_not,
}

0 comments on commit 69a06f7

Please sign in to comment.