From 8f215148555be4d2c1bff8893e2c6ebdce025565 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Tue, 18 Feb 2020 18:19:08 -0800 Subject: [PATCH] two-way-sync: Add super special case script syncing --- src/change_processor.rs | 53 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/change_processor.rs b/src/change_processor.rs index 1ce146d7..902a1c12 100644 --- a/src/change_processor.rs +++ b/src/change_processor.rs @@ -5,7 +5,7 @@ use std::{ use crossbeam_channel::{select, Receiver, RecvError, Sender}; use jod_thread::JoinHandle; -use rbx_dom_weak::RbxId; +use rbx_dom_weak::{RbxId, RbxValue}; use crate::{ message_queue::MessageQueue, @@ -204,6 +204,57 @@ impl JobThreadContext { } } + for update in &patch_set.updated_instances { + let id = update.id; + + if let Some(instance) = tree.get_instance(id) { + if update.changed_name.is_some() { + log::warn!("Cannot rename instances yet."); + } + + if update.changed_class_name.is_some() { + log::warn!("Cannot change ClassName yet."); + } + + if update.changed_metadata.is_some() { + log::warn!("Cannot change metadata yet."); + } + + for (key, changed_value) in &update.changed_properties { + if key == "Source" { + if let Some(instigating_source) = + &instance.metadata().instigating_source + { + match instigating_source { + InstigatingSource::Path(path) => { + if let Some(RbxValue::String { value }) = changed_value { + fs::write(path, value).unwrap(); + } else { + log::warn!("Cannot change Source to non-string value."); + } + } + InstigatingSource::ProjectNode(_, _, _) => { + log::warn!( + "Cannot remove instance {}, it's from a project file", + id + ); + } + } + } else { + log::warn!( + "Cannot update instance {}, it is not an instigating source.", + id + ); + } + } else { + log::warn!("Cannot change properties besides BaseScript.Source."); + } + } + } else { + log::warn!("Cannot update instance {}, it does not exist.", id); + } + } + apply_patch_set(&mut tree, patch_set) };