forked from rojo-rbx/rojo
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);
|
||||
|
||||
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");
|
||||
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");
|
||||
|
||||
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 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);
|
||||
|
||||
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();
|
||||
|
||||
|
||||
@@ -9,18 +9,18 @@ use super::{
|
||||
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();
|
||||
|
||||
for removed_id in &patch_set.removed_instances {
|
||||
tree.remove_instance(*removed_id);
|
||||
for removed_id in patch_set.removed_instances {
|
||||
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);
|
||||
}
|
||||
|
||||
for update_patch in &patch_set.updated_instances {
|
||||
for update_patch in patch_set.updated_instances {
|
||||
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) {
|
||||
if let Some(metadata) = &patch.changed_metadata {
|
||||
tree.update_metadata(patch.id, metadata.clone());
|
||||
fn apply_update_child(context: &PatchApplyContext, tree: &mut RojoTree, patch: PatchUpdate) {
|
||||
if let Some(metadata) = patch.changed_metadata {
|
||||
tree.update_metadata(patch.id, metadata);
|
||||
}
|
||||
|
||||
let mut instance = tree
|
||||
.get_instance_mut(patch.id)
|
||||
.expect("Instance referred to by patch does not exist");
|
||||
|
||||
if let Some(name) = &patch.changed_name {
|
||||
*instance.name_mut() = name.clone();
|
||||
if let Some(name) = patch.changed_name {
|
||||
*instance.name_mut() = name;
|
||||
}
|
||||
|
||||
if let Some(class_name) = &patch.changed_class_name {
|
||||
*instance.class_name_mut() = class_name.clone();
|
||||
if let Some(class_name) = patch.changed_class_name {
|
||||
*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 {
|
||||
// Ref values need to be potentially rewritten from snapshot IDs to
|
||||
// instance IDs if they referred to an instance that was created as
|
||||
// part of this patch.
|
||||
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(
|
||||
key.clone(),
|
||||
key,
|
||||
RbxValue::Ref {
|
||||
value: Some(*new_id),
|
||||
value: Some(new_id),
|
||||
},
|
||||
);
|
||||
}
|
||||
Some(value) => {
|
||||
instance.properties_mut().insert(key.clone(), value.clone());
|
||||
instance.properties_mut().insert(key, value);
|
||||
}
|
||||
None => {
|
||||
instance.properties_mut().remove(key);
|
||||
instance.properties_mut().remove(&key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,7 +186,7 @@ mod test {
|
||||
..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 child_id = root_instance.children()[0];
|
||||
@@ -235,7 +239,7 @@ mod test {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
apply_patch_set(&mut tree, &patch_set);
|
||||
apply_patch_set(&mut tree, patch_set);
|
||||
|
||||
let expected_properties = hashmap! {
|
||||
"Foo".to_owned() => RbxValue::Int32 { value: 8 },
|
||||
|
||||
Reference in New Issue
Block a user