forked from rojo-rbx/rojo
Server component of config maps
This commit is contained in:
@@ -40,7 +40,7 @@ enum SourceProjectNode {
|
|||||||
impl SourceProjectNode {
|
impl SourceProjectNode {
|
||||||
pub fn into_project_node(self, project_file_location: &Path) -> ProjectNode {
|
pub fn into_project_node(self, project_file_location: &Path) -> ProjectNode {
|
||||||
match self {
|
match self {
|
||||||
SourceProjectNode::Instance { class_name, mut children, properties, .. } => {
|
SourceProjectNode::Instance { class_name, mut children, properties, ignore_unknown } => {
|
||||||
let mut new_children = HashMap::new();
|
let mut new_children = HashMap::new();
|
||||||
|
|
||||||
for (node_name, node) in children.drain() {
|
for (node_name, node) in children.drain() {
|
||||||
@@ -51,6 +51,9 @@ impl SourceProjectNode {
|
|||||||
class_name,
|
class_name,
|
||||||
children: new_children,
|
children: new_children,
|
||||||
properties,
|
properties,
|
||||||
|
config: InstanceProjectNodeConfig {
|
||||||
|
ignore_unknown,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
SourceProjectNode::SyncPoint { path: source_path } => {
|
SourceProjectNode::SyncPoint { path: source_path } => {
|
||||||
@@ -126,6 +129,11 @@ pub struct ProjectInitError;
|
|||||||
#[fail(display = "Project save error")]
|
#[fail(display = "Project save error")]
|
||||||
pub struct ProjectSaveError;
|
pub struct ProjectSaveError;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub struct InstanceProjectNodeConfig {
|
||||||
|
pub ignore_unknown: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub enum ProjectNode {
|
pub enum ProjectNode {
|
||||||
@@ -139,7 +147,7 @@ pub struct InstanceProjectNode {
|
|||||||
pub class_name: String,
|
pub class_name: String,
|
||||||
pub children: HashMap<String, ProjectNode>,
|
pub children: HashMap<String, ProjectNode>,
|
||||||
pub properties: HashMap<String, RbxValue>,
|
pub properties: HashMap<String, RbxValue>,
|
||||||
// ignore_unknown: bool,
|
pub config: InstanceProjectNodeConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use std::{
|
|||||||
use rbx_tree::{RbxTree, RbxValue, RbxId};
|
use rbx_tree::{RbxTree, RbxValue, RbxId};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
project::{Project, ProjectNode, InstanceProjectNode},
|
project::{Project, ProjectNode, InstanceProjectNode, InstanceProjectNodeConfig},
|
||||||
message_queue::MessageQueue,
|
message_queue::MessageQueue,
|
||||||
imfs::{Imfs, ImfsItem, ImfsFile},
|
imfs::{Imfs, ImfsItem, ImfsFile},
|
||||||
path_map::PathMap,
|
path_map::PathMap,
|
||||||
@@ -19,6 +19,7 @@ use crate::{
|
|||||||
pub struct RbxSession {
|
pub struct RbxSession {
|
||||||
tree: RbxTree,
|
tree: RbxTree,
|
||||||
path_map: PathMap<RbxId>,
|
path_map: PathMap<RbxId>,
|
||||||
|
config_map: HashMap<RbxId, InstanceProjectNodeConfig>,
|
||||||
message_queue: Arc<MessageQueue<InstanceChanges>>,
|
message_queue: Arc<MessageQueue<InstanceChanges>>,
|
||||||
imfs: Arc<Mutex<Imfs>>,
|
imfs: Arc<Mutex<Imfs>>,
|
||||||
project: Arc<Project>,
|
project: Arc<Project>,
|
||||||
@@ -31,15 +32,17 @@ impl RbxSession {
|
|||||||
message_queue: Arc<MessageQueue<InstanceChanges>>,
|
message_queue: Arc<MessageQueue<InstanceChanges>>,
|
||||||
) -> RbxSession {
|
) -> RbxSession {
|
||||||
let mut path_map = PathMap::new();
|
let mut path_map = PathMap::new();
|
||||||
|
let mut config_map = HashMap::new();
|
||||||
|
|
||||||
let tree = {
|
let tree = {
|
||||||
let temp_imfs = imfs.lock().unwrap();
|
let temp_imfs = imfs.lock().unwrap();
|
||||||
construct_initial_tree(&project, &temp_imfs, &mut path_map)
|
construct_initial_tree(&project, &temp_imfs, &mut path_map, &mut config_map)
|
||||||
};
|
};
|
||||||
|
|
||||||
RbxSession {
|
RbxSession {
|
||||||
tree,
|
tree,
|
||||||
path_map,
|
path_map,
|
||||||
|
config_map,
|
||||||
message_queue,
|
message_queue,
|
||||||
imfs,
|
imfs,
|
||||||
project,
|
project,
|
||||||
@@ -60,7 +63,7 @@ impl RbxSession {
|
|||||||
let snapshot = snapshot_instances_from_imfs(&imfs, &closest_path)
|
let snapshot = snapshot_instances_from_imfs(&imfs, &closest_path)
|
||||||
.expect("Could not generate instance snapshot");
|
.expect("Could not generate instance snapshot");
|
||||||
|
|
||||||
reconcile_subtree(&mut self.tree, instance_id, &snapshot, &mut self.path_map, &mut changes);
|
reconcile_subtree(&mut self.tree, instance_id, &snapshot, &mut self.path_map, &mut self.config_map, &mut changes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !changes.is_empty() {
|
if !changes.is_empty() {
|
||||||
@@ -124,17 +127,23 @@ impl RbxSession {
|
|||||||
pub fn get_tree(&self) -> &RbxTree {
|
pub fn get_tree(&self) -> &RbxTree {
|
||||||
&self.tree
|
&self.tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_config_map(&self) -> &HashMap<RbxId, InstanceProjectNodeConfig> {
|
||||||
|
&self.config_map
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn construct_oneoff_tree(project: &Project, imfs: &Imfs) -> RbxTree {
|
pub fn construct_oneoff_tree(project: &Project, imfs: &Imfs) -> RbxTree {
|
||||||
let mut path_map = PathMap::new();
|
let mut path_map = PathMap::new();
|
||||||
construct_initial_tree(project, imfs, &mut path_map)
|
let mut config_map = HashMap::new();
|
||||||
|
construct_initial_tree(project, imfs, &mut path_map, &mut config_map)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn construct_initial_tree(
|
fn construct_initial_tree(
|
||||||
project: &Project,
|
project: &Project,
|
||||||
imfs: &Imfs,
|
imfs: &Imfs,
|
||||||
path_map: &mut PathMap<RbxId>,
|
path_map: &mut PathMap<RbxId>,
|
||||||
|
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>,
|
||||||
) -> RbxTree {
|
) -> RbxTree {
|
||||||
let snapshot = construct_project_node(
|
let snapshot = construct_project_node(
|
||||||
imfs,
|
imfs,
|
||||||
@@ -143,7 +152,7 @@ fn construct_initial_tree(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let mut changes = InstanceChanges::default();
|
let mut changes = InstanceChanges::default();
|
||||||
let tree = reify_root(&snapshot, path_map, &mut changes);
|
let tree = reify_root(&snapshot, path_map, config_map, &mut changes);
|
||||||
|
|
||||||
tree
|
tree
|
||||||
}
|
}
|
||||||
@@ -185,6 +194,7 @@ fn construct_instance_node<'a>(
|
|||||||
properties: HashMap::new(),
|
properties: HashMap::new(),
|
||||||
children,
|
children,
|
||||||
source_path: None,
|
source_path: None,
|
||||||
|
config: Some(project_node.config.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,6 +253,7 @@ fn snapshot_instances_from_imfs<'a>(imfs: &'a Imfs, imfs_path: &Path) -> Option<
|
|||||||
properties,
|
properties,
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
source_path: Some(file.path.clone()),
|
source_path: Some(file.path.clone()),
|
||||||
|
config: None,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
ImfsItem::Directory(directory) => {
|
ImfsItem::Directory(directory) => {
|
||||||
@@ -257,6 +268,7 @@ fn snapshot_instances_from_imfs<'a>(imfs: &'a Imfs, imfs_path: &Path) -> Option<
|
|||||||
properties: HashMap::new(),
|
properties: HashMap::new(),
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
source_path: Some(directory.path.clone()),
|
source_path: Some(directory.path.clone()),
|
||||||
|
config: None,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ use std::{
|
|||||||
|
|
||||||
use rbx_tree::{RbxTree, RbxId, RbxInstance, RbxValue};
|
use rbx_tree::{RbxTree, RbxId, RbxInstance, RbxValue};
|
||||||
|
|
||||||
use crate::path_map::PathMap;
|
use crate::{
|
||||||
|
path_map::PathMap,
|
||||||
|
project::InstanceProjectNodeConfig,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||||
pub struct InstanceChanges {
|
pub struct InstanceChanges {
|
||||||
@@ -28,11 +31,13 @@ pub struct RbxSnapshotInstance<'a> {
|
|||||||
pub properties: HashMap<String, RbxValue>,
|
pub properties: HashMap<String, RbxValue>,
|
||||||
pub children: Vec<RbxSnapshotInstance<'a>>,
|
pub children: Vec<RbxSnapshotInstance<'a>>,
|
||||||
pub source_path: Option<PathBuf>,
|
pub source_path: Option<PathBuf>,
|
||||||
|
pub config: Option<InstanceProjectNodeConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reify_root(
|
pub fn reify_root(
|
||||||
snapshot: &RbxSnapshotInstance,
|
snapshot: &RbxSnapshotInstance,
|
||||||
path_map: &mut PathMap<RbxId>,
|
path_map: &mut PathMap<RbxId>,
|
||||||
|
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>,
|
||||||
changes: &mut InstanceChanges,
|
changes: &mut InstanceChanges,
|
||||||
) -> RbxTree {
|
) -> RbxTree {
|
||||||
let instance = reify_core(snapshot);
|
let instance = reify_core(snapshot);
|
||||||
@@ -43,10 +48,14 @@ pub fn reify_root(
|
|||||||
path_map.insert(source_path.clone(), root_id);
|
path_map.insert(source_path.clone(), root_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(config) = &snapshot.config {
|
||||||
|
config_map.insert(root_id, config.clone());
|
||||||
|
}
|
||||||
|
|
||||||
changes.added.insert(root_id);
|
changes.added.insert(root_id);
|
||||||
|
|
||||||
for child in &snapshot.children {
|
for child in &snapshot.children {
|
||||||
reify_subtree(child, &mut tree, root_id, path_map, changes);
|
reify_subtree(child, &mut tree, root_id, path_map, config_map, changes);
|
||||||
}
|
}
|
||||||
|
|
||||||
tree
|
tree
|
||||||
@@ -57,6 +66,7 @@ pub fn reify_subtree(
|
|||||||
tree: &mut RbxTree,
|
tree: &mut RbxTree,
|
||||||
parent_id: RbxId,
|
parent_id: RbxId,
|
||||||
path_map: &mut PathMap<RbxId>,
|
path_map: &mut PathMap<RbxId>,
|
||||||
|
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>,
|
||||||
changes: &mut InstanceChanges,
|
changes: &mut InstanceChanges,
|
||||||
) {
|
) {
|
||||||
let instance = reify_core(snapshot);
|
let instance = reify_core(snapshot);
|
||||||
@@ -66,10 +76,14 @@ pub fn reify_subtree(
|
|||||||
path_map.insert(source_path.clone(), id);
|
path_map.insert(source_path.clone(), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(config) = &snapshot.config {
|
||||||
|
config_map.insert(id, config.clone());
|
||||||
|
}
|
||||||
|
|
||||||
changes.added.insert(id);
|
changes.added.insert(id);
|
||||||
|
|
||||||
for child in &snapshot.children {
|
for child in &snapshot.children {
|
||||||
reify_subtree(child, tree, id, path_map, changes);
|
reify_subtree(child, tree, id, path_map, config_map, changes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,13 +92,14 @@ pub fn reconcile_subtree(
|
|||||||
id: RbxId,
|
id: RbxId,
|
||||||
snapshot: &RbxSnapshotInstance,
|
snapshot: &RbxSnapshotInstance,
|
||||||
path_map: &mut PathMap<RbxId>,
|
path_map: &mut PathMap<RbxId>,
|
||||||
|
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>,
|
||||||
changes: &mut InstanceChanges,
|
changes: &mut InstanceChanges,
|
||||||
) {
|
) {
|
||||||
if reconcile_instance_properties(tree.get_instance_mut(id).unwrap(), snapshot) {
|
if reconcile_instance_properties(tree.get_instance_mut(id).unwrap(), snapshot) {
|
||||||
changes.updated.insert(id);
|
changes.updated.insert(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
reconcile_instance_children(tree, id, snapshot, path_map, changes);
|
reconcile_instance_children(tree, id, snapshot, path_map, config_map, changes);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reify_core(snapshot: &RbxSnapshotInstance) -> RbxInstance {
|
fn reify_core(snapshot: &RbxSnapshotInstance) -> RbxInstance {
|
||||||
@@ -165,6 +180,7 @@ fn reconcile_instance_children(
|
|||||||
id: RbxId,
|
id: RbxId,
|
||||||
snapshot: &RbxSnapshotInstance,
|
snapshot: &RbxSnapshotInstance,
|
||||||
path_map: &mut PathMap<RbxId>,
|
path_map: &mut PathMap<RbxId>,
|
||||||
|
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>,
|
||||||
changes: &mut InstanceChanges,
|
changes: &mut InstanceChanges,
|
||||||
) {
|
) {
|
||||||
let children_ids = tree.get_instance(id).unwrap().get_children_ids().to_vec();
|
let children_ids = tree.get_instance(id).unwrap().get_children_ids().to_vec();
|
||||||
@@ -195,18 +211,19 @@ fn reconcile_instance_children(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for child_snapshot in &children_to_add {
|
for child_snapshot in &children_to_add {
|
||||||
reify_subtree(child_snapshot, tree, id, path_map, changes);
|
reify_subtree(child_snapshot, tree, id, path_map, config_map, changes);
|
||||||
}
|
}
|
||||||
|
|
||||||
for child_id in &children_to_remove {
|
for child_id in &children_to_remove {
|
||||||
if let Some(subtree) = tree.remove_instance(*child_id) {
|
if let Some(subtree) = tree.remove_instance(*child_id) {
|
||||||
for id in subtree.iter_all_ids() {
|
for id in subtree.iter_all_ids() {
|
||||||
|
config_map.remove(&id);
|
||||||
changes.removed.insert(id);
|
changes.removed.insert(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (child_id, child_snapshot) in &children_to_update {
|
for (child_id, child_snapshot) in &children_to_update {
|
||||||
reconcile_subtree(tree, *child_id, child_snapshot, path_map, changes);
|
reconcile_subtree(tree, *child_id, child_snapshot, path_map, config_map, changes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ use rbx_tree::{RbxId, RootedRbxInstance};
|
|||||||
use crate::{
|
use crate::{
|
||||||
session::Session,
|
session::Session,
|
||||||
session_id::SessionId,
|
session_id::SessionId,
|
||||||
project::Project,
|
project::InstanceProjectNodeConfig,
|
||||||
rbx_snapshot::InstanceChanges,
|
rbx_snapshot::InstanceChanges,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ pub struct ServerInfoResponse<'a> {
|
|||||||
pub server_version: &'a str,
|
pub server_version: &'a str,
|
||||||
pub protocol_version: u64,
|
pub protocol_version: u64,
|
||||||
pub root_instance_id: RbxId,
|
pub root_instance_id: RbxId,
|
||||||
pub project: Cow<'a, Project>,
|
pub config_map: Cow<'a, HashMap<RbxId, InstanceProjectNodeConfig>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@@ -78,7 +78,7 @@ impl Server {
|
|||||||
protocol_version: 2,
|
protocol_version: 2,
|
||||||
session_id: self.session.session_id,
|
session_id: self.session.session_id,
|
||||||
root_instance_id: tree.get_root_id(),
|
root_instance_id: tree.get_root_id(),
|
||||||
project: Cow::Borrowed(&self.session.project),
|
config_map: Cow::Borrowed(rbx_session.get_config_map()),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user