mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-23 06:05:24 +00:00
Add builder-ish methods to InstanceSnapshot to make middleware code more readable
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::{borrow::Cow, collections::BTreeMap};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use maplit::hashmap;
|
||||
use rbx_dom_weak::RbxValue;
|
||||
@@ -39,22 +39,19 @@ impl SnapshotMiddleware for SnapshotCsv {
|
||||
|
||||
let table_contents = convert_localization_csv(&entry.contents(vfs)?);
|
||||
|
||||
let mut snapshot = InstanceSnapshot {
|
||||
snapshot_id: None,
|
||||
metadata: InstanceMetadata {
|
||||
instigating_source: Some(entry.path().to_path_buf().into()),
|
||||
relevant_paths: vec![entry.path().to_path_buf(), meta_path.clone()],
|
||||
..Default::default()
|
||||
},
|
||||
name: Cow::Owned(instance_name.to_owned()),
|
||||
class_name: Cow::Borrowed("LocalizationTable"),
|
||||
properties: hashmap! {
|
||||
let mut snapshot = InstanceSnapshot::new()
|
||||
.name(instance_name)
|
||||
.class_name("LocalizationTable")
|
||||
.properties(hashmap! {
|
||||
"Contents".to_owned() => RbxValue::String {
|
||||
value: table_contents,
|
||||
},
|
||||
},
|
||||
children: Vec::new(),
|
||||
};
|
||||
})
|
||||
.metadata(InstanceMetadata {
|
||||
instigating_source: Some(entry.path().to_path_buf().into()),
|
||||
relevant_paths: vec![entry.path().to_path_buf(), meta_path.clone()],
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
if let Some(meta_entry) = vfs.get(meta_path).with_not_found()? {
|
||||
let meta_contents = meta_entry.contents(vfs)?;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{borrow::Cow, collections::HashMap};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use rbx_dom_weak::{RbxId, RbxTree};
|
||||
|
||||
@@ -58,18 +58,15 @@ impl SnapshotMiddleware for SnapshotDir {
|
||||
entry.path().join("init.client.lua"),
|
||||
];
|
||||
|
||||
let mut snapshot = InstanceSnapshot {
|
||||
snapshot_id: None,
|
||||
metadata: InstanceMetadata {
|
||||
let mut snapshot = InstanceSnapshot::new()
|
||||
.name(instance_name)
|
||||
.class_name("Folder")
|
||||
.children(snapshot_children)
|
||||
.metadata(InstanceMetadata {
|
||||
instigating_source: Some(entry.path().to_path_buf().into()),
|
||||
relevant_paths,
|
||||
..Default::default()
|
||||
},
|
||||
name: Cow::Owned(instance_name),
|
||||
class_name: Cow::Borrowed("Folder"),
|
||||
properties: HashMap::new(),
|
||||
children: snapshot_children,
|
||||
};
|
||||
});
|
||||
|
||||
if let Some(meta_entry) = vfs.get(meta_path).with_not_found()? {
|
||||
let meta_contents = meta_entry.contents(vfs)?;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{borrow::Cow, str};
|
||||
use std::str;
|
||||
|
||||
use maplit::hashmap;
|
||||
use rbx_dom_weak::RbxValue;
|
||||
@@ -75,30 +75,23 @@ fn snapshot_lua_file<F: VfsFetcher>(vfs: &Vfs<F>, entry: &VfsEntry) -> SnapshotI
|
||||
.expect("File content was not valid UTF-8")
|
||||
.to_string();
|
||||
|
||||
let properties = hashmap! {
|
||||
"Source".to_owned() => RbxValue::String {
|
||||
value: contents_str,
|
||||
},
|
||||
};
|
||||
|
||||
let meta_path = entry
|
||||
.path()
|
||||
.with_file_name(format!("{}.meta.json", instance_name));
|
||||
|
||||
let metadata = InstanceMetadata {
|
||||
instigating_source: Some(entry.path().to_path_buf().into()),
|
||||
relevant_paths: vec![entry.path().to_path_buf(), meta_path.clone()],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut snapshot = InstanceSnapshot {
|
||||
snapshot_id: None,
|
||||
metadata,
|
||||
name: Cow::Owned(instance_name.to_owned()),
|
||||
class_name: Cow::Borrowed(class_name),
|
||||
properties,
|
||||
children: Vec::new(),
|
||||
};
|
||||
let mut snapshot = InstanceSnapshot::new()
|
||||
.name(instance_name)
|
||||
.class_name(class_name)
|
||||
.properties(hashmap! {
|
||||
"Source".to_owned() => RbxValue::String {
|
||||
value: contents_str,
|
||||
},
|
||||
})
|
||||
.metadata(InstanceMetadata {
|
||||
instigating_source: Some(entry.path().to_path_buf().into()),
|
||||
relevant_paths: vec![entry.path().to_path_buf(), meta_path.clone()],
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
if let Some(meta_entry) = vfs.get(meta_path).with_not_found()? {
|
||||
let meta_contents = meta_entry.contents(vfs)?;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::{
|
||||
snapshot::InstanceSnapshot,
|
||||
snapshot::{InstanceMetadata, InstanceSnapshot},
|
||||
vfs::{Vfs, VfsEntry, VfsFetcher},
|
||||
};
|
||||
|
||||
@@ -36,10 +34,13 @@ impl SnapshotMiddleware for SnapshotRbxlx {
|
||||
|
||||
let root_id = temp_tree.get_root_id();
|
||||
|
||||
let mut snapshot = InstanceSnapshot::from_tree(&temp_tree, root_id);
|
||||
snapshot.name = Cow::Owned(instance_name.to_owned());
|
||||
snapshot.metadata.instigating_source = Some(entry.path().to_path_buf().into());
|
||||
snapshot.metadata.relevant_paths = vec![entry.path().to_path_buf()];
|
||||
let snapshot = InstanceSnapshot::from_tree(&temp_tree, root_id)
|
||||
.name(instance_name)
|
||||
.metadata(InstanceMetadata {
|
||||
instigating_source: Some(entry.path().to_path_buf().into()),
|
||||
relevant_paths: vec![entry.path().to_path_buf()],
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
Ok(Some(snapshot))
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use std::{borrow::Cow, collections::HashMap};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use rbx_dom_weak::{RbxInstanceProperties, RbxTree};
|
||||
|
||||
use crate::{
|
||||
snapshot::InstanceSnapshot,
|
||||
snapshot::{InstanceMetadata, InstanceSnapshot},
|
||||
vfs::{Vfs, VfsEntry, VfsFetcher},
|
||||
};
|
||||
|
||||
@@ -44,10 +44,13 @@ impl SnapshotMiddleware for SnapshotRbxm {
|
||||
let children = root_instance.get_children_ids();
|
||||
|
||||
if children.len() == 1 {
|
||||
let mut snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0]);
|
||||
snapshot.name = Cow::Owned(instance_name.to_owned());
|
||||
snapshot.metadata.instigating_source = Some(entry.path().to_path_buf().into());
|
||||
snapshot.metadata.relevant_paths = vec![entry.path().to_path_buf()];
|
||||
let snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0])
|
||||
.name(instance_name)
|
||||
.metadata(InstanceMetadata {
|
||||
instigating_source: Some(entry.path().to_path_buf().into()),
|
||||
relevant_paths: vec![entry.path().to_path_buf()],
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
Ok(Some(snapshot))
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::{
|
||||
snapshot::InstanceSnapshot,
|
||||
snapshot::{InstanceMetadata, InstanceSnapshot},
|
||||
vfs::{Vfs, VfsEntry, VfsFetcher},
|
||||
};
|
||||
|
||||
@@ -38,10 +36,13 @@ impl SnapshotMiddleware for SnapshotRbxmx {
|
||||
let children = root_instance.get_children_ids();
|
||||
|
||||
if children.len() == 1 {
|
||||
let mut snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0]);
|
||||
snapshot.name = Cow::Owned(instance_name.to_owned());
|
||||
snapshot.metadata.instigating_source = Some(entry.path().to_path_buf().into());
|
||||
snapshot.metadata.relevant_paths = vec![entry.path().to_path_buf()];
|
||||
let snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0])
|
||||
.name(instance_name)
|
||||
.metadata(InstanceMetadata {
|
||||
instigating_source: Some(entry.path().to_path_buf().into()),
|
||||
relevant_paths: vec![entry.path().to_path_buf()],
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
Ok(Some(snapshot))
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{borrow::Cow, str};
|
||||
use std::str;
|
||||
|
||||
use maplit::hashmap;
|
||||
use rbx_dom_weak::{RbxId, RbxTree, RbxValue};
|
||||
@@ -48,18 +48,15 @@ impl SnapshotMiddleware for SnapshotTxt {
|
||||
.path()
|
||||
.with_file_name(format!("{}.meta.json", instance_name));
|
||||
|
||||
let mut snapshot = InstanceSnapshot {
|
||||
snapshot_id: None,
|
||||
metadata: InstanceMetadata {
|
||||
let mut snapshot = InstanceSnapshot::new()
|
||||
.name(instance_name)
|
||||
.class_name("StringValue")
|
||||
.properties(properties)
|
||||
.metadata(InstanceMetadata {
|
||||
instigating_source: Some(entry.path().to_path_buf().into()),
|
||||
relevant_paths: vec![entry.path().to_path_buf(), meta_path.clone()],
|
||||
..Default::default()
|
||||
},
|
||||
name: Cow::Owned(instance_name.to_owned()),
|
||||
class_name: Cow::Borrowed("StringValue"),
|
||||
properties,
|
||||
children: Vec::new(),
|
||||
};
|
||||
});
|
||||
|
||||
if let Some(meta_entry) = vfs.get(meta_path).with_not_found()? {
|
||||
let meta_contents = meta_entry.contents(vfs)?;
|
||||
|
||||
Reference in New Issue
Block a user