mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-22 21:55:15 +00:00
Add SnapshotSource property
This commit is contained in:
@@ -1,25 +1,32 @@
|
||||
//! Defines the structure of an instance snapshot.
|
||||
|
||||
use std::{borrow::Cow, collections::HashMap};
|
||||
use std::{borrow::Cow, collections::HashMap, path::PathBuf};
|
||||
|
||||
use rbx_dom_weak::{RbxId, RbxTree, RbxValue};
|
||||
|
||||
use crate::project::ProjectNode;
|
||||
|
||||
/// A lightweight description of what an instance should look like. Attempts to
|
||||
/// be somewhat memory efficient by borrowing from its source data, indicated by
|
||||
/// the lifetime parameter, `'source`.
|
||||
/// the lifetime parameter `'source`.
|
||||
///
|
||||
// Possible future improvements:
|
||||
// - Use refcounted/interned strings
|
||||
// - Replace use of RbxValue with a sum of RbxValue + borrowed value
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct InstanceSnapshot<'source> {
|
||||
/// A temporary ID applied to the snapshot that's used for Ref properties.
|
||||
pub snapshot_id: Option<RbxId>,
|
||||
|
||||
/// A complete view of where this snapshot came from. It should contain
|
||||
/// enough information, if not None, to recreate this snapshot
|
||||
/// deterministically assuming the source has not changed state.
|
||||
pub source: Option<SnapshotSource>,
|
||||
|
||||
pub name: Cow<'source, str>,
|
||||
pub class_name: Cow<'source, str>,
|
||||
pub properties: HashMap<String, RbxValue>,
|
||||
pub children: Vec<InstanceSnapshot<'source>>,
|
||||
// TODO: Snapshot source, like a file or a project node?
|
||||
}
|
||||
|
||||
impl<'source> InstanceSnapshot<'source> {
|
||||
@@ -32,6 +39,7 @@ impl<'source> InstanceSnapshot<'source> {
|
||||
|
||||
InstanceSnapshot {
|
||||
snapshot_id: None,
|
||||
source: self.source.clone(),
|
||||
name: Cow::Owned(self.name.clone().into_owned()),
|
||||
class_name: Cow::Owned(self.class_name.clone().into_owned()),
|
||||
properties: self.properties.clone(),
|
||||
@@ -53,6 +61,7 @@ impl<'source> InstanceSnapshot<'source> {
|
||||
|
||||
InstanceSnapshot {
|
||||
snapshot_id: Some(id),
|
||||
source: None,
|
||||
name: Cow::Owned(instance.name.clone()),
|
||||
class_name: Cow::Owned(instance.class_name.clone()),
|
||||
properties: instance.properties.clone(),
|
||||
@@ -60,3 +69,15 @@ impl<'source> InstanceSnapshot<'source> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum SnapshotSource {
|
||||
File {
|
||||
path: PathBuf,
|
||||
},
|
||||
ProjectFile {
|
||||
path: PathBuf,
|
||||
name: String,
|
||||
node: ProjectNode,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -159,6 +159,7 @@ mod test {
|
||||
|
||||
let snapshot = InstanceSnapshot {
|
||||
snapshot_id: None,
|
||||
source: None,
|
||||
name: Cow::Borrowed("Foo"),
|
||||
class_name: Cow::Borrowed("Bar"),
|
||||
properties: hashmap! {
|
||||
|
||||
@@ -244,6 +244,7 @@ mod test {
|
||||
}
|
||||
},
|
||||
|
||||
source: None,
|
||||
name: Cow::Borrowed("foo"),
|
||||
class_name: Cow::Borrowed("foo"),
|
||||
children: Vec::new(),
|
||||
@@ -294,11 +295,13 @@ mod test {
|
||||
},
|
||||
|
||||
snapshot_id: None,
|
||||
source: None,
|
||||
name: Cow::Borrowed("child"),
|
||||
class_name: Cow::Borrowed("child"),
|
||||
children: Vec::new(),
|
||||
}],
|
||||
|
||||
source: None,
|
||||
properties: HashMap::new(),
|
||||
name: Cow::Borrowed("foo"),
|
||||
class_name: Cow::Borrowed("foo"),
|
||||
@@ -311,6 +314,7 @@ mod test {
|
||||
parent_id: root_id,
|
||||
instance: InstanceSnapshot {
|
||||
snapshot_id: None,
|
||||
source: None,
|
||||
properties: hashmap! {
|
||||
"Self".to_owned() => RbxValue::Ref {
|
||||
value: Some(root_id),
|
||||
|
||||
Reference in New Issue
Block a user