mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Deletion, wrangling parents a little bit
This commit is contained in:
parent
8729de1312
commit
e4f35b29bd
4 changed files with 60 additions and 10 deletions
|
|
@ -21,7 +21,9 @@ function Session.new()
|
|||
|
||||
return api:readAll()
|
||||
:andThen(function(instances)
|
||||
local visited = {}
|
||||
for id, instance in pairs(instances) do
|
||||
visited[id] = true
|
||||
if id ~= "0" then
|
||||
local existing = created[id]
|
||||
if existing ~= nil then
|
||||
|
|
@ -45,6 +47,12 @@ function Session.new()
|
|||
created[id].Parent = created[tostring(instance.parent)]
|
||||
end
|
||||
end
|
||||
|
||||
for id, object in pairs(created) do
|
||||
if not visited[id] then
|
||||
object:Destroy()
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,20 @@ impl FileRoute {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn parent(&self) -> Option<FileRoute> {
|
||||
if self.route.len() == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut new_route = self.route.clone();
|
||||
new_route.pop();
|
||||
|
||||
Some(FileRoute {
|
||||
partition: self.partition.clone(),
|
||||
route: new_route,
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates a PathBuf out of the `FileRoute` based on the given partition
|
||||
/// `Path`.
|
||||
pub fn to_path_buf(&self, partition_path: &Path) -> PathBuf {
|
||||
|
|
|
|||
|
|
@ -20,18 +20,24 @@ fn file_to_instances(
|
|||
let mut properties = HashMap::new();
|
||||
properties.insert("Value".to_string(), contents.clone());
|
||||
|
||||
let (primary_id, parent) = match instances_by_route.get(&file_item.get_route()) {
|
||||
Some(&id) => {
|
||||
(id, output.get(&id).unwrap().parent)
|
||||
},
|
||||
let primary_id = match instances_by_route.get(&file_item.get_route()) {
|
||||
Some(&id) => id,
|
||||
None => {
|
||||
let id = get_id();
|
||||
instances_by_route.insert(route.clone(), id);
|
||||
|
||||
(id, None)
|
||||
id
|
||||
},
|
||||
};
|
||||
|
||||
let parent = match file_item.get_route().parent() {
|
||||
Some(parent_route) => match instances_by_route.get(&parent_route) {
|
||||
Some(parent_id) => Some(*parent_id),
|
||||
None => None,
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
|
||||
output.insert(primary_id, RbxInstance {
|
||||
name: route.name(partition).to_string(),
|
||||
class_name: "StringValue".to_string(),
|
||||
|
|
@ -42,18 +48,24 @@ fn file_to_instances(
|
|||
(primary_id, vec![primary_id])
|
||||
},
|
||||
FileItem::Directory { children, route } => {
|
||||
let (primary_id, parent) = match instances_by_route.get(&file_item.get_route()) {
|
||||
Some(&id) => {
|
||||
(id, output.get(&id).unwrap().parent)
|
||||
},
|
||||
let primary_id = match instances_by_route.get(&file_item.get_route()) {
|
||||
Some(&id) => id,
|
||||
None => {
|
||||
let id = get_id();
|
||||
instances_by_route.insert(route.clone(), id);
|
||||
|
||||
(id, None)
|
||||
id
|
||||
},
|
||||
};
|
||||
|
||||
let parent = match file_item.get_route().parent() {
|
||||
Some(parent_route) => match instances_by_route.get(&parent_route) {
|
||||
Some(parent_id) => Some(*parent_id),
|
||||
None => None,
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
|
||||
output.insert(primary_id, RbxInstance {
|
||||
name: route.name(partition).to_string(),
|
||||
class_name: "Folder".to_string(),
|
||||
|
|
@ -141,6 +153,13 @@ impl RbxSession {
|
|||
self.message_session.push_messages(&messages);
|
||||
},
|
||||
FileChange::Deleted(route) => {
|
||||
match self.instances_by_route.get(route) {
|
||||
Some(id) => {
|
||||
self.instances.remove(id);
|
||||
self.message_session.push_messages(&[Message::InstanceChanged { id: *id }]);
|
||||
},
|
||||
None => (),
|
||||
}
|
||||
},
|
||||
FileChange::Moved(from_route, to_route) => {
|
||||
},
|
||||
|
|
|
|||
|
|
@ -68,6 +68,15 @@ pub fn start(config: WebConfig) {
|
|||
// Did the client miss any messages since the last subscribe?
|
||||
{
|
||||
let messages = config.message_session.messages.read().unwrap();
|
||||
|
||||
if cursor > messages.len() as i32 {
|
||||
return json_response(SubscribeResponse {
|
||||
server_id: &server_id,
|
||||
messages: &[],
|
||||
message_cursor: messages.len() as i32 - 1,
|
||||
});
|
||||
}
|
||||
|
||||
if cursor < messages.len() as i32 - 1 {
|
||||
let new_messages = &messages[(cursor + 1) as usize..];
|
||||
let new_cursor = cursor + new_messages.len() as i32;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue