mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-23 14:15:24 +00:00
Add support for adding new instances, very pedantically
This commit is contained in:
@@ -7,6 +7,7 @@ use std::sync::{Arc, Mutex};
|
|||||||
|
|
||||||
use crossbeam_channel::{select, Receiver, Sender};
|
use crossbeam_channel::{select, Receiver, Sender};
|
||||||
use jod_thread::JoinHandle;
|
use jod_thread::JoinHandle;
|
||||||
|
use rbx_dom_weak::RbxId;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
message_queue::MessageQueue,
|
message_queue::MessageQueue,
|
||||||
@@ -69,56 +70,24 @@ impl ChangeProcessor {
|
|||||||
|
|
||||||
match event {
|
match event {
|
||||||
VfsEvent::Created(path) | VfsEvent::Modified(path) | VfsEvent::Removed(path) => {
|
VfsEvent::Created(path) | VfsEvent::Modified(path) | VfsEvent::Removed(path) => {
|
||||||
let affected_ids = tree.get_ids_at_path(&path).to_vec();
|
let mut current_path = path.as_path();
|
||||||
|
let affected_ids = loop {
|
||||||
|
let ids = tree.get_ids_at_path(¤t_path);
|
||||||
|
|
||||||
if affected_ids.len() == 0 {
|
log::trace!("Path {} affects IDs {:?}", current_path.display(), ids);
|
||||||
log::info!("No instances were affected by this change.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for id in affected_ids {
|
if !ids.is_empty() {
|
||||||
let metadata = tree.get_metadata(id)
|
break ids.to_vec();
|
||||||
.expect("metadata missing for instance present in tree");
|
}
|
||||||
|
|
||||||
let instigating_source = match &metadata.instigating_source {
|
log::trace!("Trying parent path...");
|
||||||
Some(path) => path,
|
match current_path.parent() {
|
||||||
None => {
|
Some(parent) => current_path = parent,
|
||||||
log::warn!("Instance {} did not have an instigating source, but was considered for an update.", id);
|
None => break Vec::new(),
|
||||||
log::warn!("This is a Rojo bug. Please file an issue!");
|
}
|
||||||
continue;
|
};
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let snapshot = match instigating_source {
|
update_affected_instances(&mut tree, &vfs, &mut applied_patches, &affected_ids)
|
||||||
InstigatingSource::Path(path) => {
|
|
||||||
let entry = vfs
|
|
||||||
.get(path)
|
|
||||||
.expect("could not get instigating path from filesystem");
|
|
||||||
|
|
||||||
// TODO: Use persisted snapshot
|
|
||||||
// context struct instead of
|
|
||||||
// recreating it every time.
|
|
||||||
let snapshot = snapshot_from_vfs(&mut InstanceSnapshotContext::default(), &vfs, &entry)
|
|
||||||
.expect("snapshot failed")
|
|
||||||
.expect("snapshot did not return an instance");
|
|
||||||
|
|
||||||
snapshot
|
|
||||||
}
|
|
||||||
InstigatingSource::ProjectNode(_, _) => {
|
|
||||||
log::warn!("Instance {} had an instigating source that was a project node, which is not yet supported.", id);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
log::trace!("Computed snapshot: {:#?}", snapshot);
|
|
||||||
|
|
||||||
let patch_set = compute_patch_set(&snapshot, &tree, id);
|
|
||||||
let applied_patch_set = apply_patch_set(&mut tree, patch_set);
|
|
||||||
|
|
||||||
log::trace!("Applied patch: {:#?}", applied_patch_set);
|
|
||||||
|
|
||||||
applied_patches.push(applied_patch_set);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,3 +112,56 @@ impl Drop for ChangeProcessor {
|
|||||||
let _ = self.shutdown_sender.send(());
|
let _ = self.shutdown_sender.send(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_affected_instances<F: VfsFetcher>(
|
||||||
|
tree: &mut RojoTree,
|
||||||
|
vfs: &Vfs<F>,
|
||||||
|
applied_patches: &mut Vec<AppliedPatchSet>,
|
||||||
|
affected_ids: &[RbxId],
|
||||||
|
) {
|
||||||
|
for &id in affected_ids {
|
||||||
|
let metadata = tree
|
||||||
|
.get_metadata(id)
|
||||||
|
.expect("metadata missing for instance present in tree");
|
||||||
|
|
||||||
|
let instigating_source = match &metadata.instigating_source {
|
||||||
|
Some(path) => path,
|
||||||
|
None => {
|
||||||
|
log::warn!("Instance {} did not have an instigating source, but was considered for an update.", id);
|
||||||
|
log::warn!("This is a Rojo bug. Please file an issue!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let snapshot = match instigating_source {
|
||||||
|
InstigatingSource::Path(path) => {
|
||||||
|
let entry = vfs
|
||||||
|
.get(path)
|
||||||
|
.expect("could not get instigating path from filesystem");
|
||||||
|
|
||||||
|
// TODO: Use persisted snapshot
|
||||||
|
// context struct instead of
|
||||||
|
// recreating it every time.
|
||||||
|
let snapshot =
|
||||||
|
snapshot_from_vfs(&mut InstanceSnapshotContext::default(), &vfs, &entry)
|
||||||
|
.expect("snapshot failed")
|
||||||
|
.expect("snapshot did not return an instance");
|
||||||
|
|
||||||
|
snapshot
|
||||||
|
}
|
||||||
|
InstigatingSource::ProjectNode(_, _) => {
|
||||||
|
log::warn!("Instance {} had an instigating source that was a project node, which is not yet supported.", id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
log::trace!("Computed snapshot: {:#?}", snapshot);
|
||||||
|
|
||||||
|
let patch_set = compute_patch_set(&snapshot, &tree, id);
|
||||||
|
let applied_patch_set = apply_patch_set(tree, patch_set);
|
||||||
|
|
||||||
|
log::trace!("Applied patch: {:#?}", applied_patch_set);
|
||||||
|
|
||||||
|
applied_patches.push(applied_patch_set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user