Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta 2 way sync #618

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
43 changes: 41 additions & 2 deletions src/change_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,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
Expand Down Expand Up @@ -244,7 +245,45 @@ impl JobThreadContext {
);
}
} else {
log::warn!("Cannot change properties besides BaseScript.Source.");
if instance.metadata().relevant_paths.len() >= 2 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally not sure if this is good enough if we where to add a new path to relevant_paths for some reason this would break

solution would be to add a special field to metadata for meta files. still this would make this change a lot lager.

let meta_path = instance.metadata().relevant_paths[1].clone();
println!("{:?}", meta_path);
if let Some(meta_contents) =
self.vfs.read(&meta_path).with_not_found().unwrap()
{
println!("File exists");
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();
println!("File writen");
} else {
println!("File did not exists");
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();
println!("File created and written to");
}
} else {
log::warn!(
"Cannot change properties of instances with no meta support"
);
}
}
}
} else {
Expand Down
8 changes: 7 additions & 1 deletion src/snapshot_middleware/meta_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ pub struct AdjacentMetadata {
#[serde(skip)]
pub path: PathBuf,
}

impl AdjacentMetadata {
pub fn new(path: PathBuf) -> AdjacentMetadata {
AdjacentMetadata {
ignore_unknown_instances: None,
properties: HashMap::new(),
path: path,
}
}
pub fn from_slice(slice: &[u8], path: PathBuf) -> anyhow::Result<Self> {
let mut meta: Self = serde_json::from_slice(slice).with_context(|| {
format!(
Expand Down
2 changes: 1 addition & 1 deletion src/snapshot_middleware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down