mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 15:16:07 +00:00
Apply patch sets by value in preparation for AppliedPatchSet
This commit is contained in:
@@ -105,7 +105,7 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
|
|||||||
let patch_set = compute_patch_set(&snapshot, &tree, root_id);
|
let patch_set = compute_patch_set(&snapshot, &tree, root_id);
|
||||||
|
|
||||||
log::trace!("Applying patch set");
|
log::trace!("Applying patch set");
|
||||||
apply_patch_set(&mut tree, &patch_set);
|
apply_patch_set(&mut tree, patch_set);
|
||||||
|
|
||||||
log::trace!("Opening output file for write");
|
log::trace!("Opening output file for write");
|
||||||
let mut file = BufWriter::new(File::create(&options.output_file)?);
|
let mut file = BufWriter::new(File::create(&options.output_file)?);
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ pub fn serve(options: &ServeOptions) -> Result<(), ServeError> {
|
|||||||
.expect("snapshot did not return an instance");
|
.expect("snapshot did not return an instance");
|
||||||
|
|
||||||
let patch_set = compute_patch_set(&snapshot, &tree, root_id);
|
let patch_set = compute_patch_set(&snapshot, &tree, root_id);
|
||||||
apply_patch_set(&mut tree, &patch_set);
|
apply_patch_set(&mut tree, patch_set);
|
||||||
|
|
||||||
let session = Arc::new(ServeSession::new(imfs, tree, maybe_project));
|
let session = Arc::new(ServeSession::new(imfs, tree, maybe_project));
|
||||||
let server = LiveServer::new(session);
|
let server = LiveServer::new(session);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ pub fn upload(options: UploadOptions) -> Result<(), UploadError> {
|
|||||||
let patch_set = compute_patch_set(&snapshot, &tree, root_id);
|
let patch_set = compute_patch_set(&snapshot, &tree, root_id);
|
||||||
|
|
||||||
log::trace!("Applying patch set");
|
log::trace!("Applying patch set");
|
||||||
apply_patch_set(&mut tree, &patch_set);
|
apply_patch_set(&mut tree, patch_set);
|
||||||
|
|
||||||
let root_id = tree.get_root_id();
|
let root_id = tree.get_root_id();
|
||||||
|
|
||||||
|
|||||||
@@ -9,18 +9,18 @@ use super::{
|
|||||||
InstancePropertiesWithMeta, InstanceSnapshot, RojoTree,
|
InstancePropertiesWithMeta, InstanceSnapshot, RojoTree,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn apply_patch_set(tree: &mut RojoTree, patch_set: &PatchSet) {
|
pub fn apply_patch_set(tree: &mut RojoTree, patch_set: PatchSet) {
|
||||||
let mut context = PatchApplyContext::default();
|
let mut context = PatchApplyContext::default();
|
||||||
|
|
||||||
for removed_id in &patch_set.removed_instances {
|
for removed_id in patch_set.removed_instances {
|
||||||
tree.remove_instance(*removed_id);
|
tree.remove_instance(removed_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
for add_patch in &patch_set.added_instances {
|
for add_patch in patch_set.added_instances {
|
||||||
apply_add_child(&mut context, tree, add_patch.parent_id, &add_patch.instance);
|
apply_add_child(&mut context, tree, add_patch.parent_id, &add_patch.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
for update_patch in &patch_set.updated_instances {
|
for update_patch in patch_set.updated_instances {
|
||||||
apply_update_child(&context, tree, update_patch);
|
apply_update_child(&context, tree, update_patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,43 +95,47 @@ fn apply_add_child(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_update_child(context: &PatchApplyContext, tree: &mut RojoTree, patch: &PatchUpdate) {
|
fn apply_update_child(context: &PatchApplyContext, tree: &mut RojoTree, patch: PatchUpdate) {
|
||||||
if let Some(metadata) = &patch.changed_metadata {
|
if let Some(metadata) = patch.changed_metadata {
|
||||||
tree.update_metadata(patch.id, metadata.clone());
|
tree.update_metadata(patch.id, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut instance = tree
|
let mut instance = tree
|
||||||
.get_instance_mut(patch.id)
|
.get_instance_mut(patch.id)
|
||||||
.expect("Instance referred to by patch does not exist");
|
.expect("Instance referred to by patch does not exist");
|
||||||
|
|
||||||
if let Some(name) = &patch.changed_name {
|
if let Some(name) = patch.changed_name {
|
||||||
*instance.name_mut() = name.clone();
|
*instance.name_mut() = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(class_name) = &patch.changed_class_name {
|
if let Some(class_name) = patch.changed_class_name {
|
||||||
*instance.class_name_mut() = class_name.clone();
|
*instance.class_name_mut() = class_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (key, property_entry) in &patch.changed_properties {
|
for (key, property_entry) in patch.changed_properties {
|
||||||
match property_entry {
|
match property_entry {
|
||||||
// Ref values need to be potentially rewritten from snapshot IDs to
|
// Ref values need to be potentially rewritten from snapshot IDs to
|
||||||
// instance IDs if they referred to an instance that was created as
|
// instance IDs if they referred to an instance that was created as
|
||||||
// part of this patch.
|
// part of this patch.
|
||||||
Some(RbxValue::Ref { value: Some(id) }) => {
|
Some(RbxValue::Ref { value: Some(id) }) => {
|
||||||
let new_id = context.snapshot_id_to_instance_id.get(id).unwrap_or(id);
|
let new_id = context
|
||||||
|
.snapshot_id_to_instance_id
|
||||||
|
.get(&id)
|
||||||
|
.copied()
|
||||||
|
.unwrap_or(id);
|
||||||
|
|
||||||
instance.properties_mut().insert(
|
instance.properties_mut().insert(
|
||||||
key.clone(),
|
key,
|
||||||
RbxValue::Ref {
|
RbxValue::Ref {
|
||||||
value: Some(*new_id),
|
value: Some(new_id),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Some(value) => {
|
Some(value) => {
|
||||||
instance.properties_mut().insert(key.clone(), value.clone());
|
instance.properties_mut().insert(key, value);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
instance.properties_mut().remove(key);
|
instance.properties_mut().remove(&key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,7 +186,7 @@ mod test {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
apply_patch_set(&mut tree, &patch_set);
|
apply_patch_set(&mut tree, patch_set);
|
||||||
|
|
||||||
let root_instance = tree.get_instance(root_id).unwrap();
|
let root_instance = tree.get_instance(root_id).unwrap();
|
||||||
let child_id = root_instance.children()[0];
|
let child_id = root_instance.children()[0];
|
||||||
@@ -235,7 +239,7 @@ mod test {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
apply_patch_set(&mut tree, &patch_set);
|
apply_patch_set(&mut tree, patch_set);
|
||||||
|
|
||||||
let expected_properties = hashmap! {
|
let expected_properties = hashmap! {
|
||||||
"Foo".to_owned() => RbxValue::Int32 { value: 8 },
|
"Foo".to_owned() => RbxValue::Int32 { value: 8 },
|
||||||
|
|||||||
Reference in New Issue
Block a user