mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-25 04:54:07 +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()
|
return api:readAll()
|
||||||
:andThen(function(instances)
|
:andThen(function(instances)
|
||||||
|
local visited = {}
|
||||||
for id, instance in pairs(instances) do
|
for id, instance in pairs(instances) do
|
||||||
|
visited[id] = true
|
||||||
if id ~= "0" then
|
if id ~= "0" then
|
||||||
local existing = created[id]
|
local existing = created[id]
|
||||||
if existing ~= nil then
|
if existing ~= nil then
|
||||||
|
|
@ -45,6 +47,12 @@ function Session.new()
|
||||||
created[id].Parent = created[tostring(instance.parent)]
|
created[id].Parent = created[tostring(instance.parent)]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for id, object in pairs(created) do
|
||||||
|
if not visited[id] then
|
||||||
|
object:Destroy()
|
||||||
|
end
|
||||||
|
end
|
||||||
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
|
/// Creates a PathBuf out of the `FileRoute` based on the given partition
|
||||||
/// `Path`.
|
/// `Path`.
|
||||||
pub fn to_path_buf(&self, partition_path: &Path) -> PathBuf {
|
pub fn to_path_buf(&self, partition_path: &Path) -> PathBuf {
|
||||||
|
|
|
||||||
|
|
@ -20,18 +20,24 @@ fn file_to_instances(
|
||||||
let mut properties = HashMap::new();
|
let mut properties = HashMap::new();
|
||||||
properties.insert("Value".to_string(), contents.clone());
|
properties.insert("Value".to_string(), contents.clone());
|
||||||
|
|
||||||
let (primary_id, parent) = match instances_by_route.get(&file_item.get_route()) {
|
let primary_id = match instances_by_route.get(&file_item.get_route()) {
|
||||||
Some(&id) => {
|
Some(&id) => id,
|
||||||
(id, output.get(&id).unwrap().parent)
|
|
||||||
},
|
|
||||||
None => {
|
None => {
|
||||||
let id = get_id();
|
let id = get_id();
|
||||||
instances_by_route.insert(route.clone(), 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 {
|
output.insert(primary_id, RbxInstance {
|
||||||
name: route.name(partition).to_string(),
|
name: route.name(partition).to_string(),
|
||||||
class_name: "StringValue".to_string(),
|
class_name: "StringValue".to_string(),
|
||||||
|
|
@ -42,18 +48,24 @@ fn file_to_instances(
|
||||||
(primary_id, vec![primary_id])
|
(primary_id, vec![primary_id])
|
||||||
},
|
},
|
||||||
FileItem::Directory { children, route } => {
|
FileItem::Directory { children, route } => {
|
||||||
let (primary_id, parent) = match instances_by_route.get(&file_item.get_route()) {
|
let primary_id = match instances_by_route.get(&file_item.get_route()) {
|
||||||
Some(&id) => {
|
Some(&id) => id,
|
||||||
(id, output.get(&id).unwrap().parent)
|
|
||||||
},
|
|
||||||
None => {
|
None => {
|
||||||
let id = get_id();
|
let id = get_id();
|
||||||
instances_by_route.insert(route.clone(), 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 {
|
output.insert(primary_id, RbxInstance {
|
||||||
name: route.name(partition).to_string(),
|
name: route.name(partition).to_string(),
|
||||||
class_name: "Folder".to_string(),
|
class_name: "Folder".to_string(),
|
||||||
|
|
@ -141,6 +153,13 @@ impl RbxSession {
|
||||||
self.message_session.push_messages(&messages);
|
self.message_session.push_messages(&messages);
|
||||||
},
|
},
|
||||||
FileChange::Deleted(route) => {
|
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) => {
|
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?
|
// Did the client miss any messages since the last subscribe?
|
||||||
{
|
{
|
||||||
let messages = config.message_session.messages.read().unwrap();
|
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 {
|
if cursor < messages.len() as i32 - 1 {
|
||||||
let new_messages = &messages[(cursor + 1) as usize..];
|
let new_messages = &messages[(cursor + 1) as usize..];
|
||||||
let new_cursor = cursor + new_messages.len() as i32;
|
let new_cursor = cursor + new_messages.len() as i32;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue