mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-26 15:46:28 +00:00
Improve init script support
- init.server.lua and init.client.lua are now supported again - Updating an init script no longer nukes its parent
This commit is contained in:
@@ -16,6 +16,10 @@ use crate::{
|
|||||||
rbx_snapshot::{RbxSnapshotInstance, InstanceChanges, reify_root, reconcile_subtree},
|
rbx_snapshot::{RbxSnapshotInstance, InstanceChanges, reify_root, reconcile_subtree},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const INIT_SCRIPT: &str = "init.lua";
|
||||||
|
const INIT_SERVER_SCRIPT: &str = "init.server.lua";
|
||||||
|
const INIT_CLIENT_SCRIPT: &str = "init.client.lua";
|
||||||
|
|
||||||
pub struct RbxSession {
|
pub struct RbxSession {
|
||||||
tree: RbxTree,
|
tree: RbxTree,
|
||||||
path_map: PathMap<RbxId>,
|
path_map: PathMap<RbxId>,
|
||||||
@@ -23,7 +27,6 @@ pub struct RbxSession {
|
|||||||
sync_point_names: HashMap<PathBuf, String>,
|
sync_point_names: HashMap<PathBuf, String>,
|
||||||
message_queue: Arc<MessageQueue<InstanceChanges>>,
|
message_queue: Arc<MessageQueue<InstanceChanges>>,
|
||||||
imfs: Arc<Mutex<Imfs>>,
|
imfs: Arc<Mutex<Imfs>>,
|
||||||
project: Arc<Project>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RbxSession {
|
impl RbxSession {
|
||||||
@@ -48,11 +51,12 @@ impl RbxSession {
|
|||||||
sync_point_names,
|
sync_point_names,
|
||||||
message_queue,
|
message_queue,
|
||||||
imfs,
|
imfs,
|
||||||
project,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path_created_or_updated(&mut self, path: &Path) {
|
fn path_created_or_updated(&mut self, path: &Path) {
|
||||||
|
// TODO: Track paths actually updated in each step so we can ignore
|
||||||
|
// redundant changes.
|
||||||
let mut changes = InstanceChanges::default();
|
let mut changes = InstanceChanges::default();
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -60,17 +64,34 @@ impl RbxSession {
|
|||||||
let root_path = imfs.get_root_for_path(path)
|
let root_path = imfs.get_root_for_path(path)
|
||||||
.expect("Path was outside in-memory filesystem roots");
|
.expect("Path was outside in-memory filesystem roots");
|
||||||
|
|
||||||
let closest_path = self.path_map.descend(root_path, path);
|
// Find the closest instance in the tree that still exists
|
||||||
let &instance_id = self.path_map.get(&closest_path).unwrap();
|
let mut path_to_snapshot = self.path_map.descend(root_path, path);
|
||||||
|
let &instance_id = self.path_map.get(&path_to_snapshot).unwrap();
|
||||||
|
|
||||||
trace!("Snapshotting path {}", closest_path.display());
|
// If this is a file that might affect its parent if modified, we
|
||||||
|
// should snapshot the parent instead.
|
||||||
|
match path_to_snapshot.file_name().unwrap().to_str() {
|
||||||
|
Some(INIT_SCRIPT) | Some(INIT_SERVER_SCRIPT) | Some(INIT_CLIENT_SCRIPT) => {
|
||||||
|
path_to_snapshot.pop();
|
||||||
|
},
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
|
||||||
let snapshot = snapshot_instances_from_imfs(&imfs, &closest_path, &mut self.sync_point_names)
|
trace!("Snapshotting path {}", path_to_snapshot.display());
|
||||||
.unwrap_or_else(|| panic!("Could not generate instance snapshot for path {}", closest_path.display()));
|
|
||||||
|
let snapshot = snapshot_instances_from_imfs(&imfs, &path_to_snapshot, &mut self.sync_point_names)
|
||||||
|
.unwrap_or_else(|| panic!("Could not generate instance snapshot for path {}", path_to_snapshot.display()));
|
||||||
|
|
||||||
trace!("Snapshot: {:#?}", snapshot);
|
trace!("Snapshot: {:#?}", snapshot);
|
||||||
|
|
||||||
reconcile_subtree(&mut self.tree, instance_id, &snapshot, &mut self.path_map, &mut self.instance_metadata_map, &mut changes);
|
reconcile_subtree(
|
||||||
|
&mut self.tree,
|
||||||
|
instance_id,
|
||||||
|
&snapshot,
|
||||||
|
&mut self.path_map,
|
||||||
|
&mut self.instance_metadata_map,
|
||||||
|
&mut changes,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if changes.is_empty() {
|
if changes.is_empty() {
|
||||||
@@ -272,10 +293,16 @@ fn snapshot_instances_from_imfs<'a>(
|
|||||||
},
|
},
|
||||||
ImfsItem::Directory(directory) => {
|
ImfsItem::Directory(directory) => {
|
||||||
// TODO: Expand init support to handle server and client scripts
|
// TODO: Expand init support to handle server and client scripts
|
||||||
let init_path = directory.path.join("init.lua");
|
let init_path = directory.path.join(INIT_SCRIPT);
|
||||||
|
let init_server_path = directory.path.join(INIT_SERVER_SCRIPT);
|
||||||
|
let init_client_path = directory.path.join(INIT_CLIENT_SCRIPT);
|
||||||
|
|
||||||
let mut instance = if directory.children.contains(&init_path) {
|
let mut instance = if directory.children.contains(&init_path) {
|
||||||
snapshot_instances_from_imfs(imfs, &init_path, sync_point_names)?
|
snapshot_instances_from_imfs(imfs, &init_path, sync_point_names)?
|
||||||
|
} else if directory.children.contains(&init_server_path) {
|
||||||
|
snapshot_instances_from_imfs(imfs, &init_server_path, sync_point_names)?
|
||||||
|
} else if directory.children.contains(&init_client_path) {
|
||||||
|
snapshot_instances_from_imfs(imfs, &init_client_path, sync_point_names)?
|
||||||
} else {
|
} else {
|
||||||
RbxSnapshotInstance {
|
RbxSnapshotInstance {
|
||||||
class_name: Cow::Borrowed("Folder"),
|
class_name: Cow::Borrowed("Folder"),
|
||||||
@@ -294,8 +321,13 @@ fn snapshot_instances_from_imfs<'a>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
for child_path in &directory.children {
|
for child_path in &directory.children {
|
||||||
if child_path != &init_path {
|
match child_path.file_name().unwrap().to_str() {
|
||||||
instance.children.push(snapshot_instances_from_imfs(imfs, child_path, sync_point_names)?);
|
Some(INIT_SCRIPT) | Some(INIT_SERVER_SCRIPT) | Some(INIT_CLIENT_SCRIPT) => {
|
||||||
|
// These modify the parent, we can skip them
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
instance.children.push(snapshot_instances_from_imfs(imfs, child_path, sync_point_names)?);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user