diff --git a/src/change_processor.rs b/src/change_processor.rs index f3902067a..180ba8afd 100644 --- a/src/change_processor.rs +++ b/src/change_processor.rs @@ -11,10 +11,11 @@ use rbx_dom_weak::types::{Ref, Variant}; use crate::{ message_queue::MessageQueue, + resolution::UnresolvedValue, snapshot::{ apply_patch_set, compute_patch_set, AppliedPatchSet, InstigatingSource, PatchSet, RojoTree, }, - snapshot_middleware::{snapshot_from_vfs, snapshot_project_node}, + snapshot_middleware::{meta_file::AdjacentMetadata, snapshot_from_vfs, snapshot_project_node}, }; /// Processes file change events, updates the DOM, and sends those updates @@ -193,6 +194,13 @@ impl JobThreadContext { } for (key, changed_value) in &update.changed_properties { + let mut meta_path = None; + for path in instance.metadata().relevant_paths.iter() { + if path.to_str().unwrap().ends_with(".meta.json") { + meta_path = Some(path); + break; + } + } if key == "Source" { if let Some(instigating_source) = &instance.metadata().instigating_source @@ -218,8 +226,36 @@ impl JobThreadContext { id ); } + } else if let Some(meta_path) = meta_path { + if let Some(meta_contents) = + self.vfs.read(&meta_path).with_not_found().unwrap() + { + let mut metadata = + AdjacentMetadata::from_slice(&meta_contents, meta_path.clone()) + .unwrap(); + metadata.properties.insert( + key.clone(), + UnresolvedValue::FullyQualified( + changed_value.as_ref().unwrap().clone(), + ), + ); + let data = serde_json::to_string_pretty(&metadata).unwrap(); + fs::write(meta_path, data).unwrap(); + } else { + let mut metadata = AdjacentMetadata::new(meta_path.clone()); + metadata.properties.insert( + key.clone(), + UnresolvedValue::FullyQualified( + changed_value.as_ref().unwrap().clone(), + ), + ); + let data = serde_json::to_string_pretty(&metadata).unwrap(); + fs::write(meta_path, data).unwrap(); + } } else { - log::warn!("Cannot change properties besides BaseScript.Source."); + log::warn!( + "Cannot change properties of instances with no meta support" + ); } } } else { diff --git a/src/snapshot_middleware/meta_file.rs b/src/snapshot_middleware/meta_file.rs index 72930e49e..3d639b269 100644 --- a/src/snapshot_middleware/meta_file.rs +++ b/src/snapshot_middleware/meta_file.rs @@ -25,8 +25,15 @@ pub struct AdjacentMetadata { #[serde(skip)] pub path: PathBuf, } - impl AdjacentMetadata { + pub fn new(path: PathBuf) -> AdjacentMetadata { + AdjacentMetadata { + ignore_unknown_instances: None, + properties: HashMap::new(), + attributes: HashMap::new(), + path: path, + } + } pub fn from_slice(slice: &[u8], path: PathBuf) -> anyhow::Result { let mut meta: Self = serde_json::from_slice(slice).with_context(|| { format!( diff --git a/src/snapshot_middleware/mod.rs b/src/snapshot_middleware/mod.rs index 3d5de76bd..536a312b6 100644 --- a/src/snapshot_middleware/mod.rs +++ b/src/snapshot_middleware/mod.rs @@ -10,7 +10,7 @@ mod dir; mod json; mod json_model; mod lua; -mod meta_file; +pub mod meta_file; mod project; mod rbxm; mod rbxmx;