mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 14:01:37 +00:00
Metadata per instance is a go
This commit is contained in:
parent
f2dc1d8898
commit
3f526cd127
4 changed files with 65 additions and 48 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use std::{
|
||||
borrow::Cow,
|
||||
collections::HashMap,
|
||||
path::Path,
|
||||
path::{Path, PathBuf},
|
||||
str,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
|
@ -23,17 +23,17 @@ const INIT_SCRIPT: &str = "init.lua";
|
|||
const INIT_SERVER_SCRIPT: &str = "init.server.lua";
|
||||
const INIT_CLIENT_SCRIPT: &str = "init.client.lua";
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct MetadataPerPath {
|
||||
pub instance_id: Option<RbxId>,
|
||||
pub instance_name: Option<String>,
|
||||
}
|
||||
|
||||
// #[derive(Debug, Default, Serialize, Deserialize)]
|
||||
// pub struct MetadataPerInstance {
|
||||
// pub source_path: Option<PathBuf>,
|
||||
// pub ignore_unknown_instances: bool,
|
||||
// }
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct MetadataPerInstance {
|
||||
pub source_path: Option<PathBuf>,
|
||||
pub ignore_unknown_instances: bool,
|
||||
}
|
||||
|
||||
pub struct RbxSession {
|
||||
tree: RbxTree,
|
||||
|
|
@ -45,7 +45,7 @@ pub struct RbxSession {
|
|||
// TODO: Hold this map, inverted from metadata_per_path
|
||||
// metadata_per_instance: PathMap<MetadataPerInstance>,
|
||||
|
||||
instance_metadata_map: HashMap<RbxId, InstanceProjectNodeMetadata>,
|
||||
instance_metadata_map: HashMap<RbxId, MetadataPerInstance>,
|
||||
message_queue: Arc<MessageQueue<InstanceChanges>>,
|
||||
imfs: Arc<Mutex<Imfs>>,
|
||||
}
|
||||
|
|
@ -182,7 +182,7 @@ impl RbxSession {
|
|||
&self.tree
|
||||
}
|
||||
|
||||
pub fn get_instance_metadata(&self, id: RbxId) -> Option<&InstanceProjectNodeMetadata> {
|
||||
pub fn get_instance_metadata(&self, id: RbxId) -> Option<&MetadataPerInstance> {
|
||||
self.instance_metadata_map.get(&id)
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +201,7 @@ fn reify_initial_tree(
|
|||
project: &Project,
|
||||
imfs: &Imfs,
|
||||
metadata_per_path: &mut PathMap<MetadataPerPath>,
|
||||
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
|
||||
instance_metadata_map: &mut HashMap<RbxId, MetadataPerInstance>,
|
||||
) -> RbxTree {
|
||||
let mut meta = SnapshotMetadata {
|
||||
metadata_per_path,
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ use crate::{
|
|||
},
|
||||
path_map::PathMap,
|
||||
// TODO: Move MetadataPerPath into this module?
|
||||
rbx_session::MetadataPerPath,
|
||||
rbx_session::{MetadataPerPath, MetadataPerInstance},
|
||||
};
|
||||
|
||||
const INIT_MODULE_NAME: &str = "init.lua";
|
||||
|
|
@ -120,8 +120,10 @@ fn snapshot_instance_node<'source>(
|
|||
name: instance_name,
|
||||
properties: node.properties.clone(),
|
||||
children,
|
||||
source_path: None,
|
||||
metadata: Some(node.metadata.clone()),
|
||||
metadata: MetadataPerInstance {
|
||||
source_path: None,
|
||||
ignore_unknown_instances: node.metadata.ignore_unknown_instances,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
@ -202,8 +204,10 @@ fn snapshot_imfs_directory<'source>(
|
|||
name: snapshot_name,
|
||||
properties: HashMap::new(),
|
||||
children: Vec::new(),
|
||||
source_path: Some(directory.path.to_owned()),
|
||||
metadata: None,
|
||||
metadata: MetadataPerInstance {
|
||||
source_path: Some(directory.path.to_owned()),
|
||||
ignore_unknown_instances: false,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -285,8 +289,10 @@ fn snapshot_lua_file<'source>(
|
|||
},
|
||||
},
|
||||
children: Vec::new(),
|
||||
metadata: None,
|
||||
source_path: Some(file.path.to_path_buf()),
|
||||
metadata: MetadataPerInstance {
|
||||
source_path: Some(file.path.to_path_buf()),
|
||||
ignore_unknown_instances: false,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
@ -321,8 +327,10 @@ fn snapshot_txt_file<'source>(
|
|||
},
|
||||
},
|
||||
children: Vec::new(),
|
||||
metadata: None,
|
||||
source_path: Some(file.path.to_path_buf()),
|
||||
metadata: MetadataPerInstance {
|
||||
source_path: Some(file.path.to_path_buf()),
|
||||
ignore_unknown_instances: false,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
@ -352,8 +360,10 @@ fn snapshot_csv_file<'source>(
|
|||
},
|
||||
},
|
||||
children: Vec::new(),
|
||||
metadata: None,
|
||||
source_path: Some(file.path.to_path_buf()),
|
||||
metadata: MetadataPerInstance {
|
||||
source_path: Some(file.path.to_path_buf()),
|
||||
ignore_unknown_instances: false,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ use serde_derive::{Serialize, Deserialize};
|
|||
|
||||
use crate::{
|
||||
path_map::PathMap,
|
||||
rbx_session::MetadataPerPath,
|
||||
project::InstanceProjectNodeMetadata,
|
||||
rbx_session::{MetadataPerPath, MetadataPerInstance},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
|
|
@ -63,10 +62,7 @@ pub struct RbxSnapshotInstance<'a> {
|
|||
pub class_name: Cow<'a, str>,
|
||||
pub properties: HashMap<String, RbxValue>,
|
||||
pub children: Vec<RbxSnapshotInstance<'a>>,
|
||||
|
||||
// TODO: Replace source_path and metadata with MetadataPerInstance
|
||||
pub source_path: Option<PathBuf>,
|
||||
pub metadata: Option<InstanceProjectNodeMetadata>,
|
||||
pub metadata: MetadataPerInstance,
|
||||
}
|
||||
|
||||
pub fn snapshot_from_tree(tree: &RbxTree, id: RbxId) -> Option<RbxSnapshotInstance<'static>> {
|
||||
|
|
@ -82,29 +78,29 @@ pub fn snapshot_from_tree(tree: &RbxTree, id: RbxId) -> Option<RbxSnapshotInstan
|
|||
class_name: Cow::Owned(instance.class_name.to_owned()),
|
||||
properties: instance.properties.clone(),
|
||||
children,
|
||||
source_path: None,
|
||||
metadata: None,
|
||||
metadata: MetadataPerInstance {
|
||||
source_path: None,
|
||||
ignore_unknown_instances: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
pub fn reify_root(
|
||||
snapshot: &RbxSnapshotInstance,
|
||||
metadata_per_path: &mut PathMap<MetadataPerPath>,
|
||||
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
|
||||
instance_metadata_map: &mut HashMap<RbxId, MetadataPerInstance>,
|
||||
changes: &mut InstanceChanges,
|
||||
) -> RbxTree {
|
||||
let instance = reify_core(snapshot);
|
||||
let mut tree = RbxTree::new(instance);
|
||||
let root_id = tree.get_root_id();
|
||||
|
||||
if let Some(source_path) = &snapshot.source_path {
|
||||
if let Some(source_path) = &snapshot.metadata.source_path {
|
||||
let path_meta = metadata_per_path.entry(source_path.to_owned()).or_default();
|
||||
path_meta.instance_id = Some(root_id);
|
||||
}
|
||||
|
||||
if let Some(metadata) = &snapshot.metadata {
|
||||
instance_metadata_map.insert(root_id, metadata.clone());
|
||||
}
|
||||
instance_metadata_map.insert(root_id, snapshot.metadata.clone());
|
||||
|
||||
changes.added.insert(root_id);
|
||||
|
||||
|
|
@ -120,20 +116,18 @@ pub fn reify_subtree(
|
|||
tree: &mut RbxTree,
|
||||
parent_id: RbxId,
|
||||
metadata_per_path: &mut PathMap<MetadataPerPath>,
|
||||
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
|
||||
instance_metadata_map: &mut HashMap<RbxId, MetadataPerInstance>,
|
||||
changes: &mut InstanceChanges,
|
||||
) {
|
||||
let instance = reify_core(snapshot);
|
||||
let id = tree.insert_instance(instance, parent_id);
|
||||
|
||||
if let Some(source_path) = &snapshot.source_path {
|
||||
if let Some(source_path) = &snapshot.metadata.source_path {
|
||||
let path_meta = metadata_per_path.entry(source_path.clone()).or_default();
|
||||
path_meta.instance_id = Some(id);
|
||||
}
|
||||
|
||||
if let Some(metadata) = &snapshot.metadata {
|
||||
instance_metadata_map.insert(id, metadata.clone());
|
||||
}
|
||||
instance_metadata_map.insert(id, snapshot.metadata.clone());
|
||||
|
||||
changes.added.insert(id);
|
||||
|
||||
|
|
@ -147,17 +141,15 @@ pub fn reconcile_subtree(
|
|||
id: RbxId,
|
||||
snapshot: &RbxSnapshotInstance,
|
||||
metadata_per_path: &mut PathMap<MetadataPerPath>,
|
||||
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
|
||||
instance_metadata_map: &mut HashMap<RbxId, MetadataPerInstance>,
|
||||
changes: &mut InstanceChanges,
|
||||
) {
|
||||
if let Some(source_path) = &snapshot.source_path {
|
||||
if let Some(source_path) = &snapshot.metadata.source_path {
|
||||
let path_meta = metadata_per_path.entry(source_path.to_owned()).or_default();
|
||||
path_meta.instance_id = Some(id);
|
||||
}
|
||||
|
||||
if let Some(metadata) = &snapshot.metadata {
|
||||
instance_metadata_map.insert(id, metadata.clone());
|
||||
}
|
||||
instance_metadata_map.insert(id, snapshot.metadata.clone());
|
||||
|
||||
if reconcile_instance_properties(tree.get_instance_mut(id).unwrap(), snapshot) {
|
||||
changes.updated.insert(id);
|
||||
|
|
@ -244,7 +236,7 @@ fn reconcile_instance_children(
|
|||
id: RbxId,
|
||||
snapshot: &RbxSnapshotInstance,
|
||||
metadata_per_path: &mut PathMap<MetadataPerPath>,
|
||||
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
|
||||
instance_metadata_map: &mut HashMap<RbxId, MetadataPerInstance>,
|
||||
changes: &mut InstanceChanges,
|
||||
) {
|
||||
let mut visited_snapshot_indices = HashSet::new();
|
||||
|
|
|
|||
|
|
@ -20,8 +20,23 @@ use crate::{
|
|||
project::InstanceProjectNodeMetadata,
|
||||
snapshot_reconciler::InstanceChanges,
|
||||
visualize::{VisualizeRbxSession, VisualizeImfs, graphviz_to_svg},
|
||||
rbx_session::{MetadataPerInstance},
|
||||
};
|
||||
|
||||
/// Contains the instance metadata relevant to Rojo clients.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct InstanceMetadata {
|
||||
ignore_unknown_instances: bool,
|
||||
}
|
||||
|
||||
impl InstanceMetadata {
|
||||
fn from_session_metadata(meta: &MetadataPerInstance) -> InstanceMetadata {
|
||||
InstanceMetadata {
|
||||
ignore_unknown_instances: meta.ignore_unknown_instances,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Used to attach metadata specific to Rojo to instances, which come from the
|
||||
/// rbx_tree crate.
|
||||
///
|
||||
|
|
@ -33,7 +48,7 @@ pub struct InstanceWithMetadata<'a> {
|
|||
pub instance: Cow<'a, RbxInstance>,
|
||||
|
||||
#[serde(rename = "Metadata")]
|
||||
pub metadata: Option<Cow<'a, InstanceProjectNodeMetadata>>,
|
||||
pub metadata: Option<InstanceMetadata>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
|
@ -163,7 +178,7 @@ impl Server {
|
|||
for &requested_id in &requested_ids {
|
||||
if let Some(instance) = tree.get_instance(requested_id) {
|
||||
let metadata = rbx_session.get_instance_metadata(requested_id)
|
||||
.map(Cow::Borrowed);
|
||||
.map(InstanceMetadata::from_session_metadata);
|
||||
|
||||
instances.insert(instance.get_id(), InstanceWithMetadata {
|
||||
instance: Cow::Borrowed(instance),
|
||||
|
|
@ -172,7 +187,7 @@ impl Server {
|
|||
|
||||
for descendant in tree.descendants(requested_id) {
|
||||
let descendant_meta = rbx_session.get_instance_metadata(descendant.get_id())
|
||||
.map(Cow::Borrowed);
|
||||
.map(InstanceMetadata::from_session_metadata);
|
||||
|
||||
instances.insert(descendant.get_id(), InstanceWithMetadata {
|
||||
instance: Cow::Borrowed(descendant),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue