Skip to content

Commit

Permalink
Reserialize HumanoidDescription properties that aren't deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekkonot committed Sep 24, 2024
1 parent 61f9d2b commit 4cf075f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/syncback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub fn syncback_loop(
}
}
}
reserialize_humanoid_descriptions(&mut new_tree);

// Handle removing the current camera.
if let Some(syncback_rules) = &project.syncback_rules {
Expand Down Expand Up @@ -511,3 +512,39 @@ fn strip_unknown_root_children(new: &mut WeakDom, old: &RojoTree) {
new.destroy(child_ref);
}
}

/// HACK: There are non-deterministic properties on `HumanoidDescription`
/// and they cause spurious diffs. We can fix that by reserializing them
/// manually.
fn reserialize_humanoid_descriptions(dom: &mut WeakDom) {
log::debug!("Fixing serialization of HumanoidDescriptions");
for referent in descendants(dom, dom.root_ref()) {
let inst = dom
.get_by_ref_mut(referent)
.expect("all descendants should be in the DOM");
if inst.class != "HumanoidDescription" {
continue;
}
if let Some(Variant::String(content)) = inst.properties.remove("EquippedEmotesDataInternal")
{
inst.properties.insert(
"EquippedEmotesDataInternal".into(),
split_and_reorder(content).into(),
);
}
if let Some(Variant::String(content)) = inst.properties.remove("EmotesDataInternal") {
inst.properties.insert(
"EmotesDataInternal".into(),
split_and_reorder(content).into(),
);
}
}
}

fn split_and_reorder(content: String) -> String {
let mut subsections: Vec<_> = content.split("\\").collect();
subsections.pop();
subsections.sort();
subsections.push("");
subsections.join("\\")
}

0 comments on commit 4cf075f

Please sign in to comment.